From 967e2d4805ba1a02a4cd3ff7c27422aee7ce1e9d Mon Sep 17 00:00:00 2001 From: Andreas Fuchs Date: Wed, 26 Apr 2017 22:06:10 -0700 Subject: [PATCH 1/2] Add the "option" field type for custom fields JIRA supports SelectList field types, which are similar to but represented not quite the same as Strings. This change allows go-jira to create issues with custom fields on them that are SelectLists. --- issue.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/issue.go b/issue.go index 97a5fc1..dcf50bc 100644 --- a/issue.go +++ b/issue.go @@ -312,6 +312,12 @@ type TransitionPayload struct { ID string `json:"id" structs:"id"` } +// Option represents an option value in a SelectList or MultiSelect +// custom issue field +type Option struct { + Value string `json:"value" structs:"value"` +} + // UnmarshalJSON will transform the JIRA time into a time.Time // during the transformation of the JIRA JSON response func (t *Time) UnmarshalJSON(b []byte) error { @@ -718,7 +724,7 @@ func (s *IssueService) DoTransition(ticketID, transitionID string) (*Response, e // * metaProject should contain metaInformation about the project where the issue should be created. // * metaIssuetype is the MetaInformation about the Issuetype that needs to be created. // * fieldsConfig is a key->value pair where key represents the name of the field as seen in the UI -// And value is the string value for that particular key. +// And value is the string value for that particular key. // Note: This method doesn't verify that the fieldsConfig is complete with mandatory fields. The fieldsConfig is // supposed to be already verified with MetaIssueType.CheckCompleteAndAvailable. It will however return // error if the key is not found. @@ -775,6 +781,10 @@ func InitIssueWithMetaAndFields(metaProject *MetaProject, metaIssuetype *MetaIss issueFields.Unknowns[jiraKey] = IssueType{ Name: value, } + case "option": + issueFields.Unknowns[jiraKey] = Option{ + Value: value, + } default: return nil, fmt.Errorf("Unknown issue type encountered: %s for %s", valueType, key) } From dda28f9b9c53b3e3aedb34645f721502c7e8c7f1 Mon Sep 17 00:00:00 2001 From: Andreas Fuchs Date: Thu, 27 Apr 2017 09:41:25 -0700 Subject: [PATCH 2/2] Add a test case for the "option" field type --- issue_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/issue_test.go b/issue_test.go index 06e8a81..84caa0f 100644 --- a/issue_test.go +++ b/issue_test.go @@ -894,6 +894,42 @@ func TestInitIssueWithMetaAndFields_PriorityValueType(t *testing.T) { } } +func TestInitIssueWithMetaAndFields_SelectList(t *testing.T) { + metaProject := MetaProject{ + Name: "Engineering - Dept", + Id: "ENG", + } + + fields := tcontainer.NewMarshalMap() + fields["someitem"] = map[string]interface{}{ + "name": "A Select Item", + "schema": map[string]interface{}{ + "type": "option", + }, + } + + metaIssueType := MetaIssueType{ + Fields: fields, + } + + expectedVal := "Value" + fieldConfig := map[string]string{ + "A Select Item": expectedVal, + } + + issue, err := InitIssueWithMetaAndFields(&metaProject, &metaIssueType, fieldConfig) + if err != nil { + t.Errorf("Expected nil error, recieved %s", err) + } + + a, _ := issue.Fields.Unknowns.Value("someitem") + gotVal := a.(Option).Value + + if gotVal != expectedVal { + t.Errorf("Expected %s recieved %s", expectedVal, gotVal) + } +} + func TestInitIssueWithMetaAndFields_IssuetypeValueType(t *testing.T) { metaProject := MetaProject{ Name: "Engineering - Dept",