Skip to content

Commit

Permalink
[issue 194] Closing issues or merge requests does not create an event…
Browse files Browse the repository at this point in the history
… post with a link back to the project #194 (#285)

* added proper link for PR and issue close reopen

* fix test

* resolved suggestion

* resolved suggestion

* trigger build

* trigger build

---------

Co-authored-by: sibasankarnayak <sibasankar@demansoltech.com>
  • Loading branch information
sibasankarnayak and sibasankarnayak authored Mar 4, 2023
1 parent d041aba commit 21beec5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions server/webhook/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ func (w *webhook) handleChannelIssue(ctx context.Context, event *gitlab.IssueEve
case actionOpen:
message = fmt.Sprintf("#### %s\n##### [%s#%v](%s)\n###### new issue by [%s](%s) on [%s](%s)\n\n%s", issue.Title, repo.PathWithNamespace, issue.IID, issue.URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername), issue.CreatedAt, issue.URL, sanitizeDescription(issue.Description))
case actionClose:
message = fmt.Sprintf("[%s] Issue [%s](%s) closed by [%s](%s)", repo.PathWithNamespace, issue.Title, issue.URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername))
message = fmt.Sprintf("[%s](%s) Issue [%s](%s) closed by [%s](%s)", repo.PathWithNamespace, repo.WebURL, issue.Title, issue.URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername))
case actionReopen:
message = fmt.Sprintf("[%s] Issue [%s](%s) reopened by [%s](%s)", repo.PathWithNamespace, issue.Title, issue.URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername))
message = fmt.Sprintf("[%s](%s) Issue [%s](%s) reopened by [%s](%s)", repo.PathWithNamespace, repo.WebURL, issue.Title, issue.URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername))
case actionUpdate:
if len(event.Changes.Labels.Current) > 0 && !sameLabels(event.Changes.Labels.Current, event.Changes.Labels.Previous) {
message = fmt.Sprintf("#### %s\n##### [%s#%v](%s)\n###### issue labeled `%s` by [%s](%s) on [%s](%s)\n\n%s", issue.Title, repo.PathWithNamespace, issue.IID, issue.URL, labelToString(event.Changes.Labels.Current), event.User.Username, w.gitlabRetreiver.GetUserURL(event.User.Username), issue.UpdatedAt, issue.URL, sanitizeDescription(issue.Description))
Expand Down
4 changes: 2 additions & 2 deletions server/webhook/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var testDataIssue = []testDataIssueStr{
ToChannels: []string{},
From: "manland",
}, {
Message: "[manland/webhook] Issue [test new issue](http://localhost:3000/manland/webhook/issues/1) closed by [manland](http://my.gitlab.com/manland)",
Message: "[manland/webhook](http://localhost:3000/manland/webhook) Issue [test new issue](http://localhost:3000/manland/webhook/issues/1) closed by [manland](http://my.gitlab.com/manland)",
ToUsers: []string{},
ToChannels: []string{"channel1"},
From: "manland",
Expand All @@ -94,7 +94,7 @@ var testDataIssue = []testDataIssueStr{
ToUsers: []string{"root"},
From: "manland",
}, {
Message: "[manland/webhook] Issue [test new issue](http://localhost:3000/manland/webhook/issues/1) reopened by [manland](http://my.gitlab.com/manland)",
Message: "[manland/webhook](http://localhost:3000/manland/webhook) Issue [test new issue](http://localhost:3000/manland/webhook/issues/1) reopened by [manland](http://my.gitlab.com/manland)",
ToUsers: []string{},
ToChannels: []string{"channel1"},
From: "manland",
Expand Down
6 changes: 3 additions & 3 deletions server/webhook/merge_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ func (w *webhook) handleChannelMergeRequest(ctx context.Context, event *gitlab.M
case actionOpen:
message = fmt.Sprintf("#### %s\n##### [%s!%v](%s) new merge-request by [%s](%s) on [%s](%s)\n\n%s", pr.Title, repo.PathWithNamespace, pr.IID, pr.URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername), pr.CreatedAt, pr.URL, sanitizeDescription(pr.Description))
case actionMerge:
message = fmt.Sprintf("[%s] Merge request [!%v %s](%s) was merged by [%s](%s)", repo.PathWithNamespace, pr.IID, pr.Title, pr.URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername))
message = fmt.Sprintf("[%s](%s) Merge request [!%v %s](%s) was merged by [%s](%s)", repo.PathWithNamespace, repo.WebURL, pr.IID, pr.Title, pr.URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername))
case actionClose:
message = fmt.Sprintf("[%s] Merge request [!%v %s](%s) was closed by [%s](%s)", repo.PathWithNamespace, pr.IID, pr.Title, pr.URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername))
message = fmt.Sprintf("[%s](%s) Merge request [!%v %s](%s) was closed by [%s](%s)", repo.PathWithNamespace, repo.WebURL, pr.IID, pr.Title, pr.URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername))
case actionReopen:
message = fmt.Sprintf("[%s] Merge request [!%v %s](%s) was reopened by [%s](%s)", repo.PathWithNamespace, pr.IID, pr.Title, pr.URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername))
message = fmt.Sprintf("[%s](%s) Merge request [!%v %s](%s) was reopened by [%s](%s)", repo.PathWithNamespace, repo.WebURL, pr.IID, pr.Title, pr.URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername))
}

