Skip to content

Commit cb6475e

Browse files
author
Xinguang Wang
committed
support gitlab
1 parent 1bed1f8 commit cb6475e

File tree

6 files changed

+57
-1
lines changed

6 files changed

+57
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
.ash_history
33

44
webhook
5+
test-data
6+
webhook.log
7+
debug

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Launch",
9+
"type": "go",
10+
"request": "launch",
11+
"mode": "auto",
12+
"program": "${workspaceFolder}/main.go",
13+
"env": {},
14+
"args": ["-l", "webhook.log"]
15+
}
16+
]
17+
}

config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"Repo":"https://bitbucket.org/starboychina/hook",
1515
"Branch":"master",
1616
"Shell":"date"
17+
},
18+
{
19+
"Repo":"https://gitlab.com/xinguang/webhook.git",
20+
"Branch":"master",
21+
"Shell":"date"
1722
}
1823
]
1924
}

gitlab.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
)
7+
8+
type gitlabPayload struct {
9+
// ref
10+
Ref string `json:"ref"` // "refs/heads/master"
11+
// Repository
12+
Repository gitlabRepository `json:"repository"`
13+
}
14+
15+
// Repository is the common gitlab Repository Entity
16+
type gitlabRepository struct {
17+
GitURL string `json:"git_http_url"`
18+
}
19+
20+
func init() {
21+
var payload gitlabPayload
22+
route("/gitlab", &payload, func(hook Hook) bool {
23+
fmt.Println(payload.Ref)
24+
fmt.Println(strings.TrimRight(hook.Repo, "/"))
25+
return strings.Contains(payload.Repository.GitURL, strings.TrimRight(hook.Repo, "/")) &&
26+
payload.Ref == "refs/heads/"+hook.Branch
27+
})
28+
}

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/starboychina/webhook
2+
3+
go 1.12

log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var logger *log.Logger
1111
func setLog() {
1212
logHandler, err := os.OpenFile(*cmdLogFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777)
1313
if err != nil {
14-
panic("cannot write log")
14+
panic("cannot write log -> " + *cmdLogFile)
1515
}
1616

1717
logger = log.New(io.MultiWriter(logHandler, os.Stdout),

0 commit comments

Comments
 (0)