Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions internal/config/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ type issueTypeFieldConf struct {
Name string `yaml:"name"`
Key string `yaml:"key"`
Schema struct {
DataType string `yaml:"datatype"`
Items string `yaml:"items,omitempty"`
DataType string `yaml:"datatype"`
Items string `yaml:"items,omitempty"`
CustomType string `yaml:"custom,omitempty"`
}
}

Expand Down Expand Up @@ -718,11 +719,13 @@ func (c *JiraCLIConfigGenerator) configureFields() error {
Name: field.Name,
Key: field.ID,
Schema: struct {
DataType string `yaml:"datatype"`
Items string `yaml:"items,omitempty"`
DataType string `yaml:"datatype"`
Items string `yaml:"items,omitempty"`
CustomType string `yaml:"custom,omitempty"`
}{
DataType: field.Schema.DataType,
Items: field.Schema.Items,
DataType: field.Schema.DataType,
Items: field.Schema.Items,
CustomType: field.Schema.CustomType,
},
})
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/jira/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ func constructCustomFields(fields map[string]string, configuredFields []IssueTyp
continue
}

// Check custom type first for specialized handling
if configured.Schema.CustomType == customFieldFormatTeam {
data.Fields.M.customFields[configured.Key] = customFieldTypeTeam{ID: val}
continue
}

switch configured.Schema.DataType {
case customFieldFormatOption:
data.Fields.M.customFields[configured.Key] = customFieldTypeOption{Value: val}
Expand Down
42 changes: 42 additions & 0 deletions pkg/jira/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,45 @@ func TestCreateEpicNextGen(t *testing.T) {
_, err = client.CreateV2(&requestData)
assert.Error(t, &ErrUnexpectedResponse{}, err)
}

func TestCreateWithTeamCustomField(t *testing.T) {
expectedBody := `{"update":{},"fields":{"project":{"key":"TEST"},"issuetype":{"name":"Task"},` +
`"summary":"Test task","customfield_10001":{"id":"8eb445e7-c606-4500-9b0b-ba87184f2a08"}}}`
testServer := createTestServer{code: 201}
server := testServer.serve(t, expectedBody)
defer server.Close()

client := NewClient(Config{Server: server.URL}, WithTimeout(3*time.Second))

configuredFields := []IssueTypeField{
{
Name: "Team",
Key: "customfield_10001",
Schema: struct {
DataType string `json:"type"`
Items string `json:"items,omitempty"`
CustomType string `json:"custom,omitempty"`
}{
DataType: "any",
CustomType: "com.atlassian.teams:rm-teams-custom-field-team",
},
},
}

requestData := CreateRequest{
Project: "TEST",
IssueType: "Task",
Summary: "Test task",
CustomFields: map[string]string{"team": "8eb445e7-c606-4500-9b0b-ba87184f2a08"},
}
requestData.WithCustomFields(configuredFields)

actual, err := client.CreateV2(&requestData)
assert.NoError(t, err)

expected := &CreateResponse{
ID: "10057",
Key: "TEST-3",
}
assert.Equal(t, expected, actual)
}
9 changes: 9 additions & 0 deletions pkg/jira/customfield.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const (
customFieldFormatArray = "array"
customFieldFormatNumber = "number"
customFieldFormatProject = "project"
customFieldFormatTeam = "com.atlassian.teams:rm-teams-custom-field-team"
)

type customField map[string]interface{}
Expand Down Expand Up @@ -39,3 +40,11 @@ type customFieldTypeProject struct {
type customFieldTypeProjectSet struct {
Set customFieldTypeProject `json:"set"`
}

type customFieldTypeTeam struct {
ID string `json:"id"`
}

type customFieldTypeTeamSet struct {
Set customFieldTypeTeam `json:"set"`
}
6 changes: 6 additions & 0 deletions pkg/jira/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,12 @@ func constructCustomFieldsForEdit(fields map[string]string, configuredFields []I
continue
}

// Check custom type first for specialized handling
if configured.Schema.CustomType == customFieldFormatTeam {
data.Update.M.customFields[configured.Key] = []customFieldTypeTeamSet{{Set: customFieldTypeTeam{ID: val}}}
continue
}

switch configured.Schema.DataType {
case customFieldFormatOption:
data.Update.M.customFields[configured.Key] = []customFieldTypeOptionSet{{Set: customFieldTypeOption{Value: val}}}
Expand Down
26 changes: 15 additions & 11 deletions pkg/jira/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,10 @@ func TestGetField(t *testing.T) {
Name: "Fix Version/s",
Custom: false,
Schema: struct {
DataType string `json:"type"`
Items string `json:"items,omitempty"`
FieldID int `json:"customId,omitempty"`
DataType string `json:"type"`
Items string `json:"items,omitempty"`
FieldID int `json:"customId,omitempty"`
CustomType string `json:"custom,omitempty"`
}{
DataType: "array",
Items: "version",
Expand All @@ -651,22 +652,25 @@ func TestGetField(t *testing.T) {
Name: "Original story points",
Custom: true,
Schema: struct {
DataType string `json:"type"`
Items string `json:"items,omitempty"`
FieldID int `json:"customId,omitempty"`
DataType string `json:"type"`
Items string `json:"items,omitempty"`
FieldID int `json:"customId,omitempty"`
CustomType string `json:"custom,omitempty"`
}{
DataType: "number",
FieldID: 10111,
DataType: "number",
FieldID: 10111,
CustomType: "com.atlassian.jpo:jpo-custom-field-original-story-points",
},
},
{
ID: "timespent",
Name: "Time Spent",
Custom: false,
Schema: struct {
DataType string `json:"type"`
Items string `json:"items,omitempty"`
FieldID int `json:"customId,omitempty"`
DataType string `json:"type"`
Items string `json:"items,omitempty"`
FieldID int `json:"customId,omitempty"`
CustomType string `json:"custom,omitempty"`
}{
DataType: "number",
},
Expand Down
12 changes: 7 additions & 5 deletions pkg/jira/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ type Field struct {
Name string `json:"name"`
Custom bool `json:"custom"`
Schema struct {
DataType string `json:"type"`
Items string `json:"items,omitempty"`
FieldID int `json:"customId,omitempty"`
DataType string `json:"type"`
Items string `json:"items,omitempty"`
FieldID int `json:"customId,omitempty"`
CustomType string `json:"custom,omitempty"`
} `json:"schema"`
}

Expand All @@ -143,8 +144,9 @@ type IssueTypeField struct {
Name string `json:"name"`
Key string `json:"key"`
Schema struct {
DataType string `json:"type"`
Items string `json:"items,omitempty"`
DataType string `json:"type"`
Items string `json:"items,omitempty"`
CustomType string `json:"custom,omitempty"`
} `json:"schema"`
FieldID string `json:"fieldId,omitempty"`
}
Expand Down