Skip to content

Commit

Permalink
Merge pull request #1561 from tobischo/feature/1386-add-custom-type-f…
Browse files Browse the repository at this point in the history
…or-issue-relations

Add specific type for issue relations
  • Loading branch information
svanharmelen committed Oct 29, 2022
2 parents 6d50bb2 + c9c315f commit 291b783
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 25 deletions.
35 changes: 33 additions & 2 deletions issue_links.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package gitlab
import (
"fmt"
"net/http"
"time"
)

// IssueLinksService handles communication with the issue relations related methods
Expand All @@ -38,14 +39,44 @@ type IssueLink struct {
LinkType string `json:"link_type"`
}

// IssueRelation gets a relation between two issues.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issue_links.html#list-issue-relations
type IssueRelation struct {
ID int `json:"id"`
IID int `json:"iid"`
State string `json:"state"`
Description string `json:"description"`
Confidential bool `json:"confidential"`
Author *IssueAuthor `json:"author"`
Milestone *Milestone `json:"milestone"`
ProjectID int `json:"project_id"`
Assignees []*IssueAssignee `json:"assignees"`
Assignee *IssueAssignee `json:"assignee"`
UpdatedAt *time.Time `json:"updated_at"`
Title string `json:"title"`
CreatedAt *time.Time `json:"created_at"`
Labels Labels `json:"labels"`
DueDate *ISOTime `json:"due_date"`
WebURL string `json:"web_url"`
References *IssueReferences `json:"references"`
Weight int `json:"weight"`
UserNotesCount int `json:"user_notes_count"`
IssueLinkID int `json:"issue_link_id"`
LinkType string `json:"link_type"`
LinkCreatedAt *time.Time `json:"link_created_at"`
LinkUpdatedAt *time.Time `json:"link_updated_at"`
}

// ListIssueRelations gets a list of related issues of a given issue,
// sorted by the relationship creation datetime (ascending).
//
// Issues will be filtered according to the user authorizations.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/issue_links.html#list-issue-relations
func (s *IssueLinksService) ListIssueRelations(pid interface{}, issue int, options ...RequestOptionFunc) ([]*Issue, *Response, error) {
func (s *IssueLinksService) ListIssueRelations(pid interface{}, issue int, options ...RequestOptionFunc) ([]*IssueRelation, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
Expand All @@ -57,7 +88,7 @@ func (s *IssueLinksService) ListIssueRelations(pid interface{}, issue int, optio
return nil, nil, err
}

var is []*Issue
var is []*IssueRelation
resp, err := s.client.Do(req, &is)
if err != nil {
return nil, resp, err
Expand Down
42 changes: 19 additions & 23 deletions issue_links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestIssueLinksService_ListIssueRelations(t *testing.T) {
{
"id" : 84,
"iid" : 14,
"confidential": false,
"issue_link_id": 1,
"project_id" : 4,
"title" : "Issues with auth",
Expand Down Expand Up @@ -49,35 +50,30 @@ func TestIssueLinksService_ListIssueRelations(t *testing.T) {
`)
})

want := []*Issue{{
ID: 84,
IID: 14,
ExternalID: "",
State: "opened",
Description: "",
want := []*IssueRelation{{
ID: 84,
IID: 14,
State: "opened",
Description: "",
Confidential: false,
Author: &IssueAuthor{
ID: 18,
State: "active",
WebURL: "https://gitlab.example.com/eileen.lowe",
Name: "Venkatesh Thalluri",
AvatarURL: "",
Username: "venkatesh.thalluri"},
ProjectID: 4,
Assignees: []*IssueAssignee{},
Title: "Issues with auth",
MovedToID: 0,
Labels: []string{"bug"},
Upvotes: 0,
Downvotes: 0,
WebURL: "http://example.com/example/example/issues/14",
Confidential: false,
Weight: 0,
DiscussionLocked: false,
Subscribed: false,
UserNotesCount: 0,
IssueLinkID: 1,
MergeRequestCount: 0,
EpicIssueID: 0,
Username: "venkatesh.thalluri",
},
Milestone: nil,
ProjectID: 4,
Assignees: []*IssueAssignee{},
Assignee: nil,
Title: "Issues with auth",
Labels: []string{"bug"},
WebURL: "http://example.com/example/example/issues/14",
Weight: 0,
IssueLinkID: 1,
LinkType: "relates_to",
}}

is, resp, err := client.IssueLinks.ListIssueRelations(4, 14, nil)
Expand Down

0 comments on commit 291b783

Please sign in to comment.