From f45d8bff118a37b875ee70135b112173b17d30cb Mon Sep 17 00:00:00 2001 From: Chhekur <820121223505e@gmail.com> Date: Mon, 22 Nov 2021 18:24:06 +0530 Subject: [PATCH] :zap: [ISSUE] Add: Rank API --- issue.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/issue.go b/issue.go index a59cfd6..338424f 100644 --- a/issue.go +++ b/issue.go @@ -606,6 +606,20 @@ type RemoteLinkStatus struct { Icon *RemoteLinkIcon `json:"icon,omitempty" structs:"icon,omitempty"` } + +// type for rank api +type RankBeforeReqBody struct { + Issues []string `json:"issues"` + RankBeforeIssue string `json:"rankBeforeIssue"` + RankCustomFieldId int64 `json:"rankCustomFieldId"` +} + +type RankAfterReqBody struct { + Issues []string `json:"issues"` + RankAfterIssue string `json:"rankAfterIssue"` + RankCustomFieldId int64 `json:"rankCustomFieldId"` +} + // GetWithContext returns a full representation of the issue for the given issue key. // Jira will attempt to identify the issue by the issueIdOrKey path parameter. // This can be an issue id, or an issue key. @@ -782,6 +796,39 @@ func (s *IssueService) GetWorklogsWithContext(ctx context.Context, issueID strin return v, resp, err } +// Rank rank's given issue +func (s * IssueService) Rank(issueIDs []string, beforeIssue, afterIssue string, customFieldId int64) error { + apiEndpoint := "/rest/agile/1.0/issue/rank" + var reqBody interface{} + + if len(beforeIssue) > 0 { + reqBody = &RankBeforeReqBody { + Issues: issueIDs, + RankBeforeIssue: beforeIssue, + RankCustomFieldId: customFieldId, + } + } else { + reqBody = &RankAfterReqBody { + Issues: issueIDs, + RankAfterIssue: beforeIssue, + RankCustomFieldId: customFieldId, + } + } + + req, err := s.client.NewRequestWithContext(context.Background(), "PUT", apiEndpoint, reqBody) + if err != nil { + return err + } + + _, err = s.client.Do(req, nil) + + if err != nil { + return err + } + + return nil +} + // GetWorklogs wraps GetWorklogsWithContext using the background context. func (s *IssueService) GetWorklogs(issueID string, options ...func(*http.Request) error) (*Worklog, *Response, error) { return s.GetWorklogsWithContext(context.Background(), issueID, options...)