---
doc/hut.1.scd | 3 ++
srht/todosrht/gql.go | 23 +++++++++++++++
srht/todosrht/operations.graphql | 31 +++++++++++++++++++++
todo.go | 48 ++++++++++++++++++++++++++++++++
4 files changed, 105 insertions(+)
diff --git a/doc/hut.1.scd b/doc/hut.1.scd
index 7fdb0f0..50167df 100644
--- a/doc/hut.1.scd
+++ b/doc/hut.1.scd
@@ -620,6 +620,9 @@ Options are:
*ticket webhook delete* <ID>
Delete a ticket webhook.
+*ticket webhook list* <ID>
+ List ticket webhooks.
+
*unsubscribe* [tracker]
Unsubscribe from a tracker.
diff --git a/srht/todosrht/gql.go b/srht/todosrht/gql.go
index 91aaa41..e423e35 100644
--- a/srht/todosrht/gql.go
+++ b/srht/todosrht/gql.go
@@ -838,6 +838,29 @@ func TrackerNames(client *gqlclient.Client, ctx context.Context) (trackers *Trac
return respData.Trackers, err
}
+func TicketWebhooks(client *gqlclient.Client, ctx context.Context, name string, id int32) (me *User, err error) {
+ op := gqlclient.NewOperation("query ticketWebhooks ($name: String!, $id: Int!) {\n\tme {\n\t\ttracker(name: $name) {\n\t\t\tticket(id: $id) {\n\t\t\t\t... ticketWebhooks\n\t\t\t}\n\t\t}\n\t}\n}\nfragment ticketWebhooks on Ticket {\n\twebhooks {\n\t\tresults {\n\t\t\tid\n\t\t\tevents\n\t\t\tquery\n\t\t\turl\n\t\t}\n\t}\n}\n")
+ op.Var("name", name)
+ op.Var("id", id)
+ var respData struct {
+ Me *User
+ }
+ err = client.Execute(ctx, op, &respData)
+ return respData.Me, err
+}
+
+func TicketWebhooksByUser(client *gqlclient.Client, ctx context.Context, username string, name string, id int32) (user *User, err error) {
+ op := gqlclient.NewOperation("query ticketWebhooksByUser ($username: String!, $name: String!, $id: Int!) {\n\tuser(username: $username) {\n\t\ttracker(name: $name) {\n\t\t\tticket(id: $id) {\n\t\t\t\t... ticketWebhooks\n\t\t\t}\n\t\t}\n\t}\n}\nfragment ticketWebhooks on Ticket {\n\twebhooks {\n\t\tresults {\n\t\t\tid\n\t\t\tevents\n\t\t\tquery\n\t\t\turl\n\t\t}\n\t}\n}\n")
+ op.Var("username", username)
+ op.Var("name", name)
+ op.Var("id", id)
+ var respData struct {
+ User *User
+ }
+ err = client.Execute(ctx, op, &respData)
+ return respData.User, err
+}
+
func UserWebhooks(client *gqlclient.Client, ctx context.Context) (userWebhooks *WebhookSubscriptionCursor, err error) {
op := gqlclient.NewOperation("query userWebhooks {\n\tuserWebhooks {\n\t\tresults {\n\t\t\tid\n\t\t\tevents\n\t\t\tquery\n\t\t\turl\n\t\t}\n\t}\n}\n")
var respData struct {
diff --git a/srht/todosrht/operations.graphql b/srht/todosrht/operations.graphql
index 9d87790..9376d3d 100644
--- a/srht/todosrht/operations.graphql
+++ b/srht/todosrht/operations.graphql
@@ -250,6 +250,37 @@ query trackerNames {
}
}
+query ticketWebhooks($name: String!, $id: Int!) {
+ me {
+ tracker(name: $name) {
+ ticket(id: $id) {
+ ...ticketWebhooks
+ }
+ }
+ }
+}
+
+query ticketWebhooksByUser($username: String!, $name: String!, $id: Int!) {
+ user(username: $username) {
+ tracker(name: $name) {
+ ticket(id: $id) {
+ ...ticketWebhooks
+ }
+ }
+ }
+}
+
+fragment ticketWebhooks on Ticket {
+ webhooks {
+ results {
+ id
+ events
+ query
+ url
+ }
+ }
+}
+
query userWebhooks {
userWebhooks {
results {
diff --git a/todo.go b/todo.go
index 940e565..c62cb70 100644
--- a/todo.go
+++ b/todo.go
@@ -672,6 +672,7 @@ func newTodoTicketWebhookCommand() *cobra.Command {
Short: "Manage ticket webhooks",
}
cmd.AddCommand(newTodoTicketWebhookCreateCommand())
+ cmd.AddCommand(newTodoTicketWebhookListCommand())
cmd.AddCommand(newTodoTicketWebhookDeleteCommand())
return cmd
}
@@ -728,6 +729,53 @@ func newTodoTicketWebhookCreateCommand() *cobra.Command {
return cmd
}
+func newTodoTicketWebhookListCommand() *cobra.Command {
+ run := func(cmd *cobra.Command, args []string) {
+ ctx := cmd.Context()
+
+ ticketID, name, owner, instance, err := parseTicketResource(ctx, cmd, args[0])
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ c := createClientWithInstance("todo", cmd, instance)
+ var (
+ user *todosrht.User
+ username string
+ )
+
+ if owner != "" {
+ username = strings.TrimLeft(owner, ownerPrefixes)
+ user, err = todosrht.TicketWebhooksByUser(c.Client, ctx, username, name, ticketID)
+ } else {
+ user, err = todosrht.TicketWebhooks(c.Client, ctx, name, ticketID)
+ }
+
+ if err != nil {
+ log.Fatal(err)
+ } else if user == nil {
+ log.Fatalf("no such user %q", username)
+ } else if user.Tracker == nil {
+ log.Fatalf("no such tracker %q", name)
+ }
+
+ for _, webhook := range user.Tracker.Ticket.Webhooks.Results {
+ fmt.Printf("%s %s %s\n", termfmt.DarkYellow.Sprintf("#%d", webhook.Id),
+ webhook.Url, webhook.Events)
+ fmt.Println(indent(webhook.Query, " "))
+ }
+ }
+
+ cmd := &cobra.Command{
+ Use: "list <ID>",
+ Short: "List ticket webhooks",
+ Args: cobra.ExactArgs(1),
+ ValidArgsFunction: completeTicketID,
+ Run: run,
+ }
+ return cmd
+}
+
func newTodoTicketWebhookDeleteCommand() *cobra.Command {
run := func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
base-commit: 9e66628304522c3a2251280f8bd1b53110968e5c
--
2.37.0