pr-deployer/cmd/deployer.go

57 lines
1.2 KiB
Go

package cmd
import (
"context"
"fmt"
"net/http"
"github.com/google/go-github/v39/github"
"github.com/spf13/cobra"
"gitea.com/gitea/pr-deployer/pkgs/settings"
)
var (
// Version means the version of reverse
Version = "0.1+dev"
versionFlag *bool
deployerCmd = &cobra.Command{
Version: Version,
Use: "pr-deployer",
Short: "PR-Deployer is a tool to help deploy PR",
Long: `PR-Deployer is a tool to help deploy PR`,
Run: func(cmd *cobra.Command, args []string) {
if versionFlag != nil && *versionFlag {
fmt.Printf("%s\n", Version)
return
}
c := github.NewClient(http.DefaultClient)
// check webhook registry
c.Repositories.CreateHook(context.Background(), "go-gitea", "gitea", &github.Hook{
Name: github.String("pr-deployer"),
Events: []string{"pull_request"},
Active: github.Bool(true),
Config: map[string]interface{}{
"content_type": "json",
"insecure_ssl": "1",
"url": fmt.Sprintf("https://%s/webhook", settings.Domain),
},
})
runWeb(cmd, args)
},
}
)
func init() {
versionFlag = deployerCmd.Flags().BoolP("version", "v", false, "version of the tool")
}
// Execute represnets execute command
func Execute() error {
return deployerCmd.Execute()
}