diff --git a/examples/test-working/main.go b/examples/test-working/main.go new file mode 100644 index 0000000..8305f5b --- /dev/null +++ b/examples/test-working/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "strings" + + jira "github.com/interviewstreet/go-jira" +) + +func main() { + + jiraURL := "" + username := "" + token := "" + + tp := jira.BasicAuthTransport{ + Username: username, + Password: token, + } + + client, err := jira.NewClient(tp.Client(), strings.TrimSpace(jiraURL)) + if err != nil { + fmt.Printf("\nerror: %v\n", err) + return + } + + ctx := context.TODO() + + webhooks, _, err := client.Organization.GetWebhookList(ctx) + + pretty, _ := json.MarshalIndent(webhooks, "", " ") + fmt.Println(string(pretty)) + + if err != nil { + fmt.Printf("\nerror: %v\n", err) + return + } +} diff --git a/organization.go b/organization.go index 090594c..43e76bd 100644 --- a/organization.go +++ b/organization.go @@ -55,6 +55,16 @@ type PropertyKeys struct { Keys []PropertyKey `json:"keys,omitempty" structs:"keys,omitempty"` } +type Webhook struct { + Name string `json:"name,omitempty" structs:"name,omitempty"` + WebhookUrl string `json:"url,omitempty" structs:"url,omitempty"` + SelfUrl string `json:"self,omitempty" structs:"self,omitempty"` + Events []string `json:"events,omitempty" structs:"events,omitempty"` + Enabled bool `json:"enabled" structs:"enabled"` + LastUpdatedUserName string `json:"lastUpdatedDisplayName,omitempty" structs:"lastUpdatedDisplayName,omitempty"` + LastUpdatedUserId string `json:"lastUpdatedUser,omitempty" structs:"lastUpdatedUser,omitempty"` +} + // GetAllOrganizationsWithContext returns a list of organizations in // the Jira Service Management instance. // Use this method when you want to present a list @@ -385,3 +395,25 @@ func (s *OrganizationService) RemoveUsersWithContext(ctx context.Context, organi func (s *OrganizationService) RemoveUsers(organizationID int, users OrganizationUsersDTO) (*Response, error) { return s.RemoveUsersWithContext(context.Background(), organizationID, users) } + +func (s *OrganizationService) GetWebhookList(ctx context.Context) ([]*Webhook, *Response, error) { + apiEndPoint := "rest/webhooks/1.0/webhook" + + req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndPoint, nil) + + if err != nil { + return nil, nil, err + } + + req.Header.Set("Accept", "application/json") + + webhooks := []*Webhook{} + + resp, err := s.client.Do(req, &webhooks) + if err != nil { + jerr := NewJiraError(resp, err) + return nil, resp, jerr + } + + return webhooks, resp, nil +}