forked from drone/go-scm
-
Notifications
You must be signed in to change notification settings - Fork 84
/
commit.go
99 lines (88 loc) · 2.87 KB
/
commit.go
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
90
91
92
93
94
95
96
97
98
99
package gitlab
import (
"context"
"fmt"
"time"
"github.com/jenkins-x/go-scm/scm"
)
type commitService struct {
client *wrapper
}
func (s *commitService) UpdateCommitStatus(ctx context.Context,
repo string, sha string, options *scm.CommitStatusUpdateOptions) (*scm.CommitStatus, *scm.Response, error) {
path := fmt.Sprintf("api/v4/projects/%s/statuses/%s", encode(repo), sha)
out := new(commitStatus)
opts := convertCommitStatusUpdateOptions(options)
res, err := s.client.do(ctx, "POST", path, opts, out)
return convertCommitStatus(out), res, err
}
func convertCommitStatusUpdateOptions(from *scm.CommitStatusUpdateOptions) commitStatusUpdateOptions {
return commitStatusUpdateOptions{
ID: from.ID,
Sha: from.Sha,
State: from.State,
Ref: from.Ref,
Name: from.Name,
TargetURL: from.TargetURL,
Description: from.Description,
Coverage: from.Coverage,
PipelineID: from.PipelineID,
}
}
func convertCommitStatus(from *commitStatus) *scm.CommitStatus {
return &scm.CommitStatus{
Status: from.Status,
Created: from.Created,
Started: from.Started,
Name: from.Name,
AllowFailure: from.AllowFailure,
Author: scm.CommitStatusAuthor{
Username: from.Author.Username,
WebURL: from.Author.WebURL,
AvatarURL: from.Author.AvatarURL,
ID: from.Author.ID,
State: from.Author.State,
Name: from.Author.Name,
},
Description: from.Description,
Sha: from.Sha,
TargetURL: from.TargetURL,
ID: from.ID,
Ref: from.Ref,
Coverage: from.Coverage,
}
}
type commitStatusUpdateOptions struct {
ID string `json:"id"`
Sha string `json:"sha"`
State string `json:"state"`
Ref string `json:"ref"`
Name string `json:"name"`
TargetURL string `json:"target_url"`
Description string `json:"description"`
Coverage float64 `json:"coverage"`
PipelineID *int `json:"pipeline_id,omitempty"`
}
type commitStatus struct {
Status string `json:"status"`
Created time.Time `json:"created_at"`
Started time.Time `json:"updated_at"`
Name string `json:"name"`
AllowFailure bool `json:"allow_failure"`
Author commitStatusAuthor `json:"author"`
Description string `json:"description"`
Sha string `json:"sha"`
TargetURL string `json:"target_url"`
Finished time.Time `json:"finished_at"`
ID int `json:"id"`
Ref string `json:"ref"`
Coverage float64 `json:"coverage"`
}
type commitStatusAuthor struct {
Username string `json:"username"`
State string `json:"state"`
WebURL string `json:"web_url"`
AvatarURL string `json:"avatar_url"`
ID int `json:"id"`
Name string `json:"name"`
}