prometheus-community / jiralert

JIRA integration for Prometheus Alertmanager
Apache License 2.0
335 stars 129 forks source link

Add Watchers or Request Participants #103

Open billabongrob opened 3 years ago

billabongrob commented 3 years ago

In order to gauge the effectiveness and the outcomes of the JIRA tickets that JIRAlert is generating, we would like to be able to add either Watchers or Request Participants to the ticket during creation. I do not believe these are exposed in the "issue" API though I could be wrong.

mattatnersc commented 1 year ago

looks like it's here: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-watchers/#api-rest-api-3-issue-issueidorkey-watchers-post

mattatnersc commented 1 year ago

looks like it's possible to add a watcher to a issue in the golang library, but it doesn't work for me: https://github.com/andygrunwald/go-jira/blob/v1.16.0/issue.go#L1458

In fact, the REST API doc at https://docs.atlassian.com/software/jira/docs/api/REST/9.6.0/#api/2/issue-addWatcher gives "fred" as an example whereas the other examples are all in JSON format, so perhaps this is an Atlassian bug.

// AddWatcherWithContext adds watcher to the given issue
//
// Jira API docs: https://docs.atlassian.com/software/jira/docs/api/REST/latest/#api/2/issue-addWatcher
// Caller must close resp.Body
func (s *IssueService) AddWatcherWithContext(ctx context.Context, issueID string, userName string) (*Response, error) {
    apiEndPoint := fmt.Sprintf("rest/api/2/issue/%s/watchers", issueID)

    req, err := s.client.NewRequestWithContext(ctx, "POST", apiEndPoint, userName)
    if err != nil {
        return nil, err
    }

    resp, err := s.client.Do(req, nil)
    if err != nil {
        err = NewJiraError(resp, err)
    }

    return resp, err
}

// AddWatcher wraps AddWatcherWithContext using the background context.
// Caller must close resp.Body
func (s *IssueService) AddWatcher(issueID string, userName string) (*Response, error) {
    return s.AddWatcherWithContext(context.Background(), issueID, userName)
}