andygrunwald / andygrunwald/go-jira

Creating Jira issues with attachments fails

Aperta
#386 6 commenti 0 reazioni 0 assegnatari Vedi su GitHub
needs triage
Lingua principale
Go
Stelle
1.6k
Fork
500
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

## Describe the bug

Attachments are not working and result in the following response from Jira:

```
{"errorMessages":[],"errors":{"attachment":"string expected at index 0"}}
```

## To Reproduce

Example code which fails:

```
func ReportIssue(client *jira.Client, project Project, summary string, description string) error {
jww.INFO.Printf("Reporting an issue for '%s' project on Jira...\n", project.Name)

// Acquire the id/keys through /rest/api/latest/field
// NOTE: For custom fields with specific data types (string/number), the value must be passed directly
// NOTE: Syntax for multicheckboxes (an array) => []map[string]string{{"value": "Something"}}
// NOTE: Syntax for customfieldtype:select => map[string]string{"value": "NA"}
customFields := tcontainer.NewMarshalMap()
// Revision reported
customFields["customfield_10700"] = "39018"
// Reproducibilty
customFields["customfield_10922"] = map[string]string{"value": "50% - Random"}
// Severity
customFields["customfield_10919"] = map[string]string{"value": "P1 - Critical"}

logFile, err := ioutil.ReadFile("D:\\hello.txt")
if err != nil {
jww.FATAL.Println(err)
}

mtype := mimetype.Detect(logFile)

i := jira.Issue{
Fields: &jira.IssueFields{
Type: jira.IssueType{
Name: "Bug",
},
Project: jira.Project{
Key: project.Name,
},
Priority: &jira.Priority{
Name: "Medium",
},
Components: []*jira.Component{
&jira.Component{
Name: "QA",
},
},
Description: description,
Summary: summary,
FixVersions: []*jira.FixVersion{
&jira.FixVersion{
Name: "Gameplay Prototype",
},
},
Attachments: []*jira.Attachment{
&jira.Attachment{
Filename: "helloworld.txt",
Size: len(logFile),
MimeType: mtype.String(),
Content: string(logFile[:]),
},
},
Unknowns: customFields,
},
}

issue, resp, err := client.Issue.Create(&i)
if err != nil {
jww.FATAL.Println(err)
body, err := ioutil.ReadAll(resp.Body)
if err == nil {
jww.FATAL.Println(string(body))
} else {
jww.FATAL.Println("Failed to decode the Jira's response!")
}
return errors.New("Failed to create the Jira issue!")
}

jww.INFO.Printf("The Jira issue '%s': %+v has been created!\n", issue.Key, issue.Self)

return nil
}
```

## Expected behavior

The attachments should work when creating an issue.

## Your Environment

Include as many relevant details about the environment you experienced the problem in

* go-jira version (v1.8.0):
* Go version (1.16):
* Jira version: Hosted from atlassian.net
* Jira type (cloud or on-premise): cloud
* Involved Jira plugins:
* Operating System and version: Windows 10

## Additional context

Our Jira instance requires the following (some are custom fields and attachments) when we create an issue:

```
{"errorMessages":["Please fill in the Component, priority, reproducibility, severity, type, description, Fix version, and revision reported. Also add your log/video or images as an attachment"],"errors":{}}
```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.