Skip to content

Commit

Permalink
[MM-232]: Fixed the issue of same message being received while creati…
Browse files Browse the repository at this point in the history
…ng and deleting tags (#524)

* [MM-232]: Fixed the issue of same msg being recieved while creating and deleting tags

* [MM-232]: review fixes
  • Loading branch information
Kshitij-Katiyar authored Nov 22, 2024
1 parent b3acd9e commit 47ff76e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions server/webhook/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = fmt.Sprintf(": %s", 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)
Expand Down

0 comments on commit 47ff76e

Please sign in to comment.