Skip to content

Commit

Permalink
make "jira" golang package, move code from jira/cli to root, move jir…
Browse files Browse the repository at this point in the history
…a/main.go to main/main.go
  • Loading branch information
coryb committed Dec 23, 2015
1 parent 2df21d3 commit 7268b9e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 24 deletions.
39 changes: 27 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,32 @@ PLATFORMS= \
$(NULL)

DIST=$(shell pwd)/dist

export GOPATH=$(shell pwd)
GOBIN ?= $(shell pwd)/bin

GOBIN ?= $(shell pwd)
NAME=jira

BIN ?= $(GOBIN)/$(NAME)

CURVER ?= $(shell [ -d .git ] && git describe --abbrev=0 --tags || grep ^\#\# CHANGELOG.md | awk '{print $$2; exit}')
LDFLAGS:=-X main.buildVersion=$(CURVER)
LDFLAGS:=-X jira.VERSION=$(patsubst v%,%,$(CURVER)) -w

# use make DEBUG=1 and you can get a debuggable golang binary
# see https://github.com/mailgun/godebug
ifneq ($(DEBUG),)
GOBUILD=go get -v github.com/mailgun/godebug && ./bin/godebug build
else
GOBUILD=go build -v -ldflags "$(LDFLAGS) -s"
endif

build: src/github.com/Netflix-Skunkworks/go-jira
go build -ldflags "$(LDFLAGS)" -o $(GOBIN)/$(NAME) jira/main.go
$(GOBUILD) -o $(BIN) main/main.go

src/%:
mkdir -p $(@D)
test -L $@ || ln -sf ../../.. $@
go get -v $*/jira
go get -v $* $*/main

cross-setup:
for p in $(PLATFORMS); do \
Expand All @@ -40,33 +52,36 @@ all:
mkdir -p $(DIST); \
for p in $(PLATFORMS); do \
echo "Building for $$p"; \
GOOS=$${p/-*/} GOARCH=$${p/*-/} go build -v -ldflags "$(LDFLAGS) -s" -o $(DIST)/$(NAME)-$$p jira/main.go ; \
${MAKE} build GOOS=$${p/-*/} GOARCH=$${p/*-/} BIN=$(DIST)/$(NAME)-$$p; \
done

fmt:
gofmt -s -w jira
gofmt -s -w main/*.go *.go

install:
export GOBIN=~/bin && ${MAKE} build
${MAKE} GOBIN=~/bin build

NEWVER ?= $(shell echo $(CURVER) | awk -F. '{print $$1"."$$2"."$$3+1}')
TODAY := $(shell date +%Y-%m-%d)

changes:
@git log --pretty=format:"* %s [%cn] [%h]" --no-merges ^$(CURVER) HEAD jira | grep -v gofmt | grep -v "bump version"
@git log --pretty=format:"* %s [%cn] [%h]" --no-merges ^$(CURVER) HEAD main/*.go *.go | grep -vE 'gofmt|go fmt'

update-changelog:
update-changelog:
@echo "# Changelog" > CHANGELOG.md.new; \
echo >> CHANGELOG.md.new; \
echo "## $(NEWVER) - $(TODAY)" >> CHANGELOG.md.new; \
echo >> CHANGELOG.md.new; \
$(MAKE) changes | \
$(MAKE) --no-print-directory --silent changes | \
perl -pe 's{\[([a-f0-9]+)\]}{[[$$1](https://github.com/Netflix-Skunkworks/go-jira/commit/$$1)]}g' | \
perl -pe 's{\#(\d+)}{[#$$1](https://github.com/Netflix-Skunkworks/go-jira/issues/$$1)}g' >> CHANGELOG.md.new; \
tail +2 CHANGELOG.md >> CHANGELOG.md.new; \
tail -n +2 CHANGELOG.md >> CHANGELOG.md.new; \
mv CHANGELOG.md.new CHANGELOG.md; \
git commit -m "Updated Changelog" CHANGELOG.md; \
git tag $(NEWVER)

version:
@echo $(patsubst v%,%,$(CURVER))

clean:
rm -rf pkg dist bin src ./toolkit
rm -rf pkg dist bin src ./$(NAME)
7 changes: 5 additions & 2 deletions jira/cli/cli.go → cli.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cli
package jira

import (
"bytes"
Expand All @@ -18,7 +18,10 @@ import (
"time"
)

var log = logging.MustGetLogger("jira.cli")
var (
log = logging.MustGetLogger("jira")
VERSION string
)

type Cli struct {
endpoint *url.URL
Expand Down
2 changes: 1 addition & 1 deletion jira/cli/commands.go → commands.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cli
package jira

import (
"bytes"
Expand Down
13 changes: 6 additions & 7 deletions jira/main.go → main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"bytes"
"fmt"
"github.com/Netflix-Skunkworks/go-jira/jira/cli"
"github.com/Netflix-Skunkworks/go-jira"
"github.com/coryb/optigo"
"github.com/op/go-logging"
"gopkg.in/coryb/yaml.v2"
Expand All @@ -16,7 +16,6 @@ import (
var (
log = logging.MustGetLogger("jira")
format = "%{color}%{time:2006-01-02T15:04:05.000Z07:00} %{level:-5s} [%{shortfile}]%{color:reset} %{message}"
buildVersion string
)

func main() {
Expand Down Expand Up @@ -172,7 +171,7 @@ Command Options:
op := optigo.NewDirectAssignParser(map[string]interface{}{
"h|help": usage,
"version": func() {
fmt.Println(fmt.Sprintf("version: %s", buildVersion))
fmt.Println(fmt.Sprintf("version: %s", jira.VERSION))
os.Exit(0)
},
"v|verbose+": func() {
Expand Down Expand Up @@ -258,7 +257,7 @@ Command Options:
os.Exit(1)
}

c := cli.New(opts)
c := jira.New(opts)

log.Debug("opts: %s", opts)

Expand Down Expand Up @@ -306,7 +305,7 @@ Command Options:
for _, issue := range issues {
if err = c.CmdEdit(issue.(map[string]interface{})["key"].(string)); err != nil {
switch err.(type) {
case cli.NoChangesFound:
case jira.NoChangesFound:
log.Warning("No Changes found: %s", err)
err = nil
continue
Expand Down Expand Up @@ -441,9 +440,9 @@ func populateEnv(opts map[string]interface{}) {

func loadConfigs(opts map[string]interface{}) {
populateEnv(opts)
paths := cli.FindParentPaths(".jira.d/config.yml")
paths := jira.FindParentPaths(".jira.d/config.yml")
// prepend
paths = append([]string{"/etc/jira-cli.yml"}, paths...)
paths = append([]string{"/etc/go-jira.yml"}, paths...)

// iterate paths in reverse
for i := len(paths) - 1; i >= 0; i-- {
Expand Down
2 changes: 1 addition & 1 deletion jira/cli/templates.go → templates.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cli
package jira

var all_templates = map[string]string{
"debug": default_debug_template,
Expand Down
2 changes: 1 addition & 1 deletion jira/cli/util.go → util.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cli
package jira

import (
"bufio"
Expand Down

0 comments on commit 7268b9e

Please sign in to comment.