Skip to content

Commit

Permalink
add trigger command
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Jan 27, 2024
1 parent d44c61d commit 972e8e1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func init() {
}

var pushCmd = &cobra.Command{
Use: "push",
Use: "push [document] [schema_file]",
Short: "Push a local document to TypeHub",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
Expand Down
55 changes: 55 additions & 0 deletions cmd/trigger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package cmd

import (
"fmt"
"github.com/apioo/typehub-cli/sdk"
"github.com/spf13/cobra"
"log"
)

func init() {
rootCmd.AddCommand(triggerCmd)
}

var triggerCmd = &cobra.Command{
Use: "trigger [document] [owner] [repo] [workflow_id] [access_token]",
Short: "Configures a GitHub trigger for a specific document",
Args: cobra.ExactArgs(5),
Run: func(cmd *cobra.Command, args []string) {
var client = sdkClient.GetClient()

var documentName = args[0]
var owner = args[1]
var repo = args[2]
var workflowId = args[3]
var accessToken = args[4]

user, err := client.Authorization().GetWhoami()
if err != nil {
log.Fatal(err)
}

// im
config := sdk.TriggerConfig{}
config["owner"] = owner
config["repo"] = repo
config["workflow_id"] = workflowId
config["access_token"] = accessToken

trigger := sdk.TriggerCreate{
Type: "github",
Config: config,
}

message, err := client.Trigger().Create(user.Name, documentName, trigger)
if err != nil {
log.Fatal(err)
}

if message.Success == true {
fmt.Println(message.Message)
} else {
log.Fatal(message.Message)
}
},
}

0 comments on commit 972e8e1

Please sign in to comment.