Skip to content

Commit a783764

Browse files
authored
feat(issues): Add GetEditMeta on issue
This calls the editmeta endpoint on an issue API docs: https://docs.atlassian.com/DAC/rest/jira/6.1.html#d2e1364
1 parent 1fc10e0 commit a783764

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

metaissue.go

+24
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ type CreateMetaInfo struct {
1414
Projects []*MetaProject `json:"projects,omitempty"`
1515
}
1616

17+
// EditMetaInfo contains information about fields and their attributed to edit a ticket.
18+
type EditMetaInfo struct {
19+
Fields tcontainer.MarshalMap `json:"fields,omitempty"`
20+
}
21+
1722
// MetaProject is the meta information about a project returned from createmeta api
1823
type MetaProject struct {
1924
Expand string `json:"expand,omitempty"`
@@ -73,6 +78,25 @@ func (s *IssueService) GetCreateMetaWithOptions(options *GetQueryOptions) (*Crea
7378
return meta, resp, nil
7479
}
7580

81+
// GetEditMeta makes the api call to get the edit meta information for an issue
82+
func (s *IssueService) GetEditMeta(issue *Issue) (*EditMetaInfo, *Response, error) {
83+
apiEndpoint := fmt.Sprintf("/rest/api/2/issue/%s/editmeta", issue.Key)
84+
85+
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
86+
if err != nil {
87+
return nil, nil, err
88+
}
89+
90+
meta := new(EditMetaInfo)
91+
resp, err := s.client.Do(req, meta)
92+
93+
if err != nil {
94+
return nil, resp, err
95+
}
96+
97+
return meta, resp, nil
98+
}
99+
76100
// GetProjectWithName returns a project with "name" from the meta information received. If not found, this returns nil.
77101
// The comparison of the name is case insensitive.
78102
func (m *CreateMetaInfo) GetProjectWithName(name string) *MetaProject {

metaissue_test.go

+79
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package jira
33
import (
44
"fmt"
55
"net/http"
6+
"strings"
67
"testing"
78
)
89

@@ -378,6 +379,84 @@ func TestIssueService_GetCreateMeta_Success(t *testing.T) {
378379

379380
}
380381

382+
func TestIssueService_GetEditMeta_Success(t *testing.T) {
383+
setup()
384+
defer teardown()
385+
386+
testAPIEndpoint := "/rest/api/2/issue/PROJ-9001/editmeta"
387+
388+
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
389+
testMethod(t, r, "GET")
390+
testRequestURL(t, r, testAPIEndpoint)
391+
392+
fmt.Fprint(w, `{
393+
"fields": {
394+
"summary": {
395+
"required": true,
396+
"schema": {
397+
"type": "string",
398+
"system": "summary"
399+
},
400+
"name": "Summary",
401+
"hasDefaultValue": false,
402+
"operations": [
403+
"set"
404+
]
405+
},
406+
"attachment": {
407+
"required": false,
408+
"schema": {
409+
"type": "array",
410+
"items": "attachment",
411+
"system": "attachment"
412+
},
413+
"name": "Attachment",
414+
"hasDefaultValue": false,
415+
"operations": [
416+
417+
]
418+
}
419+
}
420+
}`)
421+
})
422+
423+
editMeta, _, err := testClient.Issue.GetEditMeta(&Issue{Key: "PROJ-9001"})
424+
if err != nil {
425+
t.Errorf("Expected nil error but got %s", err)
426+
}
427+
428+
requiredFields := 0
429+
fields := editMeta.Fields
430+
for _, value := range fields {
431+
for key, value := range value.(map[string]interface{}) {
432+
if key == "required" && value == true {
433+
requiredFields = requiredFields + 1
434+
}
435+
}
436+
437+
}
438+
summary := fields["summary"].(map[string]interface{})
439+
attachment := fields["attachment"].(map[string]interface{})
440+
if summary["required"] != true {
441+
t.Error("Expected summary to be required")
442+
}
443+
if attachment["required"] != false {
444+
t.Error("Expected attachment to not be required")
445+
}
446+
}
447+
448+
func TestIssueService_GetEditMeta_Fail(t *testing.T) {
449+
_, _, err := testClient.Issue.GetEditMeta(&Issue{Key: "PROJ-9001"})
450+
if err == nil {
451+
t.Error("Expected to receive an error, received nil instead")
452+
}
453+
454+
expectedError := "connection refused"
455+
if !strings.Contains(err.Error(), expectedError) {
456+
t.Errorf("Expected to receive error containing %s, received %v instead", expectedError, err.Error())
457+
}
458+
}
459+
381460
func TestMetaIssueType_GetCreateMetaWithOptions(t *testing.T) {
382461
setup()
383462
defer teardown()

0 commit comments

Comments
 (0)