Skip to content

Commit 61dbee1

Browse files
authored
Merge pull request #113 from uservoice/master
Extend GetCreateMeta method to retrieve meta data for all projects
2 parents 9fbe92b + 825973a commit 61dbee1

3 files changed

Lines changed: 386 additions & 3 deletions

File tree

issue.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ type GetQueryOptions struct {
510510
// FieldsByKeys if true then fields in issues will be referenced by keys instead of ids
511511
FieldsByKeys bool `url:"fieldsByKeys,omitempty"`
512512
UpdateHistory bool `url:"updateHistory,omitempty"`
513+
ProjectKey string `url:"projectKey,omitempty"`
513514
}
514515

515516
// CustomFields represents custom fields of JIRA

metaissue.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66

77
"github.com/trivago/tgo/tcontainer"
8+
"github.com/google/go-querystring/query"
89
)
910

1011
// CreateMetaInfo contains information about fields and their attributed to create a ticket.
@@ -36,20 +37,31 @@ type MetaIssueType struct {
3637
Description string `json:"description,omitempty"`
3738
IconUrl string `json:"iconurl,omitempty"`
3839
Name string `json:"name,omitempty"`
39-
Subtasks bool `json:"subtask,omitempty"`
40+
Subtasks bool `json:"subtask,omitempty"`
4041
Expand string `json:"expand,omitempty"`
4142
Fields tcontainer.MarshalMap `json:"fields,omitempty"`
4243
}
4344

4445
// GetCreateMeta makes the api call to get the meta information required to create a ticket
4546
func (s *IssueService) GetCreateMeta(projectkey string) (*CreateMetaInfo, *Response, error) {
47+
return s.GetCreateMetaWithOptions(&GetQueryOptions{ProjectKey: projectkey, Expand: "projects.issuetypes.fields"})
48+
}
4649

47-
apiEndpoint := fmt.Sprintf("rest/api/2/issue/createmeta?projectKeys=%s&expand=projects.issuetypes.fields", projectkey)
50+
// GetCreateMetaWithOptions makes the api call to get the meta information without requiring to have a projectKey
51+
func (s *IssueService) GetCreateMetaWithOptions(options *GetQueryOptions) (*CreateMetaInfo, *Response, error) {
52+
apiEndpoint := "rest/api/2/issue/createmeta"
4853

4954
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
5055
if err != nil {
5156
return nil, nil, err
5257
}
58+
if options != nil {
59+
q, err := query.Values(options)
60+
if err != nil {
61+
return nil, nil , err
62+
}
63+
req.URL.RawQuery = q.Encode()
64+
}
5365

5466
meta := new(CreateMetaInfo)
5567
resp, err := s.client.Do(req, meta)
@@ -60,7 +72,6 @@ func (s *IssueService) GetCreateMeta(projectkey string) (*CreateMetaInfo, *Respo
6072

6173
return meta, resp, nil
6274
}
63-
6475
// GetProjectWithName returns a project with "name" from the meta information received. If not found, this returns nil.
6576
// The comparison of the name is case insensitive.
6677
func (m *CreateMetaInfo) GetProjectWithName(name string) *MetaProject {

0 commit comments

Comments
 (0)