From 809e0688e03ee3f3f5da51f5f5fb7646780c43d0 Mon Sep 17 00:00:00 2001 From: kshitij katiyar Date: Thu, 5 Sep 2024 14:04:58 +0530 Subject: [PATCH 1/2] [MM-232]: Fixed the issue of same msg being recieved while creating and deleting tags --- server/webhook/tag.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/server/webhook/tag.go b/server/webhook/tag.go index 7f057908..b5911723 100644 --- a/server/webhook/tag.go +++ b/server/webhook/tag.go @@ -41,14 +41,23 @@ func (w *webhook) handleDMTag(event *gitlab.TagEvent) ([]*HandleWebhook, error) } func (w *webhook) handleChannelTag(ctx context.Context, event *gitlab.TagEvent) ([]*HandleWebhook, error) { - senderGitlabUsername := w.gitlabRetreiver.GetUsernameByID(event.UserID) + senderGitlabUsername := event.UserUsername repo := event.Project tagNames := strings.Split(event.Ref, "/") tagName := tagNames[len(tagNames)-1] URL := fmt.Sprintf("%s/-/tags/%s", repo.WebURL, tagName) res := []*HandleWebhook{} - message := fmt.Sprintf("[%s](%s) New tag [%s](%s) by [%s](%s): %s", repo.PathWithNamespace, repo.WebURL, tagName, URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername), event.Message) + if len(event.Message) > 0 { + event.Message = ": " + event.Message + } + + var message string + if len(event.Commits) > 0 { + message = fmt.Sprintf("[%s](%s) New tag [%s](%s) by [%s](%s)%s", repo.PathWithNamespace, repo.WebURL, tagName, URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername), event.Message) + } else { + message = fmt.Sprintf("[%s](%s): [%s](%s) Tag deleted by [%s](%s)%s", repo.PathWithNamespace, repo.WebURL, tagName, URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername), event.Message) + } toChannels := make([]string, 0) namespace, project := normalizeNamespacedProject(repo.PathWithNamespace) From a207bc40ced5906c6f184ddbd22c8c71d2398130 Mon Sep 17 00:00:00 2001 From: kshitij katiyar Date: Mon, 9 Sep 2024 12:26:50 +0530 Subject: [PATCH 2/2] [MM-232]: review fixes --- server/webhook/tag.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/webhook/tag.go b/server/webhook/tag.go index b5911723..aa54db44 100644 --- a/server/webhook/tag.go +++ b/server/webhook/tag.go @@ -49,7 +49,7 @@ func (w *webhook) handleChannelTag(ctx context.Context, event *gitlab.TagEvent) res := []*HandleWebhook{} if len(event.Message) > 0 { - event.Message = ": " + event.Message + event.Message = fmt.Sprintf(": %s", event.Message) } var message string