1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-03-21 21:07:03 +02:00

Merge pull request #71 from antifuchs/add-option-field-type

Add the "option" field type for custom fields
This commit is contained in:
Andy Grunwald 2017-05-01 14:49:07 +02:00 committed by GitHub
commit 792e94b7c0
2 changed files with 47 additions and 1 deletions

View File

@ -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 {
@ -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)
}

View File

@ -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",