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

Reorder issue #1855

Merged
merged 5 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,3 +786,35 @@ func (s *IssuesService) GetParticipants(pid interface{}, issue int, options ...R

return bu, resp, 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
}
inputvalidation marked this conversation as resolved.
Show resolved Hide resolved
29 changes: 29 additions & 0 deletions issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,3 +931,32 @@ func TestGetIssueGroupMilestone(t *testing.T) {
t.Errorf("Issues.GetIssue returned %+v, want %+v", issue, want)
}
}

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)
}
}
Loading