mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-19 04:33:28 +02:00
[#100] add support for posting, fetching, listing and removing attachments
This commit is contained in:
@@ -2,4 +2,9 @@ jira
|
|||||||
schemas/*.json
|
schemas/*.json
|
||||||
t/.gnupg/random_seed
|
t/.gnupg/random_seed
|
||||||
t/issue.props
|
t/issue.props
|
||||||
|
t/attach.props
|
||||||
|
t/garbage.bin
|
||||||
|
t/attach1.txt
|
||||||
|
t/binary.out
|
||||||
|
t/foobar.bin
|
||||||
dist
|
dist
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package jira
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
||||||
|
)
|
||||||
|
|
||||||
|
// https://docs.atlassian.com/jira/REST/cloud/#api/2/attachment-getAttachment
|
||||||
|
func (j *Jira) GetAttachment(id string) (*jiradata.Attachment, error) {
|
||||||
|
return GetAttachment(j.UA, j.Endpoint, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAttachment(ua HttpClient, endpoint string, id string) (*jiradata.Attachment, error) {
|
||||||
|
uri := fmt.Sprintf("%s/rest/api/2/attachment/%s", endpoint, id)
|
||||||
|
resp, err := ua.GetJSON(uri)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode == 200 {
|
||||||
|
results := &jiradata.Attachment{}
|
||||||
|
return results, readJSON(resp.Body, results)
|
||||||
|
}
|
||||||
|
return nil, responseError(resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://docs.atlassian.com/jira/REST/cloud/#api/2/attachment-removeAttachment
|
||||||
|
func (j *Jira) RemoveAttachment(id string) error {
|
||||||
|
return RemoveAttachment(j.UA, j.Endpoint, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RemoveAttachment(ua HttpClient, endpoint string, id string) error {
|
||||||
|
uri := fmt.Sprintf("%s/rest/api/2/attachment/%s", endpoint, id)
|
||||||
|
resp, err := ua.Delete(uri)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode == 204 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return responseError(resp)
|
||||||
|
}
|
||||||
@@ -295,6 +295,24 @@ func main() {
|
|||||||
Command: "issuetypes",
|
Command: "issuetypes",
|
||||||
Entry: jiracmd.CmdIssueTypesRegistry(),
|
Entry: jiracmd.CmdIssueTypesRegistry(),
|
||||||
},
|
},
|
||||||
|
jiracli.CommandRegistry{
|
||||||
|
Command: "attach create",
|
||||||
|
Entry: jiracmd.CmdAttachCreateRegistry(),
|
||||||
|
},
|
||||||
|
jiracli.CommandRegistry{
|
||||||
|
Command: "attach list",
|
||||||
|
Entry: jiracmd.CmdAttachListRegistry(),
|
||||||
|
Aliases: []string{"ls"},
|
||||||
|
},
|
||||||
|
jiracli.CommandRegistry{
|
||||||
|
Command: "attach get",
|
||||||
|
Entry: jiracmd.CmdAttachGetRegistry(),
|
||||||
|
},
|
||||||
|
jiracli.CommandRegistry{
|
||||||
|
Command: "attach remove",
|
||||||
|
Entry: jiracmd.CmdAttachRemoveRegistry(),
|
||||||
|
Aliases: []string{"rm"},
|
||||||
|
},
|
||||||
jiracli.CommandRegistry{
|
jiracli.CommandRegistry{
|
||||||
Command: "export-templates",
|
Command: "export-templates",
|
||||||
Entry: jiracmd.CmdExportTemplatesRegistry(),
|
Entry: jiracmd.CmdExportTemplatesRegistry(),
|
||||||
|
|||||||
@@ -4,8 +4,13 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"mime/multipart"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/coryb/oreo"
|
||||||
|
|
||||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -533,3 +538,50 @@ func IssueAssign(ua HttpClient, endpoint string, issue, name string) error {
|
|||||||
}
|
}
|
||||||
return responseError(resp)
|
return responseError(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://docs.atlassian.com/jira/REST/cloud/#api/2/issue/{issueIdOrKey}/attachments-addAttachment
|
||||||
|
func (j *Jira) IssueAttachFile(issue, filename string, contents io.Reader) (*jiradata.ListOfAttachment, error) {
|
||||||
|
return IssueAttachFile(j.UA, j.Endpoint, issue, filename, contents)
|
||||||
|
}
|
||||||
|
|
||||||
|
func IssueAttachFile(ua HttpClient, endpoint string, issue, filename string, contents io.Reader) (*jiradata.ListOfAttachment, error) {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
w := multipart.NewWriter(&buf)
|
||||||
|
formFile, err := w.CreateFormFile("file", filename)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, err = io.Copy(formFile, contents)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
uri, err := url.Parse(fmt.Sprintf("%s/rest/api/2/issue/%s/attachments", endpoint, issue))
|
||||||
|
req := oreo.RequestBuilder(uri).WithMethod("POST").WithHeader(
|
||||||
|
"X-Atlassian-Token", "no-check",
|
||||||
|
).WithHeader(
|
||||||
|
"Accept", "application/json",
|
||||||
|
).WithContentType(w.FormDataContentType()).WithBody(&buf).Build()
|
||||||
|
w.Close()
|
||||||
|
|
||||||
|
resp, err := ua.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode == 200 {
|
||||||
|
// FIXME move this to a test, and run go tests as part of our regression
|
||||||
|
if false {
|
||||||
|
// this is because schema is wrong, defaults to type `int`, so we manually change it
|
||||||
|
// to `string`. If the jiradata is regenerated we need to manually make the change
|
||||||
|
// again.
|
||||||
|
log.Debugf("Assert Attachment.ID is a string, rather than int: %v", &jiradata.Attachment{
|
||||||
|
ID: jiradata.IntOrString(0),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
results := jiradata.ListOfAttachment{}
|
||||||
|
return &results, readJSON(resp.Body, &results)
|
||||||
|
}
|
||||||
|
return nil, responseError(resp)
|
||||||
|
}
|
||||||
|
|||||||
+20
-9
@@ -160,7 +160,8 @@ func TemplateProcessor() *template.Template {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ConfigTemplate(fig *figtree.FigTree, template, command string, opts interface{}) (string, error) {
|
func ConfigTemplate(fig *figtree.FigTree, template, command string, opts interface{}) (string, error) {
|
||||||
tmp, err := translateOptions(opts)
|
var tmp interface{}
|
||||||
|
err := ConvertType(opts, &tmp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -178,11 +179,11 @@ func ConfigTemplate(fig *figtree.FigTree, template, command string, opts interfa
|
|||||||
return buf.String(), nil
|
return buf.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func translateOptions(opts interface{}) (interface{}, error) {
|
func ConvertType(input interface{}, output interface{}) error {
|
||||||
// HACK HACK HACK: convert data formats to json for backwards compatibilty with templates
|
// HACK HACK HACK: convert data formats to json for backwards compatibilty with templates
|
||||||
jsonData, err := json.Marshal(opts)
|
jsonData, err := json.Marshal(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func(mapType, iface reflect.Type) {
|
defer func(mapType, iface reflect.Type) {
|
||||||
@@ -193,11 +194,10 @@ func translateOptions(opts interface{}) (interface{}, error) {
|
|||||||
yaml.DefaultMapType = reflect.TypeOf(map[string]interface{}{})
|
yaml.DefaultMapType = reflect.TypeOf(map[string]interface{}{})
|
||||||
yaml.IfaceType = yaml.DefaultMapType.Elem()
|
yaml.IfaceType = yaml.DefaultMapType.Elem()
|
||||||
|
|
||||||
var rawData interface{}
|
if err := yaml.Unmarshal(jsonData, output); err != nil {
|
||||||
if err := yaml.Unmarshal(jsonData, &rawData); err != nil {
|
return err
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
return &rawData, nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +212,8 @@ func RunTemplate(templateName string, data interface{}, out io.Writer) error {
|
|||||||
out = os.Stdout
|
out = os.Stdout
|
||||||
}
|
}
|
||||||
|
|
||||||
rawData, err := translateOptions(data)
|
var rawData interface{}
|
||||||
|
err = ConvertType(data, &rawData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -228,6 +229,7 @@ func RunTemplate(templateName string, data interface{}, out io.Writer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var AllTemplates = map[string]string{
|
var AllTemplates = map[string]string{
|
||||||
|
"attach-list": defaultAttachListTemplate,
|
||||||
"comment": defaultCommentTemplate,
|
"comment": defaultCommentTemplate,
|
||||||
"component-add": defaultComponentAddTemplate,
|
"component-add": defaultComponentAddTemplate,
|
||||||
"components": defaultComponentsTemplate,
|
"components": defaultComponentsTemplate,
|
||||||
@@ -268,6 +270,15 @@ const defaultTableTemplate = `{{/* table template */ -}}
|
|||||||
{{ end -}}
|
{{ end -}}
|
||||||
+{{ "-" | rep 16 }}+{{ "-" | rep $w }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 12 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+
|
+{{ "-" | rep 16 }}+{{ "-" | rep $w }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 12 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+
|
||||||
`
|
`
|
||||||
|
const defaultAttachListTemplate = `{{/* table template */ -}}
|
||||||
|
+{{ "-" | rep 12 }}+{{ "-" | rep 30 }}+{{ "-" | rep 12 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+
|
||||||
|
| {{printf "%-10s" "id"}} | {{printf "%-28s" "filename"}} | {{printf "%-10s" "bytes"}} | {{printf "%-12s" "user"}} | {{printf "%-12s" "created"}} |
|
||||||
|
+{{ "-" | rep 12 }}+{{ "-" | rep 30 }}+{{ "-" | rep 12 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+
|
||||||
|
{{range . -}}
|
||||||
|
| {{.id | printf "%10d" }} | {{.filename | printf "%-28s"}} | {{.size | printf "%10d"}} | {{.author.name | printf "%-12s"}} | {{.created | age | printf "%-12s"}} |
|
||||||
|
{{end -}}
|
||||||
|
+{{ "-" | rep 12 }}+{{ "-" | rep 30 }}+{{ "-" | rep 12 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+
|
||||||
|
`
|
||||||
|
|
||||||
const defaultViewTemplate = `{{/* view template */ -}}
|
const defaultViewTemplate = `{{/* view template */ -}}
|
||||||
issue: {{ .key }}
|
issue: {{ .key }}
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package jiracmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
|
|
||||||
|
"github.com/coryb/figtree"
|
||||||
|
"github.com/coryb/oreo"
|
||||||
|
jira "gopkg.in/Netflix-Skunkworks/go-jira.v1"
|
||||||
|
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
|
||||||
|
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||||
|
yaml "gopkg.in/coryb/yaml.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AttachCreateOptions struct {
|
||||||
|
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
|
||||||
|
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
|
||||||
|
Attachment string `yaml:"attachment,omitempty" json:"attachment,omitempty"`
|
||||||
|
Filename string `yaml:"filename,omitempty" json:"filename,omitempty"`
|
||||||
|
SaveFile string `yaml:"savefile,omitempty" json:"savefile,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func CmdAttachCreateRegistry() *jiracli.CommandRegistryEntry {
|
||||||
|
opts := AttachCreateOptions{}
|
||||||
|
|
||||||
|
return &jiracli.CommandRegistryEntry{
|
||||||
|
"Attach file to issue",
|
||||||
|
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
|
||||||
|
jiracli.LoadConfigs(cmd, fig, &opts)
|
||||||
|
return CmdAttachCreateUsage(cmd, &opts)
|
||||||
|
},
|
||||||
|
func(o *oreo.Client, globals *jiracli.GlobalOptions) error {
|
||||||
|
return CmdAttachCreate(o, globals, &opts)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CmdAttachCreateUsage(cmd *kingpin.CmdClause, opts *AttachCreateOptions) error {
|
||||||
|
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
|
||||||
|
cmd.Flag("saveFile", "Write attachment information as yaml to file").StringVar(&opts.SaveFile)
|
||||||
|
cmd.Flag("filename", "Filename to use for attachment").Short('f').StringVar(&opts.Filename)
|
||||||
|
cmd.Arg("ISSUE", "issue to assign").Required().StringVar(&opts.Issue)
|
||||||
|
cmd.Arg("ATTACHMENT", "File to attach to issue, if not provided read from stdin").StringVar(&opts.Attachment)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CmdAttachCreate(o *oreo.Client, globals *jiracli.GlobalOptions, opts *AttachCreateOptions) error {
|
||||||
|
var contents *os.File
|
||||||
|
var err error
|
||||||
|
if opts.Attachment == "" {
|
||||||
|
if terminal.IsTerminal(int(os.Stdin.Fd())) {
|
||||||
|
return fmt.Errorf("ATTACHMENT argument required or redirect from STDIN")
|
||||||
|
}
|
||||||
|
contents = os.Stdin
|
||||||
|
if opts.Filename == "" {
|
||||||
|
return fmt.Errorf("--filename required when reading from stdin")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
contents, err = os.Open(opts.Attachment)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if opts.Filename == "" {
|
||||||
|
opts.Filename = opts.Attachment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
attachments, err := jira.IssueAttachFile(o, globals.Endpoint.Value, opts.Issue, opts.Filename, contents)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Sort(sort.Reverse(attachments))
|
||||||
|
|
||||||
|
if opts.SaveFile != "" {
|
||||||
|
fh, err := os.Create(opts.SaveFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer fh.Close()
|
||||||
|
out, err := yaml.Marshal((*attachments)[0])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fh.Write(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !globals.Quiet.Value {
|
||||||
|
fmt.Printf("OK %d %s\n", (*attachments)[0].ID, (*attachments)[0].Content)
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts.Browse.Value {
|
||||||
|
return CmdBrowse(globals, opts.Issue)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package jiracmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/coryb/figtree"
|
||||||
|
"github.com/coryb/oreo"
|
||||||
|
jira "gopkg.in/Netflix-Skunkworks/go-jira.v1"
|
||||||
|
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
|
||||||
|
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AttachGetOptions struct {
|
||||||
|
AttachmentID string `yaml:"attachment-id,omitempty" json:"attachment-id,omitempty"`
|
||||||
|
OutputFile string `yaml:"output-file,omitempty" json:"output-file,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func CmdAttachGetRegistry() *jiracli.CommandRegistryEntry {
|
||||||
|
opts := AttachGetOptions{}
|
||||||
|
|
||||||
|
return &jiracli.CommandRegistryEntry{
|
||||||
|
"Fetch attachment",
|
||||||
|
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
|
||||||
|
jiracli.LoadConfigs(cmd, fig, &opts)
|
||||||
|
return CmdAttachGetUsage(cmd, &opts)
|
||||||
|
},
|
||||||
|
func(o *oreo.Client, globals *jiracli.GlobalOptions) error {
|
||||||
|
return CmdAttachGet(o, globals, &opts)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CmdAttachGetUsage(cmd *kingpin.CmdClause, opts *AttachGetOptions) error {
|
||||||
|
cmd.Flag("output", "Write attachment to specified file name, '-' for stdout").Short('o').StringVar(&opts.OutputFile)
|
||||||
|
cmd.Arg("ATTACHMENT-ID", "Attachment id to fetch").StringVar(&opts.AttachmentID)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CmdAttachGet(o *oreo.Client, globals *jiracli.GlobalOptions, opts *AttachGetOptions) error {
|
||||||
|
attachment, err := jira.GetAttachment(o, globals.Endpoint.Value, opts.AttachmentID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := o.Get(attachment.Content)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
var output *os.File
|
||||||
|
if opts.OutputFile == "-" {
|
||||||
|
output = os.Stdout
|
||||||
|
} else if opts.OutputFile != "" {
|
||||||
|
output, err = os.Create(opts.OutputFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer output.Close()
|
||||||
|
} else {
|
||||||
|
output, err = os.Create(attachment.Filename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer output.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = io.Copy(output, resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
output.Close()
|
||||||
|
if opts.OutputFile != "-" && !globals.Quiet.Value {
|
||||||
|
fmt.Printf("OK Wrote %s\n", output.Name())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package jiracmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"github.com/coryb/figtree"
|
||||||
|
"github.com/coryb/oreo"
|
||||||
|
"gopkg.in/Netflix-Skunkworks/go-jira.v1"
|
||||||
|
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
|
||||||
|
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
||||||
|
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AttachListOptions struct {
|
||||||
|
jiracli.CommonOptions `yaml:",inline" json:",inline" figtree:",inline"`
|
||||||
|
Issue string `yaml:"issue,omitempty" json:"issue,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func CmdAttachListRegistry() *jiracli.CommandRegistryEntry {
|
||||||
|
opts := AttachListOptions{
|
||||||
|
CommonOptions: jiracli.CommonOptions{
|
||||||
|
Template: figtree.NewStringOption("attach-list"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return &jiracli.CommandRegistryEntry{
|
||||||
|
"Prints issue details",
|
||||||
|
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
|
||||||
|
jiracli.LoadConfigs(cmd, fig, &opts)
|
||||||
|
return CmdAttachListUsage(cmd, &opts)
|
||||||
|
},
|
||||||
|
func(o *oreo.Client, globals *jiracli.GlobalOptions) error {
|
||||||
|
return CmdAttachList(o, globals, &opts)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CmdAttachListUsage(cmd *kingpin.CmdClause, opts *AttachListOptions) error {
|
||||||
|
jiracli.BrowseUsage(cmd, &opts.CommonOptions)
|
||||||
|
jiracli.TemplateUsage(cmd, &opts.CommonOptions)
|
||||||
|
cmd.Arg("ISSUE", "Issue id to lookup attachments").Required().StringVar(&opts.Issue)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CmdAttachList(o *oreo.Client, globals *jiracli.GlobalOptions, opts *AttachListOptions) error {
|
||||||
|
data, err := jira.GetIssue(o, globals.Endpoint.Value, opts.Issue, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// need to conver the interface{} "attachment" field to an actual
|
||||||
|
// ListOfAttachment object so we can sort it
|
||||||
|
var attachments jiradata.ListOfAttachment
|
||||||
|
err = jiracli.ConvertType(data.Fields["attachment"], &attachments)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
sort.Sort(&attachments)
|
||||||
|
|
||||||
|
if err := opts.PrintTemplate(attachments); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if opts.Browse.Value {
|
||||||
|
return CmdBrowse(globals, opts.Issue)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package jiracmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/coryb/figtree"
|
||||||
|
"github.com/coryb/oreo"
|
||||||
|
jira "gopkg.in/Netflix-Skunkworks/go-jira.v1"
|
||||||
|
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
|
||||||
|
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AttachRemoveOptions struct {
|
||||||
|
AttachmentID string `yaml:"attachment-id,omitempty" json:"attachment-id,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func CmdAttachRemoveRegistry() *jiracli.CommandRegistryEntry {
|
||||||
|
opts := AttachRemoveOptions{}
|
||||||
|
|
||||||
|
return &jiracli.CommandRegistryEntry{
|
||||||
|
"Delete attachment",
|
||||||
|
func(fig *figtree.FigTree, cmd *kingpin.CmdClause) error {
|
||||||
|
jiracli.LoadConfigs(cmd, fig, &opts)
|
||||||
|
return CmdAttachRemoveUsage(cmd, &opts)
|
||||||
|
},
|
||||||
|
func(o *oreo.Client, globals *jiracli.GlobalOptions) error {
|
||||||
|
return CmdAttachRemove(o, globals, &opts)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CmdAttachRemoveUsage(cmd *kingpin.CmdClause, opts *AttachRemoveOptions) error {
|
||||||
|
cmd.Arg("ATTACHMENT-ID", "Attachment id to fetch").StringVar(&opts.AttachmentID)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CmdAttachRemove(o *oreo.Client, globals *jiracli.GlobalOptions, opts *AttachRemoveOptions) error {
|
||||||
|
if err := jira.RemoveAttachment(o, globals.Endpoint.Value, opts.AttachmentID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !globals.Quiet.Value {
|
||||||
|
fmt.Printf("OK Deleted Attachment %s\n", opts.AttachmentID)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,179 @@
|
|||||||
|
package jiradata
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
// This Code is Generated by SlipScheme Project:
|
||||||
|
// https://github.com/coryb/slipscheme
|
||||||
|
//
|
||||||
|
// Generated with command:
|
||||||
|
// slipscheme -dir jiradata -pkg jiradata -overwrite schemas/ListofAttachment.json
|
||||||
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
// DO NOT EDIT //
|
||||||
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Attachment defined from schema:
|
||||||
|
// {
|
||||||
|
// "title": "Attachment",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "author": {
|
||||||
|
// "title": "User",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "accountId": {
|
||||||
|
// "title": "accountId",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "active": {
|
||||||
|
// "title": "active",
|
||||||
|
// "type": "boolean"
|
||||||
|
// },
|
||||||
|
// "applicationRoles": {
|
||||||
|
// "title": "Simple List Wrapper",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "items": {
|
||||||
|
// "type": "array",
|
||||||
|
// "items": {
|
||||||
|
// "title": "Group",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "name": {
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "self": {
|
||||||
|
// "type": "string"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "max-results": {
|
||||||
|
// "type": "integer"
|
||||||
|
// },
|
||||||
|
// "size": {
|
||||||
|
// "type": "integer"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "avatarUrls": {
|
||||||
|
// "title": "avatarUrls",
|
||||||
|
// "type": "object",
|
||||||
|
// "patternProperties": {
|
||||||
|
// ".+": {
|
||||||
|
// "type": "string"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "displayName": {
|
||||||
|
// "title": "displayName",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "emailAddress": {
|
||||||
|
// "title": "emailAddress",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "expand": {
|
||||||
|
// "title": "expand",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "groups": {
|
||||||
|
// "title": "Simple List Wrapper",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "items": {
|
||||||
|
// "type": "array",
|
||||||
|
// "items": {
|
||||||
|
// "title": "Group",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "name": {
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "self": {
|
||||||
|
// "type": "string"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "max-results": {
|
||||||
|
// "type": "integer"
|
||||||
|
// },
|
||||||
|
// "size": {
|
||||||
|
// "type": "integer"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "key": {
|
||||||
|
// "title": "key",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "locale": {
|
||||||
|
// "title": "locale",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "name": {
|
||||||
|
// "title": "name",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "self": {
|
||||||
|
// "title": "self",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "timeZone": {
|
||||||
|
// "title": "timeZone",
|
||||||
|
// "type": "string"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "content": {
|
||||||
|
// "title": "content",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "created": {
|
||||||
|
// "title": "created",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "filename": {
|
||||||
|
// "title": "filename",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "id": {
|
||||||
|
// "title": "id",
|
||||||
|
// "type": "integer"
|
||||||
|
// },
|
||||||
|
// "mimeType": {
|
||||||
|
// "title": "mimeType",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "properties": {
|
||||||
|
// "title": "properties",
|
||||||
|
// "type": "object",
|
||||||
|
// "patternProperties": {
|
||||||
|
// ".+": {}
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "self": {
|
||||||
|
// "title": "self",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "size": {
|
||||||
|
// "title": "size",
|
||||||
|
// "type": "integer"
|
||||||
|
// },
|
||||||
|
// "thumbnail": {
|
||||||
|
// "title": "thumbnail",
|
||||||
|
// "type": "string"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
type Attachment struct {
|
||||||
|
Author *User `json:"author,omitempty" yaml:"author,omitempty"`
|
||||||
|
Content string `json:"content,omitempty" yaml:"content,omitempty"`
|
||||||
|
Created string `json:"created,omitempty" yaml:"created,omitempty"`
|
||||||
|
Filename string `json:"filename,omitempty" yaml:"filename,omitempty"`
|
||||||
|
ID IntOrString `json:"id,omitempty" yaml:"id,omitempty"`
|
||||||
|
MimeType string `json:"mimeType,omitempty" yaml:"mimeType,omitempty"`
|
||||||
|
Properties map[string]interface{} `json:"properties,omitempty" yaml:"properties,omitempty"`
|
||||||
|
Self string `json:"self,omitempty" yaml:"self,omitempty"`
|
||||||
|
Size int `json:"size,omitempty" yaml:"size,omitempty"`
|
||||||
|
Thumbnail string `json:"thumbnail,omitempty" yaml:"thumbnail,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package jiradata
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
// This Code is Generated by SlipScheme Project:
|
||||||
|
// https://github.com/coryb/slipscheme
|
||||||
|
//
|
||||||
|
// Generated with command:
|
||||||
|
// slipscheme -dir jiradata -pkg jiradata -overwrite schemas/ListofAttachment.json
|
||||||
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
// DO NOT EDIT //
|
||||||
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Group defined from schema:
|
||||||
|
// {
|
||||||
|
// "title": "Group",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "name": {
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "self": {
|
||||||
|
// "type": "string"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
type Group struct {
|
||||||
|
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||||
|
Self string `json:"self,omitempty" yaml:"self,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package jiradata
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
// This Code is Generated by SlipScheme Project:
|
||||||
|
// https://github.com/coryb/slipscheme
|
||||||
|
//
|
||||||
|
// Generated with command:
|
||||||
|
// slipscheme -dir jiradata -pkg jiradata -overwrite schemas/ListofAttachment.json
|
||||||
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
// DO NOT EDIT //
|
||||||
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Groups defined from schema:
|
||||||
|
// {
|
||||||
|
// "type": "array",
|
||||||
|
// "items": {
|
||||||
|
// "title": "Group",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "name": {
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "self": {
|
||||||
|
// "type": "string"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
type Groups []*Group
|
||||||
@@ -0,0 +1,202 @@
|
|||||||
|
package jiradata
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
// This Code is Generated by SlipScheme Project:
|
||||||
|
// https://github.com/coryb/slipscheme
|
||||||
|
//
|
||||||
|
// Generated with command:
|
||||||
|
// slipscheme -dir jiradata -pkg jiradata -overwrite schemas/ListofAttachment.json
|
||||||
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
// DO NOT EDIT //
|
||||||
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// ListOfAttachment defined from schema:
|
||||||
|
// {
|
||||||
|
// "title": "List of Attachment",
|
||||||
|
// "id": "https://docs.atlassian.com/jira/REST/schema/list-of-attachment#",
|
||||||
|
// "type": "array",
|
||||||
|
// "definitions": {
|
||||||
|
// "simple-list-wrapper": {
|
||||||
|
// "title": "Simple List Wrapper",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "items": {
|
||||||
|
// "type": "array",
|
||||||
|
// "items": {
|
||||||
|
// "title": "Group",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "name": {
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "self": {
|
||||||
|
// "type": "string"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "max-results": {
|
||||||
|
// "type": "integer"
|
||||||
|
// },
|
||||||
|
// "size": {
|
||||||
|
// "type": "integer"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "items": {
|
||||||
|
// "title": "Attachment",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "author": {
|
||||||
|
// "title": "User",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "accountId": {
|
||||||
|
// "title": "accountId",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "active": {
|
||||||
|
// "title": "active",
|
||||||
|
// "type": "boolean"
|
||||||
|
// },
|
||||||
|
// "applicationRoles": {
|
||||||
|
// "title": "Simple List Wrapper",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "items": {
|
||||||
|
// "type": "array",
|
||||||
|
// "items": {
|
||||||
|
// "title": "Group",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "name": {
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "self": {
|
||||||
|
// "type": "string"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "max-results": {
|
||||||
|
// "type": "integer"
|
||||||
|
// },
|
||||||
|
// "size": {
|
||||||
|
// "type": "integer"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "avatarUrls": {
|
||||||
|
// "title": "avatarUrls",
|
||||||
|
// "type": "object",
|
||||||
|
// "patternProperties": {
|
||||||
|
// ".+": {
|
||||||
|
// "type": "string"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "displayName": {
|
||||||
|
// "title": "displayName",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "emailAddress": {
|
||||||
|
// "title": "emailAddress",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "expand": {
|
||||||
|
// "title": "expand",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "groups": {
|
||||||
|
// "title": "Simple List Wrapper",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "items": {
|
||||||
|
// "type": "array",
|
||||||
|
// "items": {
|
||||||
|
// "title": "Group",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "name": {
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "self": {
|
||||||
|
// "type": "string"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "max-results": {
|
||||||
|
// "type": "integer"
|
||||||
|
// },
|
||||||
|
// "size": {
|
||||||
|
// "type": "integer"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "key": {
|
||||||
|
// "title": "key",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "locale": {
|
||||||
|
// "title": "locale",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "name": {
|
||||||
|
// "title": "name",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "self": {
|
||||||
|
// "title": "self",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "timeZone": {
|
||||||
|
// "title": "timeZone",
|
||||||
|
// "type": "string"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "content": {
|
||||||
|
// "title": "content",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "created": {
|
||||||
|
// "title": "created",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "filename": {
|
||||||
|
// "title": "filename",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "id": {
|
||||||
|
// "title": "id",
|
||||||
|
// "type": "integer"
|
||||||
|
// },
|
||||||
|
// "mimeType": {
|
||||||
|
// "title": "mimeType",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "properties": {
|
||||||
|
// "title": "properties",
|
||||||
|
// "type": "object",
|
||||||
|
// "patternProperties": {
|
||||||
|
// ".+": {}
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "self": {
|
||||||
|
// "title": "self",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "size": {
|
||||||
|
// "title": "size",
|
||||||
|
// "type": "integer"
|
||||||
|
// },
|
||||||
|
// "thumbnail": {
|
||||||
|
// "title": "thumbnail",
|
||||||
|
// "type": "string"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
type ListOfAttachment []*Attachment
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package jiradata
|
||||||
|
|
||||||
|
func (l *ListOfAttachment) Len() int {
|
||||||
|
return len(*l)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListOfAttachment) Less(i, j int) bool {
|
||||||
|
return (*l)[i].ID < (*l)[j].ID
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListOfAttachment) Swap(i, j int) {
|
||||||
|
(*l)[i], (*l)[j] = (*l)[j], (*l)[i]
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package jiradata
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
// This Code is Generated by SlipScheme Project:
|
||||||
|
// https://github.com/coryb/slipscheme
|
||||||
|
//
|
||||||
|
// Generated with command:
|
||||||
|
// slipscheme -dir jiradata -pkg jiradata -overwrite schemas/ListofAttachment.json
|
||||||
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
// DO NOT EDIT //
|
||||||
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// SimpleListWrapper defined from schema:
|
||||||
|
// {
|
||||||
|
// "title": "Simple List Wrapper",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "items": {
|
||||||
|
// "type": "array",
|
||||||
|
// "items": {
|
||||||
|
// "title": "Group",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "name": {
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "self": {
|
||||||
|
// "type": "string"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "max-results": {
|
||||||
|
// "type": "integer"
|
||||||
|
// },
|
||||||
|
// "size": {
|
||||||
|
// "type": "integer"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
type SimpleListWrapper struct {
|
||||||
|
Items Groups `json:"items,omitempty" yaml:"items,omitempty"`
|
||||||
|
MaxResults int `json:"max-results,omitempty" yaml:"max-results,omitempty"`
|
||||||
|
Size int `json:"size,omitempty" yaml:"size,omitempty"`
|
||||||
|
}
|
||||||
+85
-10
@@ -5,7 +5,7 @@ package jiradata
|
|||||||
// https://github.com/coryb/slipscheme
|
// https://github.com/coryb/slipscheme
|
||||||
//
|
//
|
||||||
// Generated with command:
|
// Generated with command:
|
||||||
// slipscheme -dir jiradata -pkg jiradata -overwrite schemas/WorklogWithPagination.json
|
// slipscheme -dir jiradata -pkg jiradata -overwrite schemas/ListofAttachment.json
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// DO NOT EDIT //
|
// DO NOT EDIT //
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
@@ -16,12 +16,42 @@ package jiradata
|
|||||||
// "type": "object",
|
// "type": "object",
|
||||||
// "properties": {
|
// "properties": {
|
||||||
// "accountId": {
|
// "accountId": {
|
||||||
|
// "title": "accountId",
|
||||||
// "type": "string"
|
// "type": "string"
|
||||||
// },
|
// },
|
||||||
// "active": {
|
// "active": {
|
||||||
|
// "title": "active",
|
||||||
// "type": "boolean"
|
// "type": "boolean"
|
||||||
// },
|
// },
|
||||||
|
// "applicationRoles": {
|
||||||
|
// "title": "Simple List Wrapper",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "items": {
|
||||||
|
// "type": "array",
|
||||||
|
// "items": {
|
||||||
|
// "title": "Group",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "name": {
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "self": {
|
||||||
|
// "type": "string"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "max-results": {
|
||||||
|
// "type": "integer"
|
||||||
|
// },
|
||||||
|
// "size": {
|
||||||
|
// "type": "integer"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
// "avatarUrls": {
|
// "avatarUrls": {
|
||||||
|
// "title": "avatarUrls",
|
||||||
// "type": "object",
|
// "type": "object",
|
||||||
// "patternProperties": {
|
// "patternProperties": {
|
||||||
// ".+": {
|
// ".+": {
|
||||||
@@ -30,33 +60,78 @@ package jiradata
|
|||||||
// }
|
// }
|
||||||
// },
|
// },
|
||||||
// "displayName": {
|
// "displayName": {
|
||||||
|
// "title": "displayName",
|
||||||
// "type": "string"
|
// "type": "string"
|
||||||
// },
|
// },
|
||||||
// "emailAddress": {
|
// "emailAddress": {
|
||||||
|
// "title": "emailAddress",
|
||||||
// "type": "string"
|
// "type": "string"
|
||||||
// },
|
// },
|
||||||
|
// "expand": {
|
||||||
|
// "title": "expand",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "groups": {
|
||||||
|
// "title": "Simple List Wrapper",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "items": {
|
||||||
|
// "type": "array",
|
||||||
|
// "items": {
|
||||||
|
// "title": "Group",
|
||||||
|
// "type": "object",
|
||||||
|
// "properties": {
|
||||||
|
// "name": {
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "self": {
|
||||||
|
// "type": "string"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "max-results": {
|
||||||
|
// "type": "integer"
|
||||||
|
// },
|
||||||
|
// "size": {
|
||||||
|
// "type": "integer"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
// "key": {
|
// "key": {
|
||||||
|
// "title": "key",
|
||||||
|
// "type": "string"
|
||||||
|
// },
|
||||||
|
// "locale": {
|
||||||
|
// "title": "locale",
|
||||||
// "type": "string"
|
// "type": "string"
|
||||||
// },
|
// },
|
||||||
// "name": {
|
// "name": {
|
||||||
|
// "title": "name",
|
||||||
// "type": "string"
|
// "type": "string"
|
||||||
// },
|
// },
|
||||||
// "self": {
|
// "self": {
|
||||||
|
// "title": "self",
|
||||||
// "type": "string"
|
// "type": "string"
|
||||||
// },
|
// },
|
||||||
// "timeZone": {
|
// "timeZone": {
|
||||||
|
// "title": "timeZone",
|
||||||
// "type": "string"
|
// "type": "string"
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
type User struct {
|
type User struct {
|
||||||
AccountID string `json:"accountId,omitempty" yaml:"accountId,omitempty"`
|
AccountID string `json:"accountId,omitempty" yaml:"accountId,omitempty"`
|
||||||
Active bool `json:"active,omitempty" yaml:"active,omitempty"`
|
Active bool `json:"active,omitempty" yaml:"active,omitempty"`
|
||||||
AvatarUrls map[string]string `json:"avatarUrls,omitempty" yaml:"avatarUrls,omitempty"`
|
ApplicationRoles *SimpleListWrapper `json:"applicationRoles,omitempty" yaml:"applicationRoles,omitempty"`
|
||||||
DisplayName string `json:"displayName,omitempty" yaml:"displayName,omitempty"`
|
AvatarUrls map[string]string `json:"avatarUrls,omitempty" yaml:"avatarUrls,omitempty"`
|
||||||
EmailAddress string `json:"emailAddress,omitempty" yaml:"emailAddress,omitempty"`
|
DisplayName string `json:"displayName,omitempty" yaml:"displayName,omitempty"`
|
||||||
Key string `json:"key,omitempty" yaml:"key,omitempty"`
|
EmailAddress string `json:"emailAddress,omitempty" yaml:"emailAddress,omitempty"`
|
||||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
Expand string `json:"expand,omitempty" yaml:"expand,omitempty"`
|
||||||
Self string `json:"self,omitempty" yaml:"self,omitempty"`
|
Groups *SimpleListWrapper `json:"groups,omitempty" yaml:"groups,omitempty"`
|
||||||
TimeZone string `json:"timeZone,omitempty" yaml:"timeZone,omitempty"`
|
Key string `json:"key,omitempty" yaml:"key,omitempty"`
|
||||||
|
Locale string `json:"locale,omitempty" yaml:"locale,omitempty"`
|
||||||
|
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||||
|
Self string `json:"self,omitempty" yaml:"self,omitempty"`
|
||||||
|
TimeZone string `json:"timeZone,omitempty" yaml:"timeZone,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package jiradata
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// this is for some bad schemas like Attachments.ID where in some api's it is an `int` and some it is a `string`
|
||||||
|
type IntOrString int
|
||||||
|
|
||||||
|
func (i *IntOrString) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
|
var tmp string
|
||||||
|
if err := unmarshal(&tmp); err != nil {
|
||||||
|
return unmarshal((*int)(i))
|
||||||
|
}
|
||||||
|
tmpInt, err := strconv.Atoi(tmp)
|
||||||
|
*i = IntOrString(tmpInt)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IntOrString) UnmarshalJSON(b []byte) error {
|
||||||
|
var tmp string
|
||||||
|
if err := json.Unmarshal(b, &tmp); err != nil {
|
||||||
|
return json.Unmarshal(b, (*int)(i))
|
||||||
|
}
|
||||||
|
tmpInt, err := strconv.Atoi(tmp)
|
||||||
|
*i = IntOrString(tmpInt)
|
||||||
|
return err
|
||||||
|
}
|
||||||
Executable
+189
@@ -0,0 +1,189 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
eval "$(curl -q -s https://raw.githubusercontent.com/coryb/osht/master/osht.sh)"
|
||||||
|
cd $(dirname $0)
|
||||||
|
jira="../jira"
|
||||||
|
. env.sh
|
||||||
|
|
||||||
|
PLAN 43
|
||||||
|
|
||||||
|
# reset login
|
||||||
|
RUNS $jira logout
|
||||||
|
RUNS $jira login
|
||||||
|
|
||||||
|
# cleanup from previous failed test executions
|
||||||
|
($jira ls --project BASIC | awk -F: '{print $1}' | while read issue; do ../jira done $issue; done) | sed 's/^/# CLEANUP: /g'
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
## Create an issue
|
||||||
|
###############################################################################
|
||||||
|
RUNS $jira create --project BASIC -o summary="Attach To Me" -o description=description --noedit --saveFile issue.props
|
||||||
|
issue=$(awk '/issue/{print $2}' issue.props)
|
||||||
|
|
||||||
|
DIFF <<EOF
|
||||||
|
OK $issue $ENDPOINT/browse/$issue
|
||||||
|
EOF
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
## Attach via stdin
|
||||||
|
###############################################################################
|
||||||
|
RUNS $jira attach create $issue --filename README.md --saveFile attach.props < ./README.md
|
||||||
|
attach1=$(awk '/^id:/{print $2}' attach.props)
|
||||||
|
|
||||||
|
DIFF <<EOF
|
||||||
|
OK $attach1 $ENDPOINT/secure/attachment/$attach1/README.md
|
||||||
|
EOF
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
## Attach binary file
|
||||||
|
###############################################################################
|
||||||
|
RUNS dd of=garbage.bin if=/dev/urandom count=1k bs=1k
|
||||||
|
RUNS $jira attach create $issue garbage.bin --saveFile attach.props
|
||||||
|
attach2=$(awk '/^id:/{print $2}' attach.props)
|
||||||
|
|
||||||
|
DIFF <<EOF
|
||||||
|
OK $attach2 $ENDPOINT/secure/attachment/$attach2/garbage.bin
|
||||||
|
EOF
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
## Attach binary file with different name
|
||||||
|
###############################################################################
|
||||||
|
RUNS $jira attach create $issue garbage.bin --filename foobar.bin --saveFile attach.props
|
||||||
|
attach3=$(awk '/^id:/{print $2}' attach.props)
|
||||||
|
|
||||||
|
DIFF <<EOF
|
||||||
|
OK $attach3 $ENDPOINT/secure/attachment/$attach3/foobar.bin
|
||||||
|
EOF
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
## List attachments
|
||||||
|
###############################################################################
|
||||||
|
RUNS $jira attach list $issue
|
||||||
|
DIFF <<EOF
|
||||||
|
+------------+------------------------------+------------+--------------+--------------+
|
||||||
|
| id | filename | bytes | user | created |
|
||||||
|
+------------+------------------------------+------------+--------------+--------------+
|
||||||
|
| $(printf %10s $attach1) | README.md | 1238 | gojira | a minute |
|
||||||
|
| $(printf %10s $attach2) | garbage.bin | 1048576 | gojira | a minute |
|
||||||
|
| $(printf %10s $attach3) | foobar.bin | 1048576 | gojira | a minute |
|
||||||
|
+------------+------------------------------+------------+--------------+--------------+
|
||||||
|
EOF
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
## Fetch text attachment
|
||||||
|
###############################################################################
|
||||||
|
RUNS $jira attach get $attach1 -o attach1.txt
|
||||||
|
DIFF <<EOF
|
||||||
|
OK Wrote attach1.txt
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# verify no diffs
|
||||||
|
RUNS diff -q README.md attach1.txt
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
## Fetch text attachment to stdout
|
||||||
|
###############################################################################
|
||||||
|
RUNS sh -c "$jira attach get $attach1 -o- > attach1.txt"
|
||||||
|
|
||||||
|
# verify no diffs
|
||||||
|
RUNS diff -q README.md attach1.txt
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
## Fetch text attachment as same name
|
||||||
|
###############################################################################
|
||||||
|
RUNS $jira attach get $attach1
|
||||||
|
DIFF <<EOF
|
||||||
|
OK Wrote README.md
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# verify no diffs
|
||||||
|
RUNS git diff README.md
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
## Fetch binary attachment
|
||||||
|
###############################################################################
|
||||||
|
RUNS $jira attach get $attach2 --output binary.out
|
||||||
|
DIFF <<EOF
|
||||||
|
OK Wrote binary.out
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# verify no diffs
|
||||||
|
RUNS diff -q garbage.bin binary.out
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
## Fetch binary attachment to stdout
|
||||||
|
###############################################################################
|
||||||
|
RUNS sh -c "$jira attach get $attach2 -o- > binary.out"
|
||||||
|
|
||||||
|
# verify no diffs
|
||||||
|
RUNS diff -q garbage.bin binary.out
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
## Fetch binary attachment
|
||||||
|
###############################################################################
|
||||||
|
RUNS $jira attach get $attach3
|
||||||
|
DIFF <<EOF
|
||||||
|
OK Wrote foobar.bin
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# verify no diffs
|
||||||
|
RUNS diff -q garbage.bin foobar.bin
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
## Fetch binary attachment to stdout
|
||||||
|
###############################################################################
|
||||||
|
RUNS sh -c "$jira attach get $attach3 --output=- > binary.out"
|
||||||
|
|
||||||
|
# verify no diffs
|
||||||
|
RUNS diff -q garbage.bin binary.out
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
## Delete attachment
|
||||||
|
###############################################################################
|
||||||
|
RUNS $jira attach remove $attach1
|
||||||
|
DIFF <<EOF
|
||||||
|
OK Deleted Attachment $attach1
|
||||||
|
EOF
|
||||||
|
|
||||||
|
RUNS $jira attach list $issue
|
||||||
|
DIFF <<EOF
|
||||||
|
+------------+------------------------------+------------+--------------+--------------+
|
||||||
|
| id | filename | bytes | user | created |
|
||||||
|
+------------+------------------------------+------------+--------------+--------------+
|
||||||
|
| $(printf %10s $attach2) | garbage.bin | 1048576 | gojira | a minute |
|
||||||
|
| $(printf %10s $attach3) | foobar.bin | 1048576 | gojira | a minute |
|
||||||
|
+------------+------------------------------+------------+--------------+--------------+
|
||||||
|
EOF
|
||||||
|
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
## Delete attachment
|
||||||
|
###############################################################################
|
||||||
|
RUNS $jira attach rm $attach2
|
||||||
|
DIFF <<EOF
|
||||||
|
OK Deleted Attachment $attach2
|
||||||
|
EOF
|
||||||
|
|
||||||
|
RUNS $jira attach list $issue
|
||||||
|
DIFF <<EOF
|
||||||
|
+------------+------------------------------+------------+--------------+--------------+
|
||||||
|
| id | filename | bytes | user | created |
|
||||||
|
+------------+------------------------------+------------+--------------+--------------+
|
||||||
|
| $(printf %10s $attach3) | foobar.bin | 1048576 | gojira | a minute |
|
||||||
|
+------------+------------------------------+------------+--------------+--------------+
|
||||||
|
EOF
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
## Delete last
|
||||||
|
###############################################################################
|
||||||
|
RUNS $jira attach rm $attach3
|
||||||
|
DIFF <<EOF
|
||||||
|
OK Deleted Attachment $attach3
|
||||||
|
EOF
|
||||||
|
|
||||||
|
RUNS $jira attach list $issue
|
||||||
|
DIFF <<EOF
|
||||||
|
+------------+------------------------------+------------+--------------+--------------+
|
||||||
|
| id | filename | bytes | user | created |
|
||||||
|
+------------+------------------------------+------------+--------------+--------------+
|
||||||
|
+------------+------------------------------+------------+--------------+--------------+
|
||||||
|
EOF
|
||||||
Reference in New Issue
Block a user