nitter/internal/commands/gitea.go

59 lines
1.4 KiB
Go
Raw Normal View History

2023-03-08 13:40:04 +00:00
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
}
2023-03-08 15:13:49 +00:00
if err := cfg.Validate(); err != nil {
return err
}
2023-03-08 13:40:04 +00:00
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)
},
}
2023-03-08 15:13:49 +00:00
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]",
)
2023-03-08 13:40:04 +00:00
giteaCmd.AddCommand(pr)
return giteaCmd
}