if len(message) > 0 {
Expand Down
8 changes: 4 additions & 4 deletions server/webhook/merge_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var testDataMergeRequest = []testDataMergeRequestStr{
ToChannels: []string{},
From: "manland",
}, {
Message: "[manland/webhook] Merge request [!4 Master](http://localhost:3000/manland/webhook/merge_requests/4) was closed by [manland](http://my.gitlab.com/manland)",
Message: "[manland/webhook](http://localhost:3000/manland/webhook) Merge request [!4 Master](http://localhost:3000/manland/webhook/merge_requests/4) was closed by [manland](http://my.gitlab.com/manland)",
ToUsers: []string{},
ToChannels: []string{"channel1"},
From: "manland",
Expand All @@ -83,7 +83,7 @@ var testDataMergeRequest = []testDataMergeRequestStr{
ToChannels: []string{},
From: "manland",
}, {
Message: "[manland/webhook] Merge request [!1 Update README.md](http://localhost:3000/manland/webhook/merge_requests/1) was reopened by [manland](http://my.gitlab.com/manland)",
Message: "[manland/webhook](http://localhost:3000/manland/webhook) Merge request [!1 Update README.md](http://localhost:3000/manland/webhook/merge_requests/1) was reopened by [manland](http://my.gitlab.com/manland)",
ToUsers: []string{},
ToChannels: []string{"channel1"},
From: "manland",
Expand All @@ -110,7 +110,7 @@ var testDataMergeRequest = []testDataMergeRequestStr{
ToChannels: []string{},
From: "manland",
}, {
Message: "[manland/webhook] Merge request [!4 Master](http://localhost:3000/manland/webhook/merge_requests/4) was merged by [manland](http://my.gitlab.com/manland)",
Message: "[manland/webhook](http://localhost:3000/manland/webhook) Merge request [!4 Master](http://localhost:3000/manland/webhook/merge_requests/4) was merged by [manland](http://my.gitlab.com/manland)",
ToUsers: []string{},
ToChannels: []string{"channel1"},
From: "manland",
Expand All @@ -127,7 +127,7 @@ var testDataMergeRequest = []testDataMergeRequestStr{
ToChannels: []string{},
From: "root",
}, {
Message: "[manland/webhook] Merge request [!1 Update README.md](http://localhost:3000/manland/webhook/merge_requests/1) was closed by [root](http://my.gitlab.com/root)",
Message: "[manland/webhook](http://localhost:3000/manland/webhook) Merge request [!1 Update README.md](http://localhost:3000/manland/webhook/merge_requests/1) was closed by [root](http://my.gitlab.com/root)",
ToUsers: []string{},
ToChannels: []string{"channel1"},
From: "root",
Expand Down

0 comments on commit 21beec5

Please sign in to comment.