Skip to content

Commit

Permalink
feat: Add original estimate option to issue creation (#748)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodcloutier authored Jul 27, 2024
1 parent a9051b3 commit 527d3cd
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 68 deletions.
63 changes: 34 additions & 29 deletions internal/cmd/issue/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,21 @@ func create(cmd *cobra.Command, _ []string) {
defer s.Stop()

cr := jira.CreateRequest{
Project: project,
IssueType: params.IssueType,
ParentIssueKey: params.ParentIssueKey,
Summary: params.Summary,
Body: params.Body,
Reporter: params.Reporter,
Assignee: params.Assignee,
Priority: params.Priority,
Labels: params.Labels,
Components: params.Components,
FixVersions: params.FixVersions,
AffectsVersions: params.AffectsVersions,
CustomFields: params.CustomFields,
EpicField: viper.GetString("epic.link"),
Project: project,
IssueType: params.IssueType,
ParentIssueKey: params.ParentIssueKey,
Summary: params.Summary,
Body: params.Body,
Reporter: params.Reporter,
Assignee: params.Assignee,
Priority: params.Priority,
Labels: params.Labels,
Components: params.Components,
FixVersions: params.FixVersions,
AffectsVersions: params.AffectsVersions,
OriginalEstimate: params.OriginalEstimate,
CustomFields: params.CustomFields,
EpicField: viper.GetString("epic.link"),
}
cr.ForProjectType(projectType)
cr.ForInstallationType(installation)
Expand Down Expand Up @@ -347,6 +348,9 @@ func parseFlags(flags query.FlagParser) *cmdcommon.CreateParams {
affectsVersions, err := flags.GetStringArray("affects-version")
cmdutil.ExitIfError(err)

originalEstimate, err := flags.GetString("original-estimate")
cmdutil.ExitIfError(err)

custom, err := flags.GetStringToString("custom")
cmdutil.ExitIfError(err)

Expand All @@ -360,20 +364,21 @@ func parseFlags(flags query.FlagParser) *cmdcommon.CreateParams {
cmdutil.ExitIfError(err)

return &cmdcommon.CreateParams{
IssueType: issueType,
ParentIssueKey: parentIssueKey,
Summary: summary,
Body: body,
Priority: priority,
Assignee: assignee,
Labels: labels,
Reporter: reporter,
Components: components,
FixVersions: fixVersions,
AffectsVersions: affectsVersions,
CustomFields: custom,
Template: template,
NoInput: noInput,
Debug: debug,
IssueType: issueType,
ParentIssueKey: parentIssueKey,
Summary: summary,
Body: body,
Priority: priority,
Assignee: assignee,
Labels: labels,
Reporter: reporter,
Components: components,
FixVersions: fixVersions,
AffectsVersions: affectsVersions,
OriginalEstimate: originalEstimate,
CustomFields: custom,
Template: template,
NoInput: noInput,
Debug: debug,
}
}
34 changes: 18 additions & 16 deletions internal/cmdcommon/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@ const (

// CreateParams holds parameters for create command.
type CreateParams struct {
Name string
IssueType string
ParentIssueKey string
Summary string
Body string
Priority string
Reporter string
Assignee string
Labels []string
Components []string
FixVersions []string
AffectsVersions []string
CustomFields map[string]string
Template string
NoInput bool
Debug bool
Name string
IssueType string
ParentIssueKey string
Summary string
Body string
Priority string
Reporter string
Assignee string
Labels []string
Components []string
FixVersions []string
AffectsVersions []string
OriginalEstimate string
CustomFields map[string]string
Template string
NoInput bool
Debug bool
}

// SetCreateFlags sets flags supported by create command.
Expand All @@ -63,6 +64,7 @@ And, this field is mandatory when creating a sub-task.`)
cmd.Flags().StringArrayP("component", "C", []string{}, prefix+" components")
cmd.Flags().StringArray("fix-version", []string{}, "Release info (fixVersions)")
cmd.Flags().StringArray("affects-version", []string{}, "Release info (affectsVersions)")
cmd.Flags().StringP("original-estimate", "e", "", prefix+" Original estimate")
cmd.Flags().StringToString("custom", custom, "Set custom fields")
cmd.Flags().StringP("template", "T", "", "Path to a file to read body/description from")
cmd.Flags().Bool("web", false, "Open in web browser after successful creation")
Expand Down
27 changes: 17 additions & 10 deletions pkg/jira/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ type CreateRequest struct {
IssueType string
// ParentIssueKey is required when creating a sub-task for classic project.
// This can also be used to attach epic for next-gen project.
ParentIssueKey string
Summary string
Body interface{} // string in v1/v2 and adf.ADF in v3
Reporter string
Assignee string
Priority string
Labels []string
Components []string
FixVersions []string
AffectsVersions []string
ParentIssueKey string
Summary string
Body interface{} // string in v1/v2 and adf.ADF in v3
Reporter string
Assignee string
Priority string
Labels []string
Components []string
FixVersions []string
AffectsVersions []string
OriginalEstimate string
// EpicField is the dynamic epic field name
// that changes per jira installation.
EpicField string
Expand Down Expand Up @@ -132,6 +133,9 @@ func (*Client) getRequestData(req *CreateRequest) *createRequest {
Summary: req.Summary,
Labels: req.Labels,
epicField: req.EpicField,
TimeTracking: struct {
OriginalEstimate string `json:"originalEstimate,omitempty"`
}{OriginalEstimate: req.OriginalEstimate},
}

switch v := req.Body.(type) {
Expand Down Expand Up @@ -303,6 +307,9 @@ type createFields struct {
AffectsVersions []struct {
Name string `json:"name,omitempty"`
} `json:"versions,omitempty"`
TimeTracking struct {
OriginalEstimate string `json:"originalEstimate,omitempty"`
} `json:"timetracking,omitempty"`
epicField string
customFields customField
}
Expand Down
28 changes: 15 additions & 13 deletions pkg/jira/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,25 @@ func (c *createTestServer) statusCode(code int) {
func TestCreate(t *testing.T) {
expectedBody := `{"update":{},"fields":{"project":{"key":"TEST"},"issuetype":{"name":"Bug"},` +
`"summary":"Test bug","description":"Test description","priority":{"name":"Normal"},"labels":["test","dev"],` +
`"components":[{"name":"BE"},{"name":"FE"}],"fixVersions":[{"name":"v2.0"},{"name":"v2.1-hotfix"}],"versions":[{"name":"v3.0"},{"name":"v3.1-hotfix"}]}}`
`"components":[{"name":"BE"},{"name":"FE"}],"fixVersions":[{"name":"v2.0"},{"name":"v2.1-hotfix"}],"versions":[{"name":"v3.0"},{"name":"v3.1-hotfix"}],` +
`"timetracking":{"originalEstimate":"2d"}}}`
testServer := createTestServer{code: 201}
server := testServer.serve(t, expectedBody)
defer server.Close()

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

requestData := CreateRequest{
Project: "TEST",
IssueType: "Bug",
Summary: "Test bug",
Body: "Test description",
Priority: "Normal",
Labels: []string{"test", "dev"},
Components: []string{"BE", "FE"},
FixVersions: []string{"v2.0", "v2.1-hotfix"},
AffectsVersions: []string{"v3.0", "v3.1-hotfix"},
Project: "TEST",
IssueType: "Bug",
Summary: "Test bug",
Body: "Test description",
Priority: "Normal",
Labels: []string{"test", "dev"},
Components: []string{"BE", "FE"},
FixVersions: []string{"v2.0", "v2.1-hotfix"},
AffectsVersions: []string{"v3.0", "v3.1-hotfix"},
OriginalEstimate: "2d",
}
actual, err := client.CreateV2(&requestData)
assert.NoError(t, err)
Expand All @@ -82,7 +84,7 @@ func TestCreate(t *testing.T) {

func TestCreateSubtask(t *testing.T) {
expectedBody := `{"update":{},"fields":{"project":{"key":"TEST"},"issuetype":{"name":"Sub-task"},` +
`"parent":{"key":"TEST-123"},"summary":"Test sub-task","description":"Test description"}}`
`"parent":{"key":"TEST-123"},"summary":"Test sub-task","description":"Test description","timetracking":{}}}`
testServer := createTestServer{code: 201}
server := testServer.serve(t, expectedBody)
defer server.Close()
Expand Down Expand Up @@ -114,7 +116,7 @@ func TestCreateSubtask(t *testing.T) {

func TestCreateEpic(t *testing.T) {
expectedBody := `{"update":{},"fields":{"customfield_10001":"CLI","description":"Test description","issuetype":{"name":` +
`"Bug"},"priority":{"name":"Normal"},"project":{"key":"TEST"},"summary":"Test bug"}}`
`"Bug"},"priority":{"name":"Normal"},"project":{"key":"TEST"},"summary":"Test bug", "timetracking":{}}}`
testServer := createTestServer{code: 201}
server := testServer.serve(t, expectedBody)
defer server.Close()
Expand Down Expand Up @@ -146,7 +148,7 @@ func TestCreateEpic(t *testing.T) {

func TestCreateEpicNextGen(t *testing.T) {
expectedBody := `{"update":{},"fields":{"description":"Test description","issuetype":{"name":"Bug"},` +
`"parent":{"key":"TEST-123"},"project":{"key":"TEST"},"summary":"Test bug"}}`
`"parent":{"key":"TEST-123"},"project":{"key":"TEST"},"summary":"Test bug","timetracking":{}}}`
testServer := createTestServer{code: 201}
server := testServer.serve(t, expectedBody)
defer server.Close()
Expand Down

0 comments on commit 527d3cd

Please sign in to comment.