Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1855 from inputvalidation/reorder-issue
Browse files Browse the repository at this point in the history
Reorder issue
  • Loading branch information
svanharmelen authored Jan 13, 2024
2 parents 1ba1a2d + 2a5b6e1 commit 9897d3b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
32 changes: 32 additions & 0 deletions issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,38 @@ func (s *IssuesService) DeleteIssue(pid interface{}, issue int, options ...Reque
return s.client.Do(req, nil)
}

// ReorderIssueOptions represents the available ReorderIssue() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#reorder-an-issue
type ReorderIssueOptions struct {
MoveAfterID *int `url:"move_after_id,omitempty" json:"move_after_id,omitempty"`
MoveBeforeID *int `url:"move_before_id,omitempty" json:"move_before_id,omitempty"`
}

// ReorderIssue reorders an issue.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#reorder-an-issue
func (s *IssuesService) ReorderIssue(pid interface{}, issue int, opt *ReorderIssueOptions, options ...RequestOptionFunc) (*Issue, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/reorder", PathEscape(project), issue)

req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
if err != nil {
return nil, nil, err
}

i := new(Issue)
resp, err := s.client.Do(req, i)
if err != nil {
return nil, resp, err
}

return i, resp, nil
}

// MoveIssueOptions represents the available MoveIssue() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/issues.html#move-an-issue
Expand Down
29 changes: 29 additions & 0 deletions issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,35 @@ func TestDeleteIssue(t *testing.T) {
}
}

func TestReorderIssue(t *testing.T) {
mux, client := setup(t)

mux.HandleFunc("/api/v4/projects/1/issues/5/reorder", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
fmt.Fprint(w, `{"id":1, "title" : "Reordered issue", "description": "This is the description of a reordered issue", "author" : {"id" : 1, "name": "corrie"}, "assignees":[{"id":1}]}`)
})

afterID := 100
opt := ReorderIssueOptions{MoveAfterID: &afterID}

issue, _, err := client.Issues.ReorderIssue("1", 5, &opt)
if err != nil {
log.Fatal(err)
}

want := &Issue{
ID: 1,
Title: "Reordered issue",
Description: "This is the description of a reordered issue",
Author: &IssueAuthor{ID: 1, Name: "corrie"},
Assignees: []*IssueAssignee{{ID: 1}},
}

if !reflect.DeepEqual(want, issue) {
t.Errorf("Issues.ReorderIssue returned %+v, want %+v", issue, want)
}
}

func TestMoveIssue(t *testing.T) {
mux, client := setup(t)

Expand Down

0 comments on commit 9897d3b

Please sign in to comment.