1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2024-11-24 08:22:42 +02:00

Add: Organization Webhook API [HX-822] (#11)

 Add: Organization Webhook API
This commit is contained in:
Karan Jagtiani 2021-12-16 14:29:46 +05:30 committed by GitHub
parent 66f3331bee
commit 5e62a2d0c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 0 deletions

View File

@ -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
}
}

View File

@ -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
}