forked from ovh/cds
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype_gitlab.go
More file actions
89 lines (81 loc) · 2.92 KB
/
type_gitlab.go
File metadata and controls
89 lines (81 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package hooks
import (
"time"
"github.com/ovh/cds/sdk"
)
// GitlabEvent represents payload send by gitlab on a push event
type GitlabEvent struct {
ObjectKind string `json:"object_kind"`
Before string `json:"before"`
After string `json:"after"`
Ref string `json:"ref"`
CheckoutSha string `json:"checkout_sha"`
UserID int `json:"user_id"`
UserName string `json:"user_name"`
UserUsername string `json:"user_username"`
UserEmail string `json:"user_email"`
UserAvatar string `json:"user_avatar"`
ProjectID int `json:"project_id"`
Project *GitlabProject `json:"project"`
Repository *GitlabRepository `json:"repository"`
Commits []GitlabCommit `json:"commits"`
TotalCommitsCount int `json:"total_commits_count"`
}
type GitlabCommit struct {
ID string `json:"id"`
Message string `json:"message"`
Timestamp time.Time `json:"timestamp"`
URL string `json:"url"`
Author GitlabAuthor `json:"author"`
Added []string `json:"added"`
Modified []string `json:"modified"`
Removed []interface{} `json:"removed"`
}
type GitlabAuthor struct {
Name string `json:"name"`
Email string `json:"email"`
}
type GitlabRepository struct {
Name string `json:"name"`
URL string `json:"url"`
Description string `json:"description"`
Homepage string `json:"homepage"`
GitHTTPURL string `json:"git_http_url"`
GitSSHURL string `json:"git_ssh_url"`
VisibilityLevel int `json:"visibility_level"`
}
type GitlabProject struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
WebURL string `json:"web_url"`
AvatarURL interface{} `json:"avatar_url"`
GitSSHURL string `json:"git_ssh_url"`
GitHTTPURL string `json:"git_http_url"`
Namespace string `json:"namespace"`
VisibilityLevel int `json:"visibility_level"`
PathWithNamespace string `json:"path_with_namespace"`
DefaultBranch string `json:"default_branch"`
Homepage string `json:"homepage"`
URL string `json:"url"`
SSHURL string `json:"ssh_url"`
HTTPURL string `json:"http_url"`
}
func (g *GitlabEvent) GetCommits() []sdk.VCSCommit {
commits := []sdk.VCSCommit{}
for _, c := range g.Commits {
commit := sdk.VCSCommit{
Hash: c.ID,
Author: sdk.VCSAuthor{
Name: c.Author.Name,
DisplayName: c.Author.Name,
Email: c.Author.Email,
},
Message: c.Message,
URL: c.URL,
Timestamp: c.Timestamp.Unix(),
}
commits = append(commits, commit)
}
return commits
}