mirror of
https://github.com/interviewstreet/go-jira.git
synced 2024-11-28 08:39:03 +02:00
✨ Add: Organization Webhook API [HX-822] (#11)
✨ Add: Organization Webhook API
This commit is contained in:
parent
66f3331bee
commit
5e62a2d0c0
40
examples/test-working/main.go
Normal file
40
examples/test-working/main.go
Normal 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
|
||||||
|
}
|
||||||
|
}
|
@ -55,6 +55,16 @@ type PropertyKeys struct {
|
|||||||
Keys []PropertyKey `json:"keys,omitempty" structs:"keys,omitempty"`
|
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
|
// GetAllOrganizationsWithContext returns a list of organizations in
|
||||||
// the Jira Service Management instance.
|
// the Jira Service Management instance.
|
||||||
// Use this method when you want to present a list
|
// 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) {
|
func (s *OrganizationService) RemoveUsers(organizationID int, users OrganizationUsersDTO) (*Response, error) {
|
||||||
return s.RemoveUsersWithContext(context.Background(), organizationID, users)
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user