fix: format of date when MR was closed or merged (#367) refactor: Add Payload Validators + Middleware In Go Code (#366) fix: Add better checks for leaving comments (#369) fix: regex support for http credentials embedded in remote url (#372) fix: Comment on single line selects two lines (#371) This is a #PATCH release.
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package app
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/xanzy/go-gitlab"
|
|
)
|
|
|
|
type AssigneeUpdateRequest struct {
|
|
Ids []int `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)
|
|
}
|
|
}
|