feat: add validation for object-format flag in repo create command

This commit is contained in:
Lunny Xiao
2025-04-03 22:23:45 -07:00
parent d633e3018d
commit f0b07c7614
2 changed files with 91 additions and 11 deletions

View File

@ -87,6 +87,10 @@ var CmdRepoCreate = cli.Command{
Name: "trustmodel",
Usage: "select trust model (committer,collaborator,collaborator+committer)",
},
&cli.StringFlag{
Name: "object-format",
Usage: "select git object format (sha1,sha256)",
},
}, flags.LoginOutputFlags...),
}
@ -112,18 +116,26 @@ func runRepoCreate(cmd *cli.Context) error {
}
}
if ctx.IsSet("object-format") {
format := ctx.String("object-format")
if format != "sha1" && format != "sha256" {
return fmt.Errorf("invalid object format '%s', must be either 'sha1' or 'sha256'", format)
}
}
opts := gitea.CreateRepoOption{
Name: ctx.String("name"),
Description: ctx.String("description"),
Private: ctx.Bool("private"),
AutoInit: ctx.Bool("init"),
IssueLabels: ctx.String("labels"),
Gitignores: ctx.String("gitignores"),
License: ctx.String("license"),
Readme: ctx.String("readme"),
DefaultBranch: ctx.String("branch"),
Template: ctx.Bool("template"),
TrustModel: trustmodel,
Name: ctx.String("name"),
Description: ctx.String("description"),
Private: ctx.Bool("private"),
AutoInit: ctx.Bool("init"),
IssueLabels: ctx.String("labels"),
Gitignores: ctx.String("gitignores"),
License: ctx.String("license"),
Readme: ctx.String("readme"),
DefaultBranch: ctx.String("branch"),
Template: ctx.Bool("template"),
TrustModel: trustmodel,
ObjectFormatName: ctx.String("object-format"),
}
if len(ctx.String("owner")) != 0 {
repo, _, err = client.CreateOrgRepo(ctx.String("owner"), opts)