M doc/hut.1.scd => doc/hut.1.scd +3 -0
@@ 352,6 352,9 @@ Options are:
*-u*, *--url* <URL>
The payload URL which receives the _POST_ request. Required.
+
+*webhook delete* <ID>
+ Delete a git webhook.
*webhook list* [repo]
List git webhooks.
M git.go => git.go +29 -0
@@ 1000,6 1000,7 @@ func newGitWebhookCommand() *cobra.Command {
}
cmd.AddCommand(newGitWebhookCreateCommand())
cmd.AddCommand(newGitWebhookListCommand())
+ cmd.AddCommand(newGitWebhookDeleteCommand())
return cmd
}
@@ 1117,6 1118,34 @@ func newGitWebhookListCommand() *cobra.Command {
return cmd
}
+func newGitWebhookDeleteCommand() *cobra.Command {
+ run := func(cmd *cobra.Command, args []string) {
+ ctx := cmd.Context()
+ c := createClient("git", cmd)
+
+ id, err := parseInt32(args[0])
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ webhook, err := gitsrht.DeleteGitWebhook(c.Client, ctx, id)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ log.Printf("Deleted webhook %d\n", webhook.Id)
+ }
+
+ cmd := &cobra.Command{
+ Use: "delete <ID>",
+ Short: "Delete a git webhook",
+ Args: cobra.ExactArgs(1),
+ ValidArgsFunction: cobra.NoFileCompletions,
+ Run: run,
+ }
+ return cmd
+}
+
func getGitRepoName(ctx context.Context, cmd *cobra.Command) (repoName, owner, instance string, err error) {
repoName, err = cmd.Flags().GetString("repo")
if err != nil {
M srht/gitsrht/gql.go => srht/gitsrht/gql.go +10 -0
@@ 978,3 978,13 @@ func CreateGitWebhook(client *gqlclient.Client, ctx context.Context, config GitW
err = client.Execute(ctx, op, &respData)
return respData.CreateGitWebhook, err
}
+
+func DeleteGitWebhook(client *gqlclient.Client, ctx context.Context, id int32) (deleteGitWebhook *WebhookSubscription, err error) {
+ op := gqlclient.NewOperation("mutation deleteGitWebhook ($id: Int!) {\n\tdeleteGitWebhook(id: $id) {\n\t\tid\n\t}\n}\n")
+ op.Var("id", id)
+ var respData struct {
+ DeleteGitWebhook *WebhookSubscription
+ }
+ err = client.Execute(ctx, op, &respData)
+ return respData.DeleteGitWebhook, err
+}
M srht/gitsrht/operations.graphql => srht/gitsrht/operations.graphql +6 -0
@@ 332,3 332,9 @@ mutation createGitWebhook($config: GitWebhookInput!) {
id
}
}
+
+mutation deleteGitWebhook($id: Int!) {
+ deleteGitWebhook(id: $id) {
+ id
+ }
+}