-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
129 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package jira | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata" | ||
) | ||
|
||
type ComponentProvider interface { | ||
ProvideComponent() *jiradata.Component | ||
} | ||
|
||
// https://docs.atlassian.com/jira/REST/cloud/#api/2/component-createComponent | ||
func (j *Jira) CreateComponent(cp ComponentProvider) (*jiradata.Component, error) { | ||
req := cp.ProvideComponent() | ||
encoded, err := json.Marshal(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
uri := fmt.Sprintf("%s/rest/api/2/component", j.Endpoint) | ||
resp, err := j.UA.Post(uri, "application/json", bytes.NewBuffer(encoded)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode == 201 { | ||
results := &jiradata.Component{} | ||
return results, readJSON(resp.Body, results) | ||
} | ||
return nil, responseError(resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package jiracli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata" | ||
kingpin "gopkg.in/alecthomas/kingpin.v2" | ||
) | ||
|
||
type ComponentAddOptions struct { | ||
GlobalOptions | ||
Overrides map[string]string | ||
} | ||
|
||
func (jc *JiraCli) CmdComponentAddRegistry() *CommandRegistryEntry { | ||
opts := ComponentAddOptions{ | ||
GlobalOptions: GlobalOptions{ | ||
Template: "component-add", | ||
}, | ||
Overrides: map[string]string{}, | ||
} | ||
|
||
return &CommandRegistryEntry{ | ||
"ComponentAdd issue", | ||
func() error { | ||
return jc.CmdComponentAdd(&opts) | ||
}, | ||
func(cmd *kingpin.CmdClause) error { | ||
return jc.CmdComponentAddUsage(cmd, &opts) | ||
}, | ||
} | ||
} | ||
|
||
func (jc *JiraCli) CmdComponentAddUsage(cmd *kingpin.CmdClause, opts *ComponentAddOptions) error { | ||
if err := jc.GlobalUsage(cmd, &opts.GlobalOptions); err != nil { | ||
return err | ||
} | ||
jc.EditorUsage(cmd, &opts.GlobalOptions) | ||
jc.TemplateUsage(cmd, &opts.GlobalOptions) | ||
cmd.Flag("noedit", "Disable opening the editor").BoolVar(&opts.SkipEditing) | ||
cmd.Flag("project", "project to create component in").Short('p').PreAction(func(ctx *kingpin.ParseContext) error { | ||
opts.Overrides["project"] = flagValue(ctx, "project") | ||
return nil | ||
}).String() | ||
cmd.Flag("name", "name of component").Short('n').PreAction(func(ctx *kingpin.ParseContext) error { | ||
opts.Overrides["name"] = flagValue(ctx, "name") | ||
return nil | ||
}).String() | ||
cmd.Flag("description", "description of component").Short('d').PreAction(func(ctx *kingpin.ParseContext) error { | ||
opts.Overrides["description"] = flagValue(ctx, "description") | ||
return nil | ||
}).String() | ||
cmd.Flag("lead", "person that acts as lead for component").Short('l').PreAction(func(ctx *kingpin.ParseContext) error { | ||
opts.Overrides["lead"] = flagValue(ctx, "lead") | ||
return nil | ||
}).String() | ||
return nil | ||
} | ||
|
||
// CmdComponentAdd sends the provided overrides to the "component-add" template for editing, then | ||
// will parse the edited document as YAML and submit the document to jira. | ||
func (jc *JiraCli) CmdComponentAdd(opts *ComponentAddOptions) error { | ||
input := struct { | ||
Overrides map[string]string | ||
}{ | ||
opts.Overrides, | ||
} | ||
|
||
var err error | ||
component := &jiradata.Component{} | ||
err = jc.editLoop(&opts.GlobalOptions, &input, component, func() error { | ||
component, err = jc.CreateComponent(component) | ||
return err | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("OK %s %s\n", component.Project, component.Name) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters