MCPcopy Create free account
hub / github.com/gogs/gogs / getSlackPushPayload

Function getSlackPushPayload

internal/database/webhook_slack.go:101–144  ·  view source on GitHub ↗
(p *api.PushPayload, slack *SlackMeta)

Source from the content-addressed store, hash-verified

99}
100
101func getSlackPushPayload(p *api.PushPayload, slack *SlackMeta) *SlackPayload {
102 // n new commits
103 var (
104 branchName = git.RefShortName(p.Ref)
105 commitDesc string
106 commitString string
107 )
108
109 if len(p.Commits) == 1 {
110 commitDesc = "1 new commit"
111 } else {
112 commitDesc = fmt.Sprintf("%d new commits", len(p.Commits))
113 }
114 if len(p.CompareURL) > 0 {
115 commitString = SlackLinkFormatter(p.CompareURL, commitDesc)
116 } else {
117 commitString = commitDesc
118 }
119
120 repoLink := SlackLinkFormatter(p.Repo.HTMLURL, p.Repo.Name)
121 branchLink := SlackLinkFormatter(p.Repo.HTMLURL+"/src/"+branchName, branchName)
122 text := fmt.Sprintf("[%s:%s] %s pushed by %s", repoLink, branchLink, commitString, p.Pusher.UserName)
123
124 var attachmentText string
125 // for each commit, generate attachment text
126 for i, commit := range p.Commits {
127 attachmentText += fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.URL, commit.ID[:7]), SlackShortTextFormatter(commit.Message), SlackTextFormatter(commit.Author.Name))
128 // add linebreak to each commit but the last
129 if i < len(p.Commits)-1 {
130 attachmentText += "\n"
131 }
132 }
133
134 return &SlackPayload{
135 Channel: slack.Channel,
136 Text: text,
137 Username: slack.Username,
138 IconURL: slack.IconURL,
139 Attachments: []*SlackAttachment{{
140 Color: slack.Color,
141 Text: attachmentText,
142 }},
143 }
144}
145
146func getSlackIssuesPayload(p *api.IssuesPayload, slack *SlackMeta) *SlackPayload {
147 senderLink := SlackLinkFormatter(conf.Server.ExternalURL+p.Sender.UserName, p.Sender.UserName)

Callers 1

GetSlackPayloadFunction · 0.85

Calls 3

SlackLinkFormatterFunction · 0.85
SlackShortTextFormatterFunction · 0.85
SlackTextFormatterFunction · 0.85

Tested by

no test coverage detected