57 lines
2.2 KiB
Go
57 lines
2.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/Pingu-Studio/MaidnCLI/internal/e2emutate"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
e2eMutateForgejoURL, e2eMutateOwner, e2eMutateRepo, e2eMutateBranch, e2eMutateSHA string
|
|
e2eMutateTokenEnv, e2eMutateTokenFile string
|
|
e2eMutateOpenPR bool
|
|
e2eMutator = e2emutate.DefaultMutator
|
|
)
|
|
|
|
var e2eMutateCmd = &cobra.Command{
|
|
Use: "e2e-mutate",
|
|
Short: "Update a Forgejo E2E fixture branch and optionally open its PR.",
|
|
RunE: runE2EMutate,
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(e2eMutateCmd)
|
|
e2eMutateCmd.Flags().StringVar(&e2eMutateForgejoURL, "forgejo-url", "", "Credential-free Forgejo base URL")
|
|
e2eMutateCmd.Flags().StringVar(&e2eMutateOwner, "owner", "", "Fixture Forgejo owner (must be test-org-2)")
|
|
e2eMutateCmd.Flags().StringVar(&e2eMutateRepo, "repo", "", "Fixture Forgejo repository (must start maidn-e2e-)")
|
|
e2eMutateCmd.Flags().StringVar(&e2eMutateBranch, "branch", "", "Fixture Forgejo branch (must start maidn-e2e-)")
|
|
e2eMutateCmd.Flags().StringVar(&e2eMutateSHA, "sha", "", "Full Git object ID for the fixture branch")
|
|
e2eMutateCmd.Flags().StringVar(&e2eMutateTokenEnv, "token-env", "", "Environment variable containing the Forgejo token")
|
|
e2eMutateCmd.Flags().StringVar(&e2eMutateTokenFile, "token-file", "", "Path to a file containing the Forgejo token")
|
|
e2eMutateCmd.Flags().BoolVar(&e2eMutateOpenPR, "open-pr", false, "Open one pull request from the fixture branch to main")
|
|
for _, name := range []string{"forgejo-url", "owner", "repo", "branch", "sha"} {
|
|
_ = e2eMutateCmd.MarkFlagRequired(name)
|
|
}
|
|
}
|
|
|
|
func runE2EMutate(cmd *cobra.Command, _ []string) error {
|
|
token, err := e2emutate.ReadToken(e2eMutateTokenEnv, e2eMutateTokenFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
ctx := cmd.Context()
|
|
if ctx == nil {
|
|
ctx = context.Background()
|
|
}
|
|
return e2eMutator().Run(ctx, e2emutate.Options{
|
|
ForgejoURL: e2eMutateForgejoURL,
|
|
Owner: e2eMutateOwner,
|
|
Repo: e2eMutateRepo,
|
|
Branch: e2eMutateBranch,
|
|
SHA: e2eMutateSHA,
|
|
Token: token,
|
|
OpenPR: e2eMutateOpenPR,
|
|
})
|
|
}
|