-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
changes_reviewer.go
164 lines (138 loc) · 5.67 KB
/
changes_reviewer.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package gerrit
import (
"context"
"fmt"
)
// ReviewerInfo entity contains information about a reviewer and its votes on a change.
type ReviewerInfo struct {
AccountInfo
Approvals map[string]string `json:"approvals"`
}
// SuggestedReviewerInfo entity contains information about a reviewer that can be added to a change (an account or a group).
type SuggestedReviewerInfo struct {
Account AccountInfo `json:"account,omitempty"`
Group GroupBaseInfo `json:"group,omitempty"`
}
// AddReviewerResult entity describes the result of adding a reviewer to a change.
type AddReviewerResult struct {
Input string `json:"input,omitempty"`
Reviewers []ReviewerInfo `json:"reviewers,omitempty"`
CCS []ReviewerInfo `json:"ccs,omitempty"`
Error string `json:"error,omitempty"`
Confirm bool `json:"confirm,omitempty"`
}
// DeleteVoteInput entity contains options for the deletion of a vote.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#delete-vote-input
type DeleteVoteInput struct {
Label string `json:"label,omitempty"`
Notify string `json:"notify,omitempty"`
NotifyDetails map[string]NotifyInfo `json:"notify_details"`
}
// ListReviewers lists the reviewers of a change.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-reviewers
func (s *ChangesService) ListReviewers(ctx context.Context, changeID string) (*[]ReviewerInfo, *Response, error) {
u := fmt.Sprintf("changes/%s/reviewers/", changeID)
req, err := s.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
}
v := new([]ReviewerInfo)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// SuggestReviewers suggest the reviewers for a given query q and result limit n.
// If result limit is not passed, then the default 10 is used.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#suggest-reviewers
func (s *ChangesService) SuggestReviewers(ctx context.Context, changeID string, opt *QueryOptions) (*[]SuggestedReviewerInfo, *Response, error) {
u := fmt.Sprintf("changes/%s/suggest_reviewers", changeID)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
}
v := new([]SuggestedReviewerInfo)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// GetReviewer retrieves a reviewer of a change.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-reviewer
func (s *ChangesService) GetReviewer(ctx context.Context, changeID, accountID string) (*ReviewerInfo, *Response, error) {
u := fmt.Sprintf("changes/%s/reviewers/%s", changeID, accountID)
req, err := s.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
}
v := new(ReviewerInfo)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// AddReviewer adds one user or all members of one group as reviewer to the change.
// The reviewer to be added to the change must be provided in the request body as a ReviewerInput entity.
//
// As response an AddReviewerResult entity is returned that describes the newly added reviewers.
// If a group is specified, adding the group members as reviewers is an atomic operation.
// This means if an error is returned, none of the members are added as reviewer.
// If a group with many members is added as reviewer a confirmation may be required.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#add-reviewer
func (s *ChangesService) AddReviewer(ctx context.Context, changeID string, input *ReviewerInput) (*AddReviewerResult, *Response, error) {
u := fmt.Sprintf("changes/%s/reviewers", changeID)
req, err := s.client.NewRequest(ctx, "POST", u, input)
if err != nil {
return nil, nil, err
}
v := new(AddReviewerResult)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// DeleteReviewer deletes a reviewer from a change.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#delete-reviewer
func (s *ChangesService) DeleteReviewer(ctx context.Context, changeID, accountID string) (*Response, error) {
u := fmt.Sprintf("changes/%s/reviewers/%s", changeID, accountID)
return s.client.DeleteRequest(ctx, u, nil)
}
// ListVotes lists the votes for a specific reviewer of the change.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-votes
func (s *ChangesService) ListVotes(ctx context.Context, changeID string, accountID string) (map[string]int, *Response, error) {
u := fmt.Sprintf("changes/%s/reviewers/%s/votes/", changeID, accountID)
req, err := s.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
}
var v map[string]int
resp, err := s.client.Do(req, &v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// DeleteVote deletes a single vote from a change. Note, that even when the
// last vote of a reviewer is removed the reviewer itself is still listed on
// the change.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#delete-vote
func (s *ChangesService) DeleteVote(ctx context.Context, changeID string, accountID string, label string, input *DeleteVoteInput) (*Response, error) {
u := fmt.Sprintf("changes/%s/reviewers/%s/votes/%s", changeID, accountID, label)
return s.client.DeleteRequest(ctx, u, input)
}