andygrunwald / go-jira

Go client library for Atlassian Jira
https://pkg.go.dev/github.com/andygrunwald/go-jira?tab=doc
MIT License
1.47k stars 469 forks source link

Watchers cannot be added/updated (perhaps due to typo, i.e. watches instead of watchers) #340

Open 030 opened 3 years ago

030 commented 3 years ago

Example

https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-watchers/#api-rest-api-2-issue-issueidorkey-watchers-post

curl --request POST \
  --url 'https://your-domain.atlassian.com/rest/api/2/issue/{issueIdOrKey}/watchers' \
  --user 'email@example.com:<api_token>' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '"<string>"'

related

https://github.com/andygrunwald/go-jira/issues/191#issuecomment-771658944

cfloody commented 3 years ago

Here's a quick workaround that worked for me:

First, figure out the custom field ID for the Watchers field

var customFieldID string
fieldList, _, _ := client.Field.GetList()

for _, v := range fieldList {
        if v.Name == "Watchers" {
                customFieldID = v.ID
                break
        }
}

Then set the values for that custom field in the Unknowns map

i := jira.Issue{
        Fields: &jira.IssueFields{
                Unknowns: map[string]interface{}{
                        customFieldID: []*jira.Watcher{
                                {
                                        Name: "cfloody",
                                },
                        },
                },
                Description: description,
                Type: jira.IssueType{
                        Name: "Task",
                },
                Project: jira.Project{
                        Key: "Foo",
                },

                Summary: summary,
                Priority: &jira.Priority{
                        Name: "Low",
                },
        },
}
andygrunwald commented 3 years ago

Hey @030, did this solve the initial request? If yes, please let us know and it can be added to the example directory.

andygrunwald commented 2 years ago

Hey,

I am very sorry that this issue has been open for a long time with no final solution. We work on this project in our spare time, and sometimes, other priorities take over. This is the typical open source dilemma.

However, there is news: We are kicking off v2 of this library 🚀

To provide visibility, we created the Road to v2 Milestone and calling for your feedback in https://github.com/andygrunwald/go-jira/issues/489

The development will take some time; however, I hope you can benefit from the changes. If you seek priority development for your issue + you like to sponsor it, please contact me.

What does this mean for my issue?

We will work on this issue indirectly. This means that during the development phase, we aim to tackle it. Maybe in a different way like it is currently handled. Please understand that this will take a while because we are running this in our spare time.

Final words

Thanks for using this library. If there is anything else you would like to tell us, let us know!