Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GITLAB_COMMENT_DISCUSSION_AUTORESOLVE optional environment #196

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/swift-berries-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'changesets-gitlab': minor
---

Add GITLAB_COMMENT_DISCUSSION_AUTORESOLVE optional environment variable to automaticly resolve added discussion with options to resolve discussion by default (value `all`) or resolve only when changeset is present (value `hasChangeset`)
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ GLOBAL_AGENT_NO_PROXY # Like above but for no proxied requests

GITLAB_HOST # optional, if you're using custom GitLab host, will fallback to `CI_SERVER_URL` if not provided

GITLAB_TOKEN # required, token with accessibility to push
GITLAB_TOKEN_TYPE # optional, type of the provided token in GITLAB_TOKEN. defaults to personal access token. can be `job` if you provide the Gitlab CI_JOB_TOKEN or `oauth` if you use Gitlab Oauth token
GITLAB_CI_USER_NAME # optional, username with accessibility to push, used in pairs of the above token (if it was personal access token). If not set read it from the Gitlab API
GITLAB_CI_USER_EMAIL # optional, default `gitlab[bot]@users.noreply.gitlab.com`
GITLAB_COMMENT_TYPE # optional, type of the comment. defaults to `discussion`. can be set to `note` to not create a discussion instead of a thread
GITLAB_ADD_CHANGESET_MESSAGE # optional, default commit message for adding changesets on GitLab Web UI
DEBUG_GITLAB_CREDENTIAL # optional, default `false`
GITLAB_TOKEN # required, token with accessibility to push
GITLAB_TOKEN_TYPE # optional, type of the provided token in GITLAB_TOKEN. defaults to personal access token. can be `job` if you provide the Gitlab CI_JOB_TOKEN or `oauth` if you use Gitlab Oauth token
GITLAB_CI_USER_NAME # optional, username with accessibility to push, used in pairs of the above token (if it was personal access token). If not set read it from the Gitlab API
GITLAB_CI_USER_EMAIL # optional, default `gitlab[bot]@users.noreply.gitlab.com`
GITLAB_COMMENT_TYPE # optional, type of the comment. defaults to `discussion`. can be set to `note` to not create a discussion instead of a thread
GITLAB_ADD_CHANGESET_MESSAGE # optional, default commit message for adding changesets on GitLab Web UI
GITLAB_COMMENT_DISCUSSION_AUTORESOLVE # optional, automaticly resolve added discussion with options to resolve discussion by default (value `always`) or resolve only when changeset is present (value `hasChangeset`)
DEBUG_GITLAB_CREDENTIAL # optional, default `false`
```

### Example workflow
Expand Down
14 changes: 14 additions & 0 deletions src/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export const comment = async () => {
CI_MERGE_REQUEST_SOURCE_BRANCH_SHA,
CI_MERGE_REQUEST_TITLE,
GITLAB_COMMENT_TYPE,
GITLAB_COMMENT_DISCUSSION_AUTORESOLVE,
GITLAB_ADD_CHANGESET_MESSAGE,
} = env

Expand Down Expand Up @@ -314,6 +315,19 @@ export const comment = async () => {
switch (GITLAB_COMMENT_TYPE) {
case 'discussion': {
if (noteInfo) {
if (
GITLAB_COMMENT_DISCUSSION_AUTORESOLVE === 'always' ||
(GITLAB_COMMENT_DISCUSSION_AUTORESOLVE === 'hasChangeset' &&
hasChangeset)
) {
await api.MergeRequestDiscussions.resolve(
context.projectId,
mrIid,
noteInfo.discussionId,
true,
)
}

return api.MergeRequestDiscussions.editNote(
context.projectId,
mrIid,
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export type Env = GitLabCIPredefinedVariables &
GITLAB_CI_USER_NAME?: string
GITLAB_CI_USER_EMAIL: string
GITLAB_COMMENT_TYPE: LooseString<'discussion' | 'note'>
GITLAB_COMMENT_DISCUSSION_AUTORESOLVE: LooseString<
'always' | 'hasChangeset'
>
GITLAB_ADD_CHANGESET_MESSAGE?: string
DEBUG_GITLAB_CREDENTIAL: LooseString<'1' | 'true'>

Expand Down