mirror of
https://gitea.com/jolheiser/sip
synced 2024-11-22 19:51:58 +01:00
Add create repo command (#13)
Add create repo command Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: jolheiser <john.olheiser@gmail.com> Reviewed-on: https://gitea.com/jolheiser/sip/pulls/13
This commit is contained in:
parent
4490cc9888
commit
03fb319d39
@ -13,6 +13,9 @@ var Repo = cli.Command{
|
|||||||
Name: "repo",
|
Name: "repo",
|
||||||
Usage: "Commands for interacting with a Gitea repository",
|
Usage: "Commands for interacting with a Gitea repository",
|
||||||
Action: doRepo,
|
Action: doRepo,
|
||||||
|
Subcommands: []*cli.Command{
|
||||||
|
&RepoCreate,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func doRepo(ctx *cli.Context) error {
|
func doRepo(ctx *cli.Context) error {
|
||||||
|
91
cmd/repo_create.go
Normal file
91
cmd/repo_create.go
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.gitea.io/sdk/gitea"
|
||||||
|
"github.com/AlecAivazis/survey/v2"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
"go.jolheiser.com/beaver"
|
||||||
|
"go.jolheiser.com/beaver/color"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var RepoCreate = cli.Command{
|
||||||
|
Name: "create",
|
||||||
|
Usage: "Create a new repository",
|
||||||
|
Action: doRepoCreate,
|
||||||
|
}
|
||||||
|
|
||||||
|
func doRepoCreate(ctx *cli.Context) error {
|
||||||
|
token, err := requireToken(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
client := gitea.NewClient(ctx.String("url"), token)
|
||||||
|
|
||||||
|
questions := []*survey.Question{
|
||||||
|
{
|
||||||
|
Name: "name",
|
||||||
|
Prompt: &survey.Input{Message: "Name"},
|
||||||
|
Validate: survey.Required,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "description",
|
||||||
|
Prompt: &survey.Input{Message: "Description"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "private",
|
||||||
|
Prompt: &survey.Confirm{Message: "Private", Default: true},
|
||||||
|
Validate: survey.Required,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "auto",
|
||||||
|
Prompt: &survey.Confirm{Message: "Auto-initialize", Default: false},
|
||||||
|
Validate: survey.Required,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
answers := struct {
|
||||||
|
Name string
|
||||||
|
Description string
|
||||||
|
Private bool
|
||||||
|
Auto bool
|
||||||
|
}{}
|
||||||
|
|
||||||
|
if err := survey.Ask(questions, &answers); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
opts := gitea.CreateRepoOption{
|
||||||
|
Name: answers.Name,
|
||||||
|
Description: answers.Description,
|
||||||
|
Private: answers.Private,
|
||||||
|
AutoInit: answers.Auto,
|
||||||
|
}
|
||||||
|
|
||||||
|
if answers.Auto {
|
||||||
|
auto := autoOpts(client)
|
||||||
|
opts.Gitignores = strings.Join(auto.Gitignores, ",")
|
||||||
|
opts.License = auto.License
|
||||||
|
opts.Readme = auto.Readme
|
||||||
|
}
|
||||||
|
|
||||||
|
repo, err := client.CreateRepo(opts)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
beaver.Infof("Created new repo at %s", color.FgMagenta.Format(repo.HTMLURL))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type autoInit struct {
|
||||||
|
Gitignores []string
|
||||||
|
License string
|
||||||
|
Readme string
|
||||||
|
}
|
||||||
|
|
||||||
|
func autoOpts(client *gitea.Client) autoInit {
|
||||||
|
// FIXME query gitignores, licenses, and readme when available in SDK
|
||||||
|
_ = client
|
||||||
|
return autoInit{Readme: "Default"}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user