From b9b653dec35798eaedcd15a61d671618f7d68cd8 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 22 Oct 2018 02:52:57 +0800 Subject: [PATCH] Add release create (#1) * add release create * typo --- README.md | 1 + cmd/releases.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/README.md b/README.md index ad228bc..65586ec 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ git clone git@try.gitea.io:gitea/gitea.git cd gitea tea login add --name=try --url=https://try.gitea.io --token=xxxxxx tea issues +tea releases ``` ## Contributing diff --git a/cmd/releases.go b/cmd/releases.go index 5734bff..0a4c4f2 100644 --- a/cmd/releases.go +++ b/cmd/releases.go @@ -8,6 +8,8 @@ import ( "fmt" "log" + "code.gitea.io/sdk/gitea" + "github.com/urfave/cli" ) @@ -17,6 +19,9 @@ var CmdReleases = cli.Command{ Usage: "Log in a Gitea server", Description: `Log in a Gitea server`, Action: runReleases, + Subcommands: []cli.Command{ + CmdReleaseCreate, + }, Flags: []cli.Flag{ cli.StringFlag{ Name: "login, l", @@ -51,3 +56,55 @@ func runReleases(ctx *cli.Context) error { return nil } + +var CmdReleaseCreate = cli.Command{ + Name: "create", + Usage: "Create a release in repository", + Description: `Create a release in repository`, + Action: runReleaseCreate, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "tag", + Usage: "release tag name", + }, + cli.StringFlag{ + Name: "target", + Usage: "release target refs, branch name or commit id", + }, + cli.StringFlag{ + Name: "title, t", + Usage: "release title to create", + }, + cli.StringFlag{ + Name: "note, n", + Usage: "release note to create", + }, + cli.BoolFlag{ + Name: "draft, d", + Usage: "the release is a draft", + }, + cli.BoolFlag{ + Name: "prerelease, p", + Usage: "the release is a prerelease", + }, + }, +} + +func runReleaseCreate(ctx *cli.Context) error { + login, owner, repo := initCommand(ctx) + + _, err := login.Client().CreateRelease(owner, repo, gitea.CreateReleaseOption{ + TagName: ctx.String("tag"), + Target: ctx.String("target"), + Title: ctx.String("title"), + Note: ctx.String("note"), + IsDraft: ctx.Bool("draft"), + IsPrerelease: ctx.Bool("prerelease"), + }) + + if err != nil { + log.Fatal(err) + } + + return nil +}