nitter/internal/commands/gitea.go
2023-03-08 14:40:04 +01:00

49 lines
1.3 KiB
Go

package commands
import (
gosdk "code.gitea.io/sdk/gitea"
"github.com/spf13/cobra"
"code.icb4dc0.de/prskr/nitter/nitters/gitea"
)
func Gitea() *cobra.Command {
giteaCmd := &cobra.Command{
Use: "gitea",
Short: "Parent command to Gitea related actions",
}
giteaCmd.PersistentFlags().StringP("base-address", "a", "", "Base URL of your Gitea/Forgejo instance [$NITTER_BASE_ADDRESS]")
giteaCmd.PersistentFlags().StringP("token", "t", "", "Access token to interact with Gitea/Forgejo API [$NITTER_TOKEN]")
pr := &cobra.Command{
Use: "pull-request",
Aliases: []string{"merge-request", "pr", "mr", "pull"},
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := LoadConfig[gitea.GiteaPRConfig](cmd.Flags())
if err != nil {
return err
}
report, issues, err := ReadResultsFile(cmd.Flag("result-file").Value.String())
if err != nil {
return err
}
giteaClient, err := gosdk.NewClient(cfg.BaseAddress, gosdk.SetContext(cmd.Context()), gosdk.SetToken(cfg.Token))
if err != nil {
return err
}
nitter := gitea.NewPRNitter(giteaClient, cfg)
return nitter.Report(report, issues)
},
}
pr.Flags().Int64P("pull-index", "i", -1, "PR index to add reviews to - note, this is not the ID of the PR but its number [$NITTER_PULL_INDEX]")
giteaCmd.AddCommand(pr)
return giteaCmd
}