-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathassignee.go
More file actions
59 lines (46 loc) · 1.48 KB
/
assignee.go
File metadata and controls
59 lines (46 loc) · 1.48 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
package app
import (
"encoding/json"
"errors"
"net/http"
gitlab "gitlab.com/gitlab-org/api/client-go"
)
type AssigneeUpdateRequest struct {
Ids []int64 `json:"ids" validate:"required"`
}
type AssigneeUpdateResponse struct {
SuccessResponse
Assignees []*gitlab.BasicUser `json:"assignees"`
}
type assigneesService struct {
data
client MergeRequestUpdater
}
/* assigneesHandler adds or removes assignees from a merge request. */
func (a assigneesService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
assigneeUpdateRequest, ok := r.Context().Value(payload("payload")).(*AssigneeUpdateRequest)
if !ok {
handleError(w, errors.New("could not get payload from context"), "Bad payload", http.StatusInternalServerError)
return
}
mr, res, err := a.client.UpdateMergeRequest(a.projectInfo.ProjectId, a.projectInfo.MergeId, &gitlab.UpdateMergeRequestOptions{
AssigneeIDs: &assigneeUpdateRequest.Ids,
})
if err != nil {
handleError(w, err, "Could not modify merge request assignees", http.StatusInternalServerError)
return
}
if res.StatusCode >= 300 {
handleError(w, GenericError{r.URL.Path}, "Could not modify merge request assignees", res.StatusCode)
return
}
w.WriteHeader(http.StatusOK)
response := AssigneeUpdateResponse{
SuccessResponse: SuccessResponse{Message: "Assignees updated"},
Assignees: mr.Assignees,
}
err = json.NewEncoder(w).Encode(response)
if err != nil {
handleError(w, err, "Could not encode response", http.StatusInternalServerError)
}
}