Skip to content

Commit 484477b

Browse files
committed
Merge pull request #6 from bcicen/show-all-commits-on-push
Update push notification message to show all commits
2 parents 5c63c27 + 5bf76b9 commit 484477b

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

config.json.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"SlackAPIToken": "xoxp-2123456786-313456781-3123456782-5abcdd",
88
"ChannelPrefix": "dev-",
99
"Verbose": true,
10+
"ShowAllCommits": true,
1011
"HttpTimeout": 30,
1112
"Redirect": [
1213
{

gitlab-hook-server.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var (
3636
SlackAPIToken string // Slack API Token
3737
ChannelPrefix string // Slack channel prefix
3838
Verbose bool // Enable verbose mode
39+
ShowAllCommits bool // Show all commits rather than latest
3940
HttpTimeout int // Http timeout in second
4041
Redirect []struct { // List of channel redirect
4142
Channel string
@@ -85,6 +86,7 @@ func LoadConf() {
8586
SlackAPIToken string
8687
ChannelPrefix string
8788
Verbose bool
89+
ShowAllCommits bool
8890
HttpTimeout float64
8991
Redirect []struct {
9092
Channel string
@@ -113,6 +115,7 @@ func LoadConf() {
113115
SlackAPIToken = conf.SlackAPIToken
114116
ChannelPrefix = conf.ChannelPrefix
115117
Verbose = conf.Verbose
118+
ShowAllCommits = conf.ShowAllCommits
116119
HttpTimeout = int(conf.HttpTimeout)
117120
Redirect = conf.Redirect
118121
}
@@ -344,9 +347,19 @@ func (s *PushServ) ServeHTTP(w http.ResponseWriter, r *http.Request) {
344347

345348
// Message
346349
lastCommit := j.Commits[len(j.Commits)-1]
347-
message += "[PUSH] " + n + "Push on *" + j.Repository.Name + "* by *" + j.User_name + "* at *" + dateString + "* on branch *" + j.Ref + "*:" + n // First line
348-
message += "Last commit : <" + lastCommit.Url + "|" + lastCommit.Id + "> :" + n // Second line
349-
message += "```" + MessageEncode(lastCommit.Message) + "```" // Third line (last commit message)
350+
commitCount := strconv.FormatFloat(j.Total_commits_count, 'f', 0, 64)
351+
if ShowAllCommits {
352+
message += "Push on *" + j.Repository.Name + "* by *" + j.User_name + "* at *" + dateString + "* on branch *" + j.Ref + "*:" + n // First line
353+
message += commitCount + "commits :" + n // Second line
354+
for i := range j.Commits {
355+
c := j.Commits[i]
356+
message += "<" + c.Url + "|" + c.Id[0:7] + ">: " + "_" + MessageEncode(c.Message) + "_" + n
357+
}
358+
} else {
359+
message += "[PUSH] " + n + "Push on *" + j.Repository.Name + "* by *" + j.User_name + "* at *" + dateString + "* on branch *" + j.Ref + "*:" + n // First line
360+
message += "Last commit : <" + lastCommit.Url + "|" + lastCommit.Id + "> :" + n // Second line
361+
message += "```" + MessageEncode(lastCommit.Message) + "```" // Third line (last commit message)
362+
}
350363
SendSlackMessage(j.Repository.Name, message, Push)
351364
}
352365
}

server

-24.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)