From 307d9b51578e5fc5da504bc9ae98dac6dfbabec1 Mon Sep 17 00:00:00 2001 From: Andy Walsh Date: Wed, 31 May 2023 10:52:55 -0500 Subject: [PATCH 1/2] Fix for GetList Currently the GetList() function for IssueLinkTypes in OnPremise and Cloud fails to return the JSON document from the API. This is because it expects a top level array of subdocuments and not a top level document containing an array of subdocuments. I have corrected this behavior and revised the tests to ensure the behavior is correct. I have also tested this behavior against my own Jira OnPremise and Cloud instances. --- cloud/issuelinktype.go | 9 +- onpremise/issuelinktype.go | 9 +- testing/mock-data/all_issuelinktypes.json | 244 +++++++++++----------- 3 files changed, 129 insertions(+), 133 deletions(-) diff --git a/cloud/issuelinktype.go b/cloud/issuelinktype.go index f50e5430..a1547bb7 100644 --- a/cloud/issuelinktype.go +++ b/cloud/issuelinktype.go @@ -15,22 +15,19 @@ type IssueLinkTypeService service // GetList gets all of the issue link types from Jira. // // Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issueLinkType-get -// -// TODO Double check this method if this works as expected, is using the latest API and the response is complete -// This double check effort is done for v2 - Remove this two lines if this is completed. func (s *IssueLinkTypeService) GetList(ctx context.Context) ([]IssueLinkType, *Response, error) { apiEndpoint := "rest/api/2/issueLinkType" - req, err := s.client.NewRequest(ctx, http.MethodGet, apiEndpoint, nil) + req, err := s.client.NewRequest(ctx, "GET", apiEndpoint, nil) if err != nil { return nil, nil, err } - linkTypeList := []IssueLinkType{} + var linkTypeList map[string]([]IssueLinkType) resp, err := s.client.Do(req, &linkTypeList) if err != nil { return nil, resp, NewJiraError(resp, err) } - return linkTypeList, resp, nil + return linkTypeList["issueLinkTypes"], resp, nil } // Get gets info of a specific issue link type from Jira. diff --git a/onpremise/issuelinktype.go b/onpremise/issuelinktype.go index bf4687d2..898e6e92 100644 --- a/onpremise/issuelinktype.go +++ b/onpremise/issuelinktype.go @@ -15,22 +15,19 @@ type IssueLinkTypeService service // GetList gets all of the issue link types from Jira. // // Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issueLinkType-get -// -// TODO Double check this method if this works as expected, is using the latest API and the response is complete -// This double check effort is done for v2 - Remove this two lines if this is completed. func (s *IssueLinkTypeService) GetList(ctx context.Context) ([]IssueLinkType, *Response, error) { apiEndpoint := "rest/api/2/issueLinkType" - req, err := s.client.NewRequest(ctx, http.MethodGet, apiEndpoint, nil) + req, err := s.client.NewRequest(ctx, "GET", apiEndpoint, nil) if err != nil { return nil, nil, err } - linkTypeList := []IssueLinkType{} + var linkTypeList map[string]([]IssueLinkType) resp, err := s.client.Do(req, &linkTypeList) if err != nil { return nil, resp, NewJiraError(resp, err) } - return linkTypeList, resp, nil + return linkTypeList["issueLinkTypes"], resp, nil } // Get gets info of a specific issue link type from Jira. diff --git a/testing/mock-data/all_issuelinktypes.json b/testing/mock-data/all_issuelinktypes.json index 782dade9..f1a81092 100644 --- a/testing/mock-data/all_issuelinktypes.json +++ b/testing/mock-data/all_issuelinktypes.json @@ -1,121 +1,123 @@ -[ - { - "id": "12310361", - "name": "Blocked", - "inward": "Blocked", - "outward": "Blocked", - "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310361" - }, - { - "id": "10032", - "name": "Blocker", - "inward": "is blocked by", - "outward": "blocks", - "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/10032" - }, - { - "id": "12310460", - "name": "Child-Issue", - "inward": "is a child of", - "outward": "is a parent of", - "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310460" - }, - { - "id": "10020", - "name": "Cloners", - "inward": "is cloned by", - "outward": "is a clone of", - "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/10020" - }, - { - "id": "12310060", - "name": "Container", - "inward": "Is contained by", - "outward": "contains", - "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310060" - }, - { - "id": "12310461", - "name": "Dependency", - "inward": "Dependency", - "outward": "Dependency", - "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310461" - }, - { - "id": "12310360", - "name": "Dependent", - "inward": "Dependent", - "outward": "Dependent", - "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310360" - }, - { - "id": "12310000", - "name": "Duplicate", - "inward": "is duplicated by", - "outward": "duplicates", - "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310000" - }, - { - "id": "12310010", - "name": "Incorporates", - "inward": "is part of", - "outward": "incorporates", - "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310010" - }, - { - "id": "12310462", - "name": "Parent Feature", - "inward": "Parent Feature", - "outward": "Parent Feature", - "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310462" - }, - { - "id": "12310560", - "name": "Problem/Incident", - "inward": "is caused by", - "outward": "causes", - "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310560" - }, - { - "id": "10030", - "name": "Reference", - "inward": "is related to", - "outward": "relates to", - "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/10030" - }, - { - "id": "12310050", - "name": "Regression", - "inward": "is broken by", - "outward": "breaks", - "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310050" - }, - { - "id": "12310260", - "name": "Related", - "inward": "is related to", - "outward": "relates to", - "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310260" - }, - { - "id": "12310040", - "name": "Required", - "inward": "is required by", - "outward": "requires", - "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310040" - }, - { - "id": "12310051", - "name": "Supercedes", - "inward": "is superceded by", - "outward": "supercedes", - "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310051" - }, - { - "id": "10001", - "name": "dependent", - "inward": "is depended upon by", - "outward": "depends upon", - "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/10001" - } -] +{ + "issueLinkTypes": [ + { + "id": "12310361", + "name": "Blocked", + "inward": "Blocked", + "outward": "Blocked", + "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310361" + }, + { + "id": "10032", + "name": "Blocker", + "inward": "is blocked by", + "outward": "blocks", + "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/10032" + }, + { + "id": "12310460", + "name": "Child-Issue", + "inward": "is a child of", + "outward": "is a parent of", + "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310460" + }, + { + "id": "10020", + "name": "Cloners", + "inward": "is cloned by", + "outward": "is a clone of", + "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/10020" + }, + { + "id": "12310060", + "name": "Container", + "inward": "Is contained by", + "outward": "contains", + "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310060" + }, + { + "id": "12310461", + "name": "Dependency", + "inward": "Dependency", + "outward": "Dependency", + "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310461" + }, + { + "id": "12310360", + "name": "Dependent", + "inward": "Dependent", + "outward": "Dependent", + "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310360" + }, + { + "id": "12310000", + "name": "Duplicate", + "inward": "is duplicated by", + "outward": "duplicates", + "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310000" + }, + { + "id": "12310010", + "name": "Incorporates", + "inward": "is part of", + "outward": "incorporates", + "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310010" + }, + { + "id": "12310462", + "name": "Parent Feature", + "inward": "Parent Feature", + "outward": "Parent Feature", + "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310462" + }, + { + "id": "12310560", + "name": "Problem/Incident", + "inward": "is caused by", + "outward": "causes", + "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310560" + }, + { + "id": "10030", + "name": "Reference", + "inward": "is related to", + "outward": "relates to", + "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/10030" + }, + { + "id": "12310050", + "name": "Regression", + "inward": "is broken by", + "outward": "breaks", + "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310050" + }, + { + "id": "12310260", + "name": "Related", + "inward": "is related to", + "outward": "relates to", + "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310260" + }, + { + "id": "12310040", + "name": "Required", + "inward": "is required by", + "outward": "requires", + "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310040" + }, + { + "id": "12310051", + "name": "Supercedes", + "inward": "is superceded by", + "outward": "supercedes", + "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/12310051" + }, + { + "id": "10001", + "name": "dependent", + "inward": "is depended upon by", + "outward": "depends upon", + "self": "https://issues.apache.org/jira/rest/api/2/issueLinkType/10001" + } + ] +} From fd20c71b86dfdfb4f498093d3039a2362e4c4b53 Mon Sep 17 00:00:00 2001 From: Andy Walsh Date: Wed, 31 May 2023 10:58:17 -0500 Subject: [PATCH 2/2] Fix for GetList Currently the GetList() function for IssueLinkTypes in OnPremise and Cloud fails to return the JSON document from the API. This is because it expects a top level array of subdocuments and not a top level document containing an array of subdocuments. I have corrected this behavior and revised the tests to ensure the behavior is correct. I have also tested this behavior against my own Jira OnPremise and Cloud instances. --- cloud/issuelinktype.go | 2 +- onpremise/issuelinktype.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cloud/issuelinktype.go b/cloud/issuelinktype.go index a1547bb7..7e9a1062 100644 --- a/cloud/issuelinktype.go +++ b/cloud/issuelinktype.go @@ -17,7 +17,7 @@ type IssueLinkTypeService service // Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issueLinkType-get func (s *IssueLinkTypeService) GetList(ctx context.Context) ([]IssueLinkType, *Response, error) { apiEndpoint := "rest/api/2/issueLinkType" - req, err := s.client.NewRequest(ctx, "GET", apiEndpoint, nil) + req, err := s.client.NewRequest(ctx, http.MethodGet, apiEndpoint, nil) if err != nil { return nil, nil, err } diff --git a/onpremise/issuelinktype.go b/onpremise/issuelinktype.go index 898e6e92..bd27721a 100644 --- a/onpremise/issuelinktype.go +++ b/onpremise/issuelinktype.go @@ -17,7 +17,7 @@ type IssueLinkTypeService service // Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-issueLinkType-get func (s *IssueLinkTypeService) GetList(ctx context.Context) ([]IssueLinkType, *Response, error) { apiEndpoint := "rest/api/2/issueLinkType" - req, err := s.client.NewRequest(ctx, "GET", apiEndpoint, nil) + req, err := s.client.NewRequest(ctx, http.MethodGet, apiEndpoint, nil) if err != nil { return nil, nil, err }