Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,22 @@ releases:
- v0.1.0, name: 'hoary ungar', description: 'something something dark side 2', id: 166740, tagged: 29/01/2014 at 14:27, published: 30/01/2014 at 16:20, draft: ✔, prerelease: ✗
- artifact: github.go, downloads: 0, state: uploaded, type: application/octet-stream, size: 1.9KB, id: 68616

# create a formal release
# create a draft release (or a published release if you omit the --draft flag)
$ github-release release \
--user aktau \
--repo gofinance \
--tag v0.1.0 \
--name "the wolf of source street" \
--description "Not a movie, contrary to popular opinion. Still, my first release!" \
--draft \
--pre-release

# move draft to published state
$ github-release publish \
--user aktau \
--repo gofinance \
--tag v0.1.0

# you've made a mistake, but you can edit the release without
# having to delete it first (this also means you can edit without having
# to upload your files again)
Expand Down
66 changes: 66 additions & 0 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,3 +487,69 @@ func deletecmd(opt Options) error {

return nil
}

func publishcmd(opt Options) error {
cmdopt := opt.Publish
user := nvls(cmdopt.User, EnvUser)
authUser := nvls(opt.Info.AuthUser, EnvAuthUser)
repo := nvls(cmdopt.Repo, EnvRepo)
token := nvls(cmdopt.Token, EnvToken)
tag := cmdopt.Tag

vprintln("publishing...")

if err := ValidateCredentials(user, repo, token, tag); err != nil {
return err
}

/* look up the release */
vprintf("%v/%v/%v: getting information for the release\n", user, repo, tag)
release, err := ReleaseOfTag(user, repo, tag, authUser, token)
if err != nil {
return err
}

vprintf("release %v has id %v\n", tag, release.Id)

/* the release create struct works for editing releases as well */
params := ReleaseCreate{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a link to the Github docs where Github describes the types of these parameters and what they mean? Either here or on the ReleaseCreate object definition?

TagName: release.TagName,
Name: release.Name,
Body: release.Description,
Draft: false,
Prerelease: release.Prerelease,
}

/* encode the parameters as JSON, as required by the github API */
payload, err := json.Marshal(params)
if err != nil {
return fmt.Errorf("can't encode release edit params, %v", err)
}

uri := nvls(EnvApiEndpoint, github.DefaultBaseURL) + fmt.Sprintf("/repos/%s/%s/releases/%d", user, repo, release.Id)
resp, err := github.DoAuthRequest("PATCH", uri, "application/json",
token, nil, bytes.NewReader(payload))
if err != nil {
return fmt.Errorf("while submitting %v, %v", string(payload), err)
}
defer resp.Body.Close()

vprintln("RESPONSE:", resp)
if resp.StatusCode != http.StatusOK {
if resp.StatusCode == 422 {
return fmt.Errorf("github returned %v (this is probably because the release already exists)",
resp.Status)
}
return fmt.Errorf("github returned unexpected status code %v", resp.Status)
}

if VERBOSITY != 0 {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("error while reading response, %v", err)
}
vprintln("BODY:", string(body))
}

return nil
}
7 changes: 7 additions & 0 deletions github-release.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ type Options struct {
Tag string `goptions:"-t, --tag, description='Git tag to query (optional)'"`
JSON bool `goptions:"-j, --json, description='Emit info as JSON instead of text'"`
} `goptions:"info"`
Publish struct {
Token string `goptions:"-s, --security-token, description='Github token ($GITHUB_TOKEN if set). required if repo is private.'"`
User string `goptions:"-u, --user, description='Github user (required if $GITHUB_USER not set)'"`
Repo string `goptions:"-r, --repo, description='Github repo (required if $GITHUB_REPO not set)'"`
Tag string `goptions:"-t, --tag, description='Git tag to query (optional)'"`
} `goptions:"publish"`
}

type Command func(Options) error
Expand All @@ -85,6 +91,7 @@ var commands = map[goptions.Verbs]Command{
"edit": editcmd,
"delete": deletecmd,
"info": infocmd,
"publish": publishcmd,
}

var (
Expand Down