Skip to content

Commit

Permalink
Move from draft to WIP API
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Kunicki committed Jul 6, 2018
1 parent 5ae984a commit 1eba6ab
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Expand All @@ -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

Expand Down
13 changes: 8 additions & 5 deletions cmd/brew.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/taste.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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 {
Expand All @@ -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="))
}
Expand Down

0 comments on commit 1eba6ab

Please sign in to comment.