From 1eba6ab981aa7004c81f18650bab6dd855538270 Mon Sep 17 00:00:00 2001 From: Adam Kunicki Date: Fri, 6 Jul 2018 16:31:37 -0700 Subject: [PATCH] Move from draft to WIP API --- .travis.yml | 6 +++--- README.md | 21 ++++++++++----------- cmd/brew.go | 13 ++++++++----- cmd/taste.go | 16 ++++++++-------- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/.travis.yml b/.travis.yml index ff46afd..ef76d46 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ env: before_install: - sudo apt-get -qq update - sudo apt-get install -y libssh2-1-dev - - wget https://github.com/libgit2/libgit2/archive/v0.27.0.tar.gz - - tar xf v0.27.0.tar.gz + - wget https://github.com/libgit2/libgit2/archive/v0.27.2.tar.gz + - tar xf v0.27.2.tar.gz - mkdir -p $HOME/libgit2 - - pushd libgit2-0.27.0 && mkdir -p build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/libgit2 && cmake --build . --target install && popd + - pushd libgit2-0.27.2 && mkdir -p build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/libgit2 && cmake --build . --target install && popd diff --git a/README.md b/README.md index d18b3b2..a0762c2 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,15 @@ This is a Go port of [beer-review](https://github.com/kunickiaj/beer-review) [![Build Status](https://travis-ci.org/kunickiaj/beer.svg?branch=master)](https://travis-ci.org/kunickiaj/beer) -# Prerequisites +## Prerequisites -Requires libgit2 v0.27.0 installed. On macOS `brew install libgit2`. -# Installation +Requires libgit2 v0.27 installed. On macOS `brew install libgit2`. + +## Installation `go get -u github.com/kunickiaj/beer` -# Configuration +## Configuration By default, `beer` looks for a configuration file at `~/.beer.yaml` but an alternate path can also be specified with the `--config` flag. @@ -28,19 +29,17 @@ gerrit: url: https://gerrit.googlesource.com ``` -# Usage +## Usage All help is accessible by specifying the `--help` flag to any beer command/subcommand. `beer --help` will provide an overview of available commands. -## Common Workflow - -### Work on a JIRA issue +### Common Workflow -#### Existing issue +#### Work on an Existing JIRA issue `beer brew PRJ-1234` will create a new work branch from issue PRJ-1234 and insert an empty commit with the issue key followed by the issue summary as the commit message. It will also transition the JIRA issue to an In Progress state. -#### New Issue +#### Work on a New JIRA issue `beer brew -t Bug -s 'My issue summary' -d 'My detailed issue description` will create a new JIRA issue of type Bug, with the specified summary and detailed description. it will then create a new work branch from the newly created issue with the issue key followed by the issue summary as the commit message. It will also transition the JIRA issue to an In Progress state. @@ -54,7 +53,7 @@ For example: `git commit -a --amend` ### Create a new review -`beer taste` will push a review to the configured Gerrit server. The `--draft` flag is available if you wish to push a draft/WIP review. +`beer taste` will push a review to the configured Gerrit server. The `--wip` flag is available if you wish to push a WIP review. ### Submit a change diff --git a/cmd/brew.go b/cmd/brew.go index 6e78d5e..504517d 100644 --- a/cmd/brew.go +++ b/cmd/brew.go @@ -23,10 +23,10 @@ import ( "regexp" jira "github.com/andygrunwald/go-jira" + git "github.com/libgit2/git2go" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" - "gopkg.in/libgit2/git2go.v27" ) var brewCmd = &cobra.Command{ @@ -102,11 +102,15 @@ func brew(cmd *cobra.Command, args []string) { } // Ensure issue is assigned to self - assignee := map[string]interface{}{"Assignee": jiraUser} + assignee := map[string]interface{}{"fields": map[string]interface{}{"assignee": jiraUser}} - _, err := jiraClient.Issue.UpdateIssue(issue.ID, assignee) + response, err := jiraClient.Issue.UpdateIssue(issue.ID, assignee) if err != nil { - panic(err) + log. + WithError(err). + WithField("response", bodyToString(response)). + Fatal("Failed to update issue") + return } } else { @@ -272,7 +276,6 @@ func checkout(repo *git.Repository, issue *jira.Issue) error { } if newBranch { - fmt.Printf("\nfields: %+v", issue) commitMessage := fmt.Sprintf("%s. %s", issue.Key, issue.Fields.Summary) _, err = repo.CreateCommit("refs/heads/"+issue.Key, signature, signature, commitMessage, tree, headCommit) } diff --git a/cmd/taste.go b/cmd/taste.go index 335006d..a785c23 100644 --- a/cmd/taste.go +++ b/cmd/taste.go @@ -20,8 +20,8 @@ import ( "os" "strings" + git "github.com/libgit2/git2go" "github.com/spf13/cobra" - git "gopkg.in/libgit2/git2go.v27" ) var tasteCmd = &cobra.Command{ @@ -32,19 +32,19 @@ var tasteCmd = &cobra.Command{ Args: cobra.ExactArgs(0), } -var draft bool +var wip bool var reviewers []string func init() { RootCmd.AddCommand(tasteCmd) - tasteCmd.Flags().BoolVarP(&draft, "draft", "d", false, "Setting this flag will post a draft review") + tasteCmd.Flags().BoolVar(&wip, "wip", false, "Setting this flag will post a WIP review") tasteCmd.Flags().StringArrayVarP(&reviewers, "reviewers", "r", nil, "Comma separated list of email ids of reviewers to add") } func taste(cmd *cobra.Command, args []string) { dryRun, _ := cmd.Flags().GetBool("dry-run") - isDraft, _ := cmd.Flags().GetBool("draft") + isWIP, _ := cmd.Flags().GetBool("wip") reviewers, _ := cmd.Flags().GetStringArray("reviewers") if dryRun { @@ -64,13 +64,13 @@ func taste(cmd *cobra.Command, args []string) { defer repo.Free() var ref string - if isDraft { - ref = "drafts" + if isWIP { + ref = "master%wip" } else { - ref = "for" + ref = "master" } - refspec := fmt.Sprintf("HEAD:refs/%s/%s", ref, "master") + refspec := fmt.Sprintf("HEAD:refs/for/%s", ref) if len(reviewers) > 0 { refspec = fmt.Sprintf("%s%%r=%s", refspec, strings.Join(reviewers, ",r=")) }