Compare commits

..

29 Commits

Author SHA1 Message Date
Cory Bennett b98da3612d Updated Changelog 2018-04-15 19:21:10 -07:00
Cory Bennett 7f9595cf15 fix IsTerminal usage for windows 2018-04-15 19:10:29 -07:00
Cory Bennett 09584981b6 version bump 2018-04-15 17:55:00 -07:00
Cory Bennett 1bc6b55b85 Updated Changelog 2018-04-15 17:55:00 -07:00
Cory Bennett d787ac030c [#166] fix issue when editing templates specified with full path 2018-04-15 17:40:22 -07:00
Cory Bennett 09a61c3ea1 only prompt on logout if stdin and stdout are terminals 2018-04-15 17:15:48 -07:00
Cory Bennett 64ce3812a6 only prompt on logout if stdin is an active terminal 2018-04-15 17:07:01 -07:00
Cory Bennett 9146346e2f [#163] fix url path join logic 2018-04-15 16:56:09 -07:00
Cory Bennett e639cce9af [#160] prompt when api-token is invalid to get new token 2018-04-15 15:30:30 -07:00
Cory Bennett 06b26c9e00 [#157] add password-directory: path to allow overriding PASSWORD_STORE_DIR from configs 2018-04-15 13:56:37 -07:00
coryb ac39f9ae1d Merge pull request #161 from vanniktech/patch-1
Add syntax highlighting to YAML blocks in README
2018-04-03 09:28:36 -07:00
Cory Bennett bd3cf994b8 [#160] allow jira logout to delete your api-token from keychain 2018-04-03 09:21:52 -07:00
Niklas Baudy 91059b3578 Add syntax highlighting to YAML blocks in README 2018-04-03 17:45:39 +02:00
Cory Bennett 4b9873b323 version bump 2018-04-01 12:04:52 -07:00
Cory Bennett cd106df78a Updated Changelog 2018-04-01 12:04:52 -07:00
Cory Bennett 50b5360cfe Updated Usage 2018-04-01 12:04:52 -07:00
Cory Bennett 359bec2fdf [#159] fix slice bounds out of range error in abbrev template function 2018-04-01 11:47:23 -07:00
Cory Bennett 79c83f6911 [#158] always print usage to stdout 2018-04-01 11:31:09 -07:00
coryb 585382eaea Merge pull request #150 from catskul/parameterized-go-makefile
make it easier to compile with aribtrary version of go via GO env var
2018-03-08 14:15:11 -08:00
Cory Bennett 9c818d427c use latest xgo since the project has been updated again 2018-03-08 13:54:04 -08:00
Cory Bennett 8621d9e698 version bump 2018-03-08 13:54:04 -08:00
Cory Bennett 5610707c30 Updated Changelog 2018-03-08 13:54:04 -08:00
Cory Bennett 0b4e16a35d Updated Usage 2018-03-08 13:54:04 -08:00
coryb 57bc97a378 Merge pull request #153 from catskul/document-shell-completion
Document shell completion
2018-03-08 13:48:56 -08:00
Andrew Somerville 2d02cf8132 fix md link 2018-03-08 16:47:25 -05:00
coryb 18a687e78a Merge pull request #152 from catskul/fix-missing-priority
prevent crash if priority is not set
2018-03-08 13:47:02 -08:00
Andrew Somerville 5d058536d2 Add in a stanza to the Usage section about tab completion 2018-03-08 16:38:36 -05:00
Andrew Somerville fd30bc1392 prevent crash if priority is not set 2018-03-07 16:59:47 -05:00
Andrew Somerville dea794f037 make it easier to compile with aribtrary version of go via GO env var 2018-03-07 15:59:40 -05:00
39 changed files with 170 additions and 92 deletions
+1
View File
@@ -3,6 +3,7 @@ config:
password-source: pass password-source: pass
endpoint: https://go-jira.atlassian.net endpoint: https://go-jira.atlassian.net
user: admin user: admin
login: atlassian@corybennett.org
queries: queries:
todo: | todo: |
+15
View File
@@ -1,5 +1,20 @@
# Changelog # Changelog
## 1.0.17 - 2018-04-15
* fix IsTerminal usage for windows [Cory Bennett] [[7f9595c](https://github.com/Netflix-Skunkworks/go-jira/commit/7f9595c)]
* [[#166](https://github.com/Netflix-Skunkworks/go-jira/issues/166)] fix issue when editing templates specified with full path [Cory Bennett] [[d787ac0](https://github.com/Netflix-Skunkworks/go-jira/commit/d787ac0)]
* only prompt on logout if stdin and stdout are terminals [Cory Bennett] [[09a61c3](https://github.com/Netflix-Skunkworks/go-jira/commit/09a61c3)]
* [[#163](https://github.com/Netflix-Skunkworks/go-jira/issues/163)] fix url path join logic [Cory Bennett] [[9146346](https://github.com/Netflix-Skunkworks/go-jira/commit/9146346)]
* [[#160](https://github.com/Netflix-Skunkworks/go-jira/issues/160)] prompt when api-token is invalid to get new token [Cory Bennett] [[e639cce](https://github.com/Netflix-Skunkworks/go-jira/commit/e639cce)]
* [[#157](https://github.com/Netflix-Skunkworks/go-jira/issues/157)] add `password-directory: path` to allow overriding PASSWORD_STORE_DIR from configs [Cory Bennett] [[06b26c9](https://github.com/Netflix-Skunkworks/go-jira/commit/06b26c9)]
* [[#160](https://github.com/Netflix-Skunkworks/go-jira/issues/160)] allow `jira logout` to delete your api-token from keychain [Cory Bennett] [[bd3cf99](https://github.com/Netflix-Skunkworks/go-jira/commit/bd3cf99)]
## 1.0.16 - 2018-04-01
* [[#159](https://github.com/Netflix-Skunkworks/go-jira/issues/159)] fix `slice bounds out of range` error in `abbrev` template function [Cory Bennett] [[359bec2](https://github.com/Netflix-Skunkworks/go-jira/commit/359bec2)]
* [[#158](https://github.com/Netflix-Skunkworks/go-jira/issues/158)] always print usage to stdout [Cory Bennett] [[79c83f6](https://github.com/Netflix-Skunkworks/go-jira/commit/79c83f6)]
## 1.0.15 - 2018-03-08 ## 1.0.15 - 2018-03-08
* [[#147](https://github.com/Netflix-Skunkworks/go-jira/issues/147)] [[#148](https://github.com/Netflix-Skunkworks/go-jira/issues/148)] add support for api token based authentication [Cory Bennett] [[edb0662](https://github.com/Netflix-Skunkworks/go-jira/commit/edb0662)] * [[#147](https://github.com/Netflix-Skunkworks/go-jira/issues/147)] [[#148](https://github.com/Netflix-Skunkworks/go-jira/issues/148)] add support for api token based authentication [Cory Bennett] [[edb0662](https://github.com/Netflix-Skunkworks/go-jira/commit/edb0662)]
+10 -9
View File
@@ -1,4 +1,5 @@
NAME=jira NAME=jira
GO?=go
OS=$(shell uname -s) OS=$(shell uname -s)
ifeq ($(filter CYGWIN%,$(OS)),$(OS)) ifeq ($(filter CYGWIN%,$(OS)),$(OS))
@@ -20,17 +21,17 @@ CURVER ?= $(patsubst v%,%,$(shell [ -d .git ] && git describe --abbrev=0 --tags
LDFLAGS:= -w LDFLAGS:= -w
build: build:
go build -gcflags="-e" -v -ldflags "$(LDFLAGS) -s" -o '$(BIN)' cmd/jira/main.go $(GO) build -gcflags="-e" -v -ldflags "$(LDFLAGS) -s" -o '$(BIN)' cmd/jira/main.go
vet: vet:
@go vet . @$(GO) vet .
@go vet ./jiracli @$(GO) vet ./jiracli
@go vet ./jiracmd @$(GO) vet ./jiracmd
@go vet ./jiradata @$(GO) vet ./jiradata
@go vet ./cmd/jira @$(GO) vet ./cmd/jira
lint: lint:
@go get github.com/golang/lint/golint @$(GO) get github.com/golang/lint/golint
@golint . @golint .
@golint ./jiracli @golint ./jiracli
@golint ./jiracmd @golint ./jiracmd
@@ -38,10 +39,10 @@ lint:
@golint ./cmd/jira @golint ./cmd/jira
all: all:
go get -u github.com/karalabe/xgo $(GO) get -u github.com/karalabe/xgo
rm -rf dist rm -rf dist
mkdir -p dist mkdir -p dist
xgo --go 1.9.0 --targets="freebsd/amd64,linux/386,linux/amd64,windows/386,windows/amd64,darwin/amd64" -dest ./dist -ldflags="-w -s" ./cmd/jira xgo --targets="freebsd/amd64,linux/386,linux/amd64,windows/386,windows/amd64,darwin/amd64" -dest ./dist -ldflags="-w -s" ./cmd/jira
install: install:
${MAKE} GOBIN=$$HOME/bin build ${MAKE} GOBIN=$$HOME/bin build
+24 -10
View File
@@ -1,4 +1,4 @@
g[![Join the chat at https://gitter.im/go-jira-cli/help](https://badges.gitter.im/go-jira-cli/help.svg)](https://gitter.im/go-jira-cli/help?utm_source=badge&utm_medium=badge&utm_content=badge) [![Join the chat at https://gitter.im/go-jira-cli/help](https://badges.gitter.im/go-jira-cli/help.svg)](https://gitter.im/go-jira-cli/help?utm_source=badge&utm_medium=badge&utm_content=badge)
[![Build Status](https://travis-ci.org/Netflix-Skunkworks/go-jira.svg?branch=master)](https://travis-ci.org/Netflix-Skunkworks/go-jira) [![Build Status](https://travis-ci.org/Netflix-Skunkworks/go-jira.svg?branch=master)](https://travis-ci.org/Netflix-Skunkworks/go-jira)
[![GoDoc](https://godoc.org/gopkg.in/Netflix-Skunkworks/go-jira.v1?status.svg)](https://godoc.org/gopkg.in/Netflix-Skunkworks/go-jira.v1) [![GoDoc](https://godoc.org/gopkg.in/Netflix-Skunkworks/go-jira.v1?status.svg)](https://godoc.org/gopkg.in/Netflix-Skunkworks/go-jira.v1)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
@@ -31,6 +31,7 @@ g[![Join the chat at https://gitter.im/go-jira-cli/help](https://badges.gitter.i
* [keyring password source](#keyring-password-source) * [keyring password source](#keyring-password-source)
* [pass password source](#pass-password-source) * [pass password source](#pass-password-source)
* [Usage](#usage) * [Usage](#usage)
* [TAB completion](#setting-up-tab-completion)
# go-jira # go-jira
simple command line client for Atlassian's Jira service written in Go simple command line client for Atlassian's Jira service written in Go
@@ -92,7 +93,7 @@ esac
###### **Custom Commands** ###### **Custom Commands**
Now you can create your own custom commands to do common operations with jira. Please see the details **Custom Commands** section below for more details. If you want to create a command `jira mine` that lists all the issues assigned to you now you can modify your `.jira.d/config.yml` file to add a `custom-commands` section like this: Now you can create your own custom commands to do common operations with jira. Please see the details **Custom Commands** section below for more details. If you want to create a command `jira mine` that lists all the issues assigned to you now you can modify your `.jira.d/config.yml` file to add a `custom-commands` section like this:
``` ```yaml
custom-commands: custom-commands:
- name: mine - name: mine
help: display issues assigned to me help: display issues assigned to me
@@ -137,7 +138,7 @@ Previously `jira` used attempt to get a `JSESSION` cookies by authenticating wit
The complicated configuration hierarchy is used because **go-jira** attempts to be context aware. For example, if you are working on a "foo" project and you `cd` into your project workspace, wouldn't it be nice if `jira ls` automatically knew to list only issues related to the "foo" project? Likewise when you `cd` to the "bar" project then `jira ls` should only list issues related to "bar" project. You can do this with by creating a configuration under your project workspace at **./.jira.d/config.yml** that looks like: The complicated configuration hierarchy is used because **go-jira** attempts to be context aware. For example, if you are working on a "foo" project and you `cd` into your project workspace, wouldn't it be nice if `jira ls` automatically knew to list only issues related to the "foo" project? Likewise when you `cd` to the "bar" project then `jira ls` should only list issues related to "bar" project. You can do this with by creating a configuration under your project workspace at **./.jira.d/config.yml** that looks like:
``` ```yaml
project: foo project: foo
``` ```
@@ -185,7 +186,7 @@ esac
### Custom Commands ### Custom Commands
You can now create custom commands for `jira` just by editing your `.jira.d/config.yml` config file. These commands are effectively shell-scripts that can have documented options and arguments. The basic format is like: You can now create custom commands for `jira` just by editing your `.jira.d/config.yml` config file. These commands are effectively shell-scripts that can have documented options and arguments. The basic format is like:
``` ```yaml
custom-commands: custom-commands:
- command1 - command1
- command2 - command2
@@ -233,7 +234,7 @@ These are possible keys under the command `args` property:
The `script` property is a template that whould produce `/bin/sh` compatible syntax after the template has been processed. There are 2 key template functions `{{args}}` and `{{options}}` that return the parsed arguments and option flags as a map. The `script` property is a template that whould produce `/bin/sh` compatible syntax after the template has been processed. There are 2 key template functions `{{args}}` and `{{options}}` that return the parsed arguments and option flags as a map.
To demonstrate how you might use args and options here is a `custom-test` command: To demonstrate how you might use args and options here is a `custom-test` command:
``` ```yaml
custom-commands: custom-commands:
- name: custom-test - name: custom-test
help: Testing the custom commands help: Testing the custom commands
@@ -284,7 +285,7 @@ COMMAND arg1 --abc short-non-default --day Tuesday more1 more2 more3
``` ```
The script has access to all the environment variables that are in your current environment plus those that `jira` will set. `jira` sets environment variables for each config property it has parsed from `.jira.d/config.yml` or the command configs at `.jira.d/<command>.yml`. It might be useful to see all environment variables that `jira` is producing, so here is a simple custom command to list them: The script has access to all the environment variables that are in your current environment plus those that `jira` will set. `jira` sets environment variables for each config property it has parsed from `.jira.d/config.yml` or the command configs at `.jira.d/<command>.yml`. It might be useful to see all environment variables that `jira` is producing, so here is a simple custom command to list them:
``` ```yaml
custom-commands: custom-commands:
- name: env - name: env
help: print the JIRA environment variables available to custom commands help: print the JIRA environment variables available to custom commands
@@ -293,7 +294,7 @@ custom-commands:
``` ```
You could use the environment variables automatically, so if your `.jira.d/config.yml` looks something like this: You could use the environment variables automatically, so if your `.jira.d/config.yml` looks something like this:
``` ```yaml
project: PROJECT project: PROJECT
custom-commands: custom-commands:
- name: print-project - name: print-project
@@ -304,7 +305,7 @@ custom-commands:
##### Examples ##### Examples
* `jira mine` for listing issues assigned to you * `jira mine` for listing issues assigned to you
``` ```yaml
custom-commands: custom-commands:
- name: mine - name: mine
help: display issues assigned to me help: display issues assigned to me
@@ -318,7 +319,7 @@ custom-commands:
fi fi
``` ```
* `jira sprint` for listing issues in your current sprint * `jira sprint` for listing issues in your current sprint
``` ```yaml
custom-commands: custom-commands:
- name: sprint - name: sprint
help: display issues for active sprint help: display issues for active sprint
@@ -374,7 +375,7 @@ If your Jira service still allows you to use the Session based authention method
#### User vs Login #### User vs Login
The Jira service has sometimes differing opinions about how a user is identified. In other words the ID you login with might not be ID that the jira system recognized you as. This matters when trying to identify a user via various Jira REST APIs (like issue assignment). This is especially relevent when trying to authenticate with an API Token where the authentication user is usually an email address, but within the Jira system the user is identified by a user name. To accomodate this `jira` now supports two different properties in the config file. So when authentication using the API Tokens you will likely want something like this in your `$HOME/.jira.d/config.yml` file: The Jira service has sometimes differing opinions about how a user is identified. In other words the ID you login with might not be ID that the jira system recognized you as. This matters when trying to identify a user via various Jira REST APIs (like issue assignment). This is especially relevent when trying to authenticate with an API Token where the authentication user is usually an email address, but within the Jira system the user is identified by a user name. To accomodate this `jira` now supports two different properties in the config file. So when authentication using the API Tokens you will likely want something like this in your `$HOME/.jira.d/config.yml` file:
``` ```yaml
user: person user: person
login: person@example.com login: person@example.com
``` ```
@@ -443,6 +444,19 @@ export GPG_TTY=$(tty)
## Usage ## Usage
#### Setting up TAB completion
Since go-jira is build with the "kingpin" golang command line library we supports bash/zsh shell completion automatically:
* <https://github.com/alecthomas/kingpin/tree/v2.2.5#bashzsh-shell-completion>
For example, in bash, adding something along the lines of:
`eval "$(jira --completion-script-bash)"`
to your bashrc, or .profile (assuming go-jira binary is already in your path) will cause jira to offer tab completion behavior.
``` ```
usage: jira [<flags>] <command> [<args> ...] usage: jira [<flags>] <command> [<args> ...]
+2 -4
View File
@@ -1,8 +1,6 @@
package jira package jira
import ( import (
"fmt"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata" "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
) )
@@ -12,7 +10,7 @@ func (j *Jira) GetAttachment(id string) (*jiradata.Attachment, error) {
} }
func GetAttachment(ua HttpClient, endpoint string, id string) (*jiradata.Attachment, error) { func GetAttachment(ua HttpClient, endpoint string, id string) (*jiradata.Attachment, error) {
uri := fmt.Sprintf("%s/rest/api/2/attachment/%s", endpoint, id) uri := URLJoin(endpoint, "rest/api/2/attachment", id)
resp, err := ua.GetJSON(uri) resp, err := ua.GetJSON(uri)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -32,7 +30,7 @@ func (j *Jira) RemoveAttachment(id string) error {
} }
func RemoveAttachment(ua HttpClient, endpoint string, id string) error { func RemoveAttachment(ua HttpClient, endpoint string, id string) error {
uri := fmt.Sprintf("%s/rest/api/2/attachment/%s", endpoint, id) uri := URLJoin(endpoint, "rest/api/2/attachment", id)
resp, err := ua.Delete(uri) resp, err := ua.Delete(uri)
if err != nil { if err != nil {
return err return err
+1 -2
View File
@@ -3,7 +3,6 @@ package jira
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata" "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
) )
@@ -23,7 +22,7 @@ func CreateComponent(ua HttpClient, endpoint string, cp ComponentProvider) (*jir
if err != nil { if err != nil {
return nil, err return nil, err
} }
uri := fmt.Sprintf("%s/rest/api/2/component", endpoint) uri := URLJoin(endpoint, "rest/api/2/component")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded)) resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil { if err != nil {
return nil, err return nil, err
+3 -3
View File
@@ -23,7 +23,7 @@ func EpicSearch(ua HttpClient, endpoint string, epic string, sp SearchProvider)
// if err != nil { // if err != nil {
// return nil, err // return nil, err
// } // }
uri, err := url.Parse(fmt.Sprintf("%s/rest/agile/1.0/epic/%s/issue", endpoint, epic)) uri, err := url.Parse(URLJoin(endpoint, "rest/agile/1.0/epic", epic, "issue"))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -74,7 +74,7 @@ func EpicAddIssues(ua HttpClient, endpoint string, epic string, eip EpicIssuesPr
return err return err
} }
uri := fmt.Sprintf("%s/rest/agile/1.0/epic/%s/issue", endpoint, epic) uri := URLJoin(endpoint, "rest/agile/1.0/epic", epic, "issue")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded)) resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil { if err != nil {
return err return err
@@ -99,7 +99,7 @@ func EpicRemoveIssues(ua HttpClient, endpoint string, eip EpicIssuesProvider) er
return err return err
} }
uri := fmt.Sprintf("%s/rest/agile/1.0/epic/none/issue", endpoint) uri := URLJoin(endpoint, "rest/agile/1.0/epic/none/issue")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded)) resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil { if err != nil {
return err return err
+1 -3
View File
@@ -1,8 +1,6 @@
package jira package jira
import ( import (
"fmt"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata" "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
) )
@@ -12,7 +10,7 @@ func (j *Jira) GetFields() ([]jiradata.Field, error) {
} }
func GetFields(ua HttpClient, endpoint string) ([]jiradata.Field, error) { func GetFields(ua HttpClient, endpoint string) ([]jiradata.Field, error) {
uri := fmt.Sprintf("%s/rest/api/2/field", endpoint) uri := URLJoin(endpoint, "rest/api/2/field")
resp, err := ua.GetJSON(uri) resp, err := ua.GetJSON(uri)
if err != nil { if err != nil {
return nil, err return nil, err
+26 -20
View File
@@ -59,7 +59,8 @@ func GetIssue(ua HttpClient, endpoint string, issue string, iqg IssueQueryProvid
if iqg != nil { if iqg != nil {
query = iqg.ProvideIssueQueryString() query = iqg.ProvideIssueQueryString()
} }
uri := fmt.Sprintf("%s/rest/api/2/issue/%s%s", endpoint, issue, query) uri := URLJoin(endpoint, "rest/api/2/issue", issue)
uri += query
resp, err := ua.GetJSON(uri) resp, err := ua.GetJSON(uri)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -84,7 +85,8 @@ func GetIssueWorklog(ua HttpClient, endpoint string, issue string) (*jiradata.Wo
maxResults := 100 maxResults := 100
worklogs := jiradata.Worklogs{} worklogs := jiradata.Worklogs{}
for startAt < total { for startAt < total {
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/worklog?startAt=%d&maxResults=%d", endpoint, issue, startAt, maxResults) uri := URLJoin(endpoint, "rest/api/2/issue", issue, "worklog")
uri += fmt.Sprintf("?startAt=%d&maxResults=%d", startAt, maxResults)
resp, err := ua.GetJSON(uri) resp, err := ua.GetJSON(uri)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -124,7 +126,7 @@ func AddIssueWorklog(ua HttpClient, endpoint string, issue string, wp WorklogPro
if err != nil { if err != nil {
return nil, err return nil, err
} }
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/worklog", endpoint, issue) uri := URLJoin(endpoint, "rest/api/2/issue", issue, "worklog")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded)) resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil { if err != nil {
return nil, err return nil, err
@@ -144,7 +146,7 @@ func (j *Jira) GetIssueEditMeta(issue string) (*jiradata.EditMeta, error) {
} }
func GetIssueEditMeta(ua HttpClient, endpoint string, issue string) (*jiradata.EditMeta, error) { func GetIssueEditMeta(ua HttpClient, endpoint string, issue string) (*jiradata.EditMeta, error) {
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/editmeta", endpoint, issue) uri := URLJoin(endpoint, "rest/api/2/issue", issue, "editmeta")
resp, err := ua.GetJSON(uri) resp, err := ua.GetJSON(uri)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -173,7 +175,7 @@ func EditIssue(ua HttpClient, endpoint string, issue string, iup IssueUpdateProv
if err != nil { if err != nil {
return err return err
} }
uri := fmt.Sprintf("%s/rest/api/2/issue/%s", endpoint, issue) uri := URLJoin(endpoint, "rest/api/2/issue", issue)
resp, err := ua.Put(uri, "application/json", bytes.NewBuffer(encoded)) resp, err := ua.Put(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil { if err != nil {
return err return err
@@ -197,7 +199,7 @@ func CreateIssue(ua HttpClient, endpoint string, iup IssueUpdateProvider) (*jira
if err != nil { if err != nil {
return nil, err return nil, err
} }
uri := fmt.Sprintf("%s/rest/api/2/issue", endpoint) uri := URLJoin(endpoint, "rest/api/2/issue")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded)) resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil { if err != nil {
return nil, err return nil, err
@@ -217,7 +219,8 @@ func (j *Jira) GetIssueCreateMetaProject(projectKey string) (*jiradata.CreateMet
} }
func GetIssueCreateMetaProject(ua HttpClient, endpoint string, projectKey string) (*jiradata.CreateMetaProject, error) { func GetIssueCreateMetaProject(ua HttpClient, endpoint string, projectKey string) (*jiradata.CreateMetaProject, error) {
uri := fmt.Sprintf("%s/rest/api/2/issue/createmeta?projectKeys=%s&expand=projects.issuetypes.fields", endpoint, projectKey) uri := URLJoin(endpoint, "rest/api/2/issue/createmeta")
uri += fmt.Sprintf("?projectKeys=%s&expand=projects.issuetypes.fields", projectKey)
resp, err := ua.GetJSON(uri) resp, err := ua.GetJSON(uri)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -246,7 +249,8 @@ func (j *Jira) GetIssueCreateMetaIssueType(projectKey, issueTypeName string) (*j
} }
func GetIssueCreateMetaIssueType(ua HttpClient, endpoint string, projectKey, issueTypeName string) (*jiradata.IssueType, error) { func GetIssueCreateMetaIssueType(ua HttpClient, endpoint string, projectKey, issueTypeName string) (*jiradata.IssueType, error) {
uri := fmt.Sprintf("%s/rest/api/2/issue/createmeta?projectKeys=%s&issuetypeNames=%s&expand=projects.issuetypes.fields", endpoint, projectKey, url.QueryEscape(issueTypeName)) uri := URLJoin(endpoint, "rest/api/2/issue/createmeta")
uri += fmt.Sprintf("?projectKeys=%s&issuetypeNames=%s&expand=projects.issuetypes.fields", projectKey, url.QueryEscape(issueTypeName))
resp, err := ua.GetJSON(uri) resp, err := ua.GetJSON(uri)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -288,7 +292,7 @@ func LinkIssues(ua HttpClient, endpoint string, lip LinkIssueProvider) error {
if err != nil { if err != nil {
return err return err
} }
uri := fmt.Sprintf("%s/rest/api/2/issueLink", endpoint) uri := URLJoin(endpoint, "rest/api/2/issueLink")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded)) resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil { if err != nil {
return err return err
@@ -307,7 +311,8 @@ func (j *Jira) GetIssueTransitions(issue string) (*jiradata.TransitionsMeta, err
} }
func GetIssueTransitions(ua HttpClient, endpoint string, issue string) (*jiradata.TransitionsMeta, error) { func GetIssueTransitions(ua HttpClient, endpoint string, issue string) (*jiradata.TransitionsMeta, error) {
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/transitions?expand=transitions.fields", endpoint, issue) uri := URLJoin(endpoint, "rest/api/2/issue", issue, "transitions")
uri += "?expand=transitions.fields"
resp, err := ua.GetJSON(uri) resp, err := ua.GetJSON(uri)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -332,7 +337,7 @@ func TransitionIssue(ua HttpClient, endpoint string, issue string, iup IssueUpda
if err != nil { if err != nil {
return err return err
} }
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/transitions", endpoint, issue) uri := URLJoin(endpoint, "rest/api/2/issue", issue, "transitions")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded)) resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil { if err != nil {
return err return err
@@ -351,7 +356,7 @@ func (j *Jira) GetIssueLinkTypes() (*jiradata.IssueLinkTypes, error) {
} }
func GetIssueLinkTypes(ua HttpClient, endpoint string) (*jiradata.IssueLinkTypes, error) { func GetIssueLinkTypes(ua HttpClient, endpoint string) (*jiradata.IssueLinkTypes, error) {
uri := fmt.Sprintf("%s/rest/api/2/issueLinkType", endpoint) uri := URLJoin(endpoint, "rest/api/2/issueLinkType")
resp, err := ua.GetJSON(uri) resp, err := ua.GetJSON(uri)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -375,7 +380,7 @@ func (j *Jira) IssueAddVote(issue string) error {
} }
func IssueAddVote(ua HttpClient, endpoint string, issue string) error { func IssueAddVote(ua HttpClient, endpoint string, issue string) error {
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/votes", endpoint, issue) uri := URLJoin(endpoint, "rest/api/2/issue", issue, "votes")
resp, err := ua.Post(uri, "application/json", strings.NewReader("{}")) resp, err := ua.Post(uri, "application/json", strings.NewReader("{}"))
if err != nil { if err != nil {
return err return err
@@ -394,7 +399,7 @@ func (j *Jira) IssueRemoveVote(issue string) error {
} }
func IssueRemoveVote(ua HttpClient, endpoint string, issue string) error { func IssueRemoveVote(ua HttpClient, endpoint string, issue string) error {
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/votes", endpoint, issue) uri := URLJoin(endpoint, "rest/api/2/issue", issue, "votes")
resp, err := ua.Delete(uri) resp, err := ua.Delete(uri)
if err != nil { if err != nil {
return err return err
@@ -422,7 +427,7 @@ func RankIssues(ua HttpClient, endpoint string, rrp RankRequestProvider) error {
if err != nil { if err != nil {
return err return err
} }
uri := fmt.Sprintf("%s/rest/agile/1.0/issue/rank", endpoint) uri := URLJoin(endpoint, "rest/agile/1.0/issue/rank")
resp, err := ua.Put(uri, "application/json", bytes.NewBuffer(encoded)) resp, err := ua.Put(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil { if err != nil {
return err return err
@@ -441,7 +446,7 @@ func (j *Jira) IssueAddWatcher(issue, user string) error {
} }
func IssueAddWatcher(ua HttpClient, endpoint string, issue, user string) error { func IssueAddWatcher(ua HttpClient, endpoint string, issue, user string) error {
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/watchers", endpoint, issue) uri := URLJoin(endpoint, "rest/api/2/issue", issue, "watchers")
resp, err := ua.Post(uri, "application/json", strings.NewReader(fmt.Sprintf("%q", user))) resp, err := ua.Post(uri, "application/json", strings.NewReader(fmt.Sprintf("%q", user)))
if err != nil { if err != nil {
return err return err
@@ -460,7 +465,8 @@ func (j *Jira) IssueRemoveWatcher(issue, user string) error {
} }
func IssueRemoveWatcher(ua HttpClient, endpoint string, issue, user string) error { func IssueRemoveWatcher(ua HttpClient, endpoint string, issue, user string) error {
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/watchers?username=%s", endpoint, issue, user) uri := URLJoin(endpoint, "rest/api/2/issue", issue, "watchers")
uri += fmt.Sprintf("?username=%s", user)
resp, err := ua.Delete(uri) resp, err := ua.Delete(uri)
if err != nil { if err != nil {
return err return err
@@ -488,7 +494,7 @@ func IssueAddComment(ua HttpClient, endpoint string, issue string, cp CommentPro
if err != nil { if err != nil {
return nil, err return nil, err
} }
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/comment", endpoint, issue) uri := URLJoin(endpoint, "rest/api/2/issue", issue, "comment")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded)) resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil { if err != nil {
return nil, err return nil, err
@@ -526,7 +532,7 @@ func IssueAssign(ua HttpClient, endpoint string, issue, name string) error {
if err != nil { if err != nil {
return err return err
} }
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/assignee", endpoint, issue) uri := URLJoin(endpoint, "rest/api/2/issue", issue, "assignee")
resp, err := ua.Put(uri, "application/json", bytes.NewBuffer(encoded)) resp, err := ua.Put(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil { if err != nil {
return err return err
@@ -556,7 +562,7 @@ func IssueAttachFile(ua HttpClient, endpoint string, issue, filename string, con
return nil, err return nil, err
} }
uri, err := url.Parse(fmt.Sprintf("%s/rest/api/2/issue/%s/attachments", endpoint, issue)) uri, err := url.Parse(URLJoin(endpoint, "rest/api/2/issue", issue, "attachments"))
req := oreo.RequestBuilder(uri).WithMethod("POST").WithHeader( req := oreo.RequestBuilder(uri).WithMethod("POST").WithHeader(
"X-Atlassian-Token", "no-check", "X-Atlassian-Token", "no-check",
).WithHeader( ).WithHeader(
+1 -1
View File
@@ -7,7 +7,7 @@ import (
var log = logging.MustGetLogger("jira") var log = logging.MustGetLogger("jira")
const VERSION = "1.0.15" const VERSION = "1.0.17"
type Jira struct { type Jira struct {
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"` Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
+4
View File
@@ -33,6 +33,7 @@ type GlobalOptions struct {
Insecure figtree.BoolOption `yaml:"insecure,omitempty" json:"insecure,omitempty"` Insecure figtree.BoolOption `yaml:"insecure,omitempty" json:"insecure,omitempty"`
Login figtree.StringOption `yaml:"login,omitempty" json:"login,omitempty"` Login figtree.StringOption `yaml:"login,omitempty" json:"login,omitempty"`
PasswordSource figtree.StringOption `yaml:"password-source,omitempty" json:"password-source,omitempty"` PasswordSource figtree.StringOption `yaml:"password-source,omitempty" json:"password-source,omitempty"`
PasswordDirectory figtree.StringOption `yaml:"password-directory,omitempty" json:"password-directory,omitempty"`
Quiet figtree.BoolOption `yaml:"quiet,omitempty" json:"quiet,omitempty"` Quiet figtree.BoolOption `yaml:"quiet,omitempty" json:"quiet,omitempty"`
SocksProxy figtree.StringOption `yaml:"socksproxy,omitempty" json:"socksproxy,omitempty"` SocksProxy figtree.StringOption `yaml:"socksproxy,omitempty" json:"socksproxy,omitempty"`
UnixProxy figtree.StringOption `yaml:"unixproxy,omitempty" json:"unixproxy,omitempty"` UnixProxy figtree.StringOption `yaml:"unixproxy,omitempty" json:"unixproxy,omitempty"`
@@ -122,6 +123,9 @@ func register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree) {
// rerun the original request // rerun the original request
return o.Do(req) return o.Do(req)
} }
} else if globals.AuthMethod() == "api-token" && resp.StatusCode == 401 {
globals.SetPass("")
return o.Do(req)
} }
return resp, nil return resp, nil
}, },
+10
View File
@@ -40,6 +40,11 @@ func (o *GlobalOptions) GetPass() string {
panic(err) panic(err)
} }
} else if o.PasswordSource.Value == "pass" { } else if o.PasswordSource.Value == "pass" {
if o.PasswordDirectory.Value != "" {
orig := os.Getenv("PASSWORD_STORE_DIR")
os.Setenv("PASSWORD_STORE_DIR", o.PasswordDirectory.Value)
defer os.Setenv("PASSWORD_STORE_DIR", orig)
}
if bin, err := exec.LookPath("pass"); err == nil { if bin, err := exec.LookPath("pass"); err == nil {
buf := bytes.NewBufferString("") buf := bytes.NewBufferString("")
cmd := exec.Command(bin, o.keyName()) cmd := exec.Command(bin, o.keyName())
@@ -95,6 +100,11 @@ func (o *GlobalOptions) SetPass(passwd string) error {
return err return err
} }
} else if o.PasswordSource.Value == "pass" { } else if o.PasswordSource.Value == "pass" {
if o.PasswordDirectory.Value != "" {
orig := os.Getenv("PASSWORD_STORE_DIR")
os.Setenv("PASSWORD_STORE_DIR", o.PasswordDirectory.Value)
defer os.Setenv("PASSWORD_STORE_DIR", orig)
}
if bin, err := exec.LookPath("pass"); err == nil { if bin, err := exec.LookPath("pass"); err == nil {
log.Debugf("using %s", bin) log.Debugf("using %s", bin)
passName := o.keyName() passName := o.keyName()
+2 -2
View File
@@ -158,7 +158,7 @@ func TemplateProcessor() *template.Template {
return strings.Join(vals, sep) return strings.Join(vals, sep)
}, },
"abbrev": func(max int, content string) string { "abbrev": func(max int, content string) string {
if len(content) > max { if len(content) > max && max > 2 {
var buffer bytes.Buffer var buffer bytes.Buffer
buffer.WriteString(content[:max-3]) buffer.WriteString(content[:max-3])
buffer.WriteString("...") buffer.WriteString("...")
@@ -290,7 +290,7 @@ const defaultTableTemplate = `{{/* table template */ -}}
| {{ "Issue" | printf "%-14s" }} | {{ "Summary" | printf (printf "%%-%ds" (sub $w 2)) }} | {{ "Type" | printf "%-12s"}} | {{ "Priority" | printf "%-12s" }} | {{ "Status" | printf "%-12s" }} | {{ "Age" | printf "%-10s" }} | {{ "Reporter" | printf "%-12s" }} | {{ "Assignee" | printf "%-12s" }} | | {{ "Issue" | printf "%-14s" }} | {{ "Summary" | printf (printf "%%-%ds" (sub $w 2)) }} | {{ "Type" | printf "%-12s"}} | {{ "Priority" | printf "%-12s" }} | {{ "Status" | printf "%-12s" }} | {{ "Age" | printf "%-10s" }} | {{ "Reporter" | printf "%-12s" }} | {{ "Assignee" | printf "%-12s" }} |
+{{ "-" | rep 16 }}+{{ "-" | rep $w }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 12 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+ +{{ "-" | rep 16 }}+{{ "-" | rep $w }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 12 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+
{{ range .issues -}} {{ range .issues -}}
| {{ .key | printf "%-14s"}} | {{ .fields.summary | abbrev (sub $w 2) | printf (printf "%%-%ds" (sub $w 2)) }} | {{.fields.issuetype.name | printf "%-12s" }} | {{.fields.priority.name | printf "%-12s" }} | {{.fields.status.name | printf "%-12s" }} | {{.fields.created | age | printf "%-10s" }} | {{if .fields.reporter}}{{ .fields.reporter.name | printf "%-12s"}}{{else}}<unassigned>{{end}} | {{if .fields.assignee }}{{.fields.assignee.name | printf "%-12s" }}{{else}}<unassigned>{{end}} | | {{ .key | printf "%-14s"}} | {{ .fields.summary | abbrev (sub $w 2) | printf (printf "%%-%ds" (sub $w 2)) }} | {{.fields.issuetype.name | printf "%-12s" }} | {{if .fields.priority}}{{.fields.priority.name | printf "%-12s" }}{{else}}<unassigned>{{end}} | {{.fields.status.name | printf "%-12s" }} | {{.fields.created | age | printf "%-10s" }} | {{if .fields.reporter}}{{ .fields.reporter.name | printf "%-12s"}}{{else}}<unassigned>{{end}} | {{if .fields.assignee }}{{.fields.assignee.name | printf "%-12s" }}{{else}}<unassigned>{{end}} |
{{ end -}} {{ end -}}
+{{ "-" | rep 16 }}+{{ "-" | rep $w }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 12 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+ +{{ "-" | rep 16 }}+{{ "-" | rep $w }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 12 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+
` `
+2 -1
View File
@@ -103,7 +103,8 @@ Commands:
func CommandLine(fig *figtree.FigTree, o *oreo.Client) *kingpin.Application { func CommandLine(fig *figtree.FigTree, o *oreo.Client) *kingpin.Application {
app := kingpin.New("jira", "Jira Command Line Interface") app := kingpin.New("jira", "Jira Command Line Interface")
app.UsageWriter(os.Stdout)
app.ErrorWriter(os.Stderr)
app.Command("version", "Prints version").PreAction(func(*kingpin.ParseContext) error { app.Command("version", "Prints version").PreAction(func(*kingpin.ParseContext) error {
fmt.Println(jira.VERSION) fmt.Println(jira.VERSION)
panic(Exit{Code: 0}) panic(Exit{Code: 0})
+2 -1
View File
@@ -6,6 +6,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath"
"runtime" "runtime"
"time" "time"
@@ -30,7 +31,7 @@ func findClosestParentPath(fileName string) (string, error) {
} }
func tmpYml(tmpFilePrefix string) (*os.File, error) { func tmpYml(tmpFilePrefix string) (*os.File, error) {
fh, err := ioutil.TempFile("", tmpFilePrefix) fh, err := ioutil.TempFile("", filepath.Base(tmpFilePrefix))
if err != nil { if err != nil {
return nil, err return nil, err
} }
+1 -1
View File
@@ -52,7 +52,7 @@ func CmdAssign(o *oreo.Client, globals *jiracli.GlobalOptions, opts *AssignOptio
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue) fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
} }
if opts.Browse.Value { if opts.Browse.Value {
+2 -2
View File
@@ -66,8 +66,8 @@ func CmdBlock(o *oreo.Client, globals *jiracli.GlobalOptions, opts *BlockOptions
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, globals.Endpoint.Value, opts.InwardIssue.Key) fmt.Printf("OK %s %s\n", opts.InwardIssue.Key, jira.URLJoin(globals.Endpoint.Value, "browse", opts.InwardIssue.Key))
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, globals.Endpoint.Value, opts.OutwardIssue.Key) fmt.Printf("OK %s %s\n", opts.OutwardIssue.Key, jira.URLJoin(globals.Endpoint.Value, "browse", opts.OutwardIssue.Key))
} }
if opts.Browse.Value { if opts.Browse.Value {
+2 -3
View File
@@ -1,11 +1,10 @@
package jiracmd package jiracmd
import ( import (
"fmt"
"github.com/coryb/figtree" "github.com/coryb/figtree"
"github.com/coryb/oreo" "github.com/coryb/oreo"
"github.com/pkg/browser" "github.com/pkg/browser"
jira "gopkg.in/Netflix-Skunkworks/go-jira.v1"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
kingpin "gopkg.in/alecthomas/kingpin.v2" kingpin "gopkg.in/alecthomas/kingpin.v2"
) )
@@ -27,5 +26,5 @@ func CmdBrowseRegistry() *jiracli.CommandRegistryEntry {
// CmdBrowse open the default system browser to the provided issue // CmdBrowse open the default system browser to the provided issue
func CmdBrowse(globals *jiracli.GlobalOptions, issue string) error { func CmdBrowse(globals *jiracli.GlobalOptions, issue string) error {
return browser.OpenURL(fmt.Sprintf("%s/browse/%s", globals.Endpoint.Value, issue)) return browser.OpenURL(jira.URLJoin(globals.Endpoint.Value, "browse", issue))
} }
+1 -1
View File
@@ -68,7 +68,7 @@ func CmdComment(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CommentOpt
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue) fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
} }
if opts.Browse.Value { if opts.Browse.Value {
+3 -2
View File
@@ -93,8 +93,9 @@ func CmdCreate(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CreateOptio
return err return err
} }
browseLink := jira.URLJoin(globals.Endpoint.Value, "browse", issueResp.Key)
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", issueResp.Key, globals.Endpoint.Value, issueResp.Key) fmt.Printf("OK %s %s\n", issueResp.Key, browseLink)
} }
if opts.SaveFile != "" { if opts.SaveFile != "" {
@@ -105,7 +106,7 @@ func CmdCreate(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CreateOptio
defer fh.Close() defer fh.Close()
out, err := yaml.Marshal(map[string]string{ out, err := yaml.Marshal(map[string]string{
"issue": issueResp.Key, "issue": issueResp.Key,
"link": fmt.Sprintf("%s/browse/%s", globals.Endpoint.Value, issueResp.Key), "link": browseLink,
}) })
if err != nil { if err != nil {
return err return err
+2 -2
View File
@@ -67,7 +67,7 @@ func CmdDup(o *oreo.Client, globals *jiracli.GlobalOptions, opts *DupOptions) er
return err return err
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, globals.Endpoint.Value, opts.OutwardIssue.Key) fmt.Printf("OK %s %s\n", opts.OutwardIssue.Key, jira.URLJoin(globals.Endpoint.Value, "browse", opts.OutwardIssue.Key))
} }
meta, err := jira.GetIssueTransitions(o, globals.Endpoint.Value, opts.InwardIssue.Key) meta, err := jira.GetIssueTransitions(o, globals.Endpoint.Value, opts.InwardIssue.Key)
@@ -103,7 +103,7 @@ func CmdDup(o *oreo.Client, globals *jiracli.GlobalOptions, opts *DupOptions) er
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, globals.Endpoint.Value, opts.InwardIssue.Key) fmt.Printf("OK %s %s\n", opts.InwardIssue.Key, jira.URLJoin(globals.Endpoint.Value, "browse", opts.InwardIssue.Key))
} }
if opts.Browse.Value { if opts.Browse.Value {
+2 -2
View File
@@ -98,7 +98,7 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions)
return err return err
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue) fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
} }
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue) return CmdBrowse(globals, opts.Issue)
@@ -145,7 +145,7 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions)
return err return err
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", issueData.Key, globals.Endpoint.Value, issueData.Key) fmt.Printf("OK %s %s\n", issueData.Key, jira.URLJoin(globals.Endpoint.Value, "browse", issueData.Key))
} }
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, issueData.Key) return CmdBrowse(globals, issueData.Key)
+2 -2
View File
@@ -44,9 +44,9 @@ func CmdEpicAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EpicAddOpt
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Epic, globals.Endpoint.Value, opts.Epic) fmt.Printf("OK %s %s\n", opts.Epic, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Epic))
for _, issue := range opts.Issues { for _, issue := range opts.Issues {
fmt.Printf("OK %s %s/browse/%s\n", issue, globals.Endpoint.Value, issue) fmt.Printf("OK %s %s\n", issue, jira.URLJoin(globals.Endpoint.Value, "browse", issue))
} }
} }
+1 -1
View File
@@ -43,7 +43,7 @@ func CmdEpicRemove(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EpicRem
if !globals.Quiet.Value { if !globals.Quiet.Value {
for _, issue := range opts.Issues { for _, issue := range opts.Issues {
fmt.Printf("OK %s %s/browse/%s\n", issue, globals.Endpoint.Value, issue) fmt.Printf("OK %s %s\n", issue, jira.URLJoin(globals.Endpoint.Value, "browse", issue))
} }
} }
+2 -2
View File
@@ -62,8 +62,8 @@ func CmdIssueLink(o *oreo.Client, globals *jiracli.GlobalOptions, opts *IssueLin
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, globals.Endpoint.Value, opts.InwardIssue.Key) fmt.Printf("OK %s %s\n", opts.InwardIssue.Key, jira.URLJoin(globals.Endpoint.Value, "browse", opts.InwardIssue.Key))
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, globals.Endpoint.Value, opts.OutwardIssue.Key) fmt.Printf("OK %s %s\n", opts.OutwardIssue.Key, jira.URLJoin(globals.Endpoint.Value, "browse", opts.OutwardIssue.Key))
} }
if opts.Browse.Value { if opts.Browse.Value {
+1 -1
View File
@@ -57,7 +57,7 @@ func CmdLabelsAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *LabelsAd
return err return err
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue) fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
} }
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue) return CmdBrowse(globals, opts.Issue)
+1 -1
View File
@@ -58,7 +58,7 @@ func CmdLabelsRemove(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Label
return err return err
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue) fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
} }
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue) return CmdBrowse(globals, opts.Issue)
+1 -1
View File
@@ -55,7 +55,7 @@ func CmdLabelsSet(o *oreo.Client, globals *jiracli.GlobalOptions, opts *LabelsSe
return err return err
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue) fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
} }
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue) return CmdBrowse(globals, opts.Issue)
+21
View File
@@ -2,10 +2,13 @@ package jiracmd
import ( import (
"fmt" "fmt"
"os"
"github.com/coryb/figtree" "github.com/coryb/figtree"
"github.com/coryb/oreo" "github.com/coryb/oreo"
"github.com/mgutz/ansi" "github.com/mgutz/ansi"
"golang.org/x/crypto/ssh/terminal"
survey "gopkg.in/AlecAivazis/survey.v1"
"gopkg.in/Netflix-Skunkworks/go-jira.v1" "gopkg.in/Netflix-Skunkworks/go-jira.v1"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli" "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
kingpin "gopkg.in/alecthomas/kingpin.v2" kingpin "gopkg.in/alecthomas/kingpin.v2"
@@ -29,6 +32,24 @@ func CmdLogoutRegistry() *jiracli.CommandRegistryEntry {
func CmdLogout(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.CommonOptions) error { func CmdLogout(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.CommonOptions) error {
if globals.AuthMethod() == "api-token" { if globals.AuthMethod() == "api-token" {
log.Noticef("No need to logout when using api-token authentication method") log.Noticef("No need to logout when using api-token authentication method")
if globals.GetPass() != "" && terminal.IsTerminal(int(os.Stdin.Fd())) && terminal.IsTerminal(int(os.Stdout.Fd())) {
delete := false
err := survey.AskOne(
&survey.Confirm{
Message: fmt.Sprintf("Delete api-token from password provider [%s]: ", globals.PasswordSource),
Default: false,
},
&delete,
nil,
)
if err != nil {
log.Errorf("%s", err)
panic(jiracli.Exit{Code: 1})
}
if delete {
globals.SetPass("")
}
}
return nil return nil
} }
ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks() ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks()
+2 -2
View File
@@ -59,8 +59,8 @@ func CmdRank(o *oreo.Client, globals *jiracli.GlobalOptions, opts *RankOptions)
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.First, globals.Endpoint.Value, opts.First) fmt.Printf("OK %s %s\n", opts.First, jira.URLJoin(globals.Endpoint.Value, "browse", opts.First))
fmt.Printf("OK %s %s/browse/%s\n", opts.Second, globals.Endpoint.Value, opts.Second) fmt.Printf("OK %s %s\n", opts.Second, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Second))
} }
if opts.Browse.Value { if opts.Browse.Value {
+1 -1
View File
@@ -108,7 +108,7 @@ func CmdSubtask(o *oreo.Client, globals *jiracli.GlobalOptions, opts *SubtaskOpt
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", issueResp.Key, globals.Endpoint.Value, issueResp.Key) fmt.Printf("OK %s %s\n", issueResp.Key, jira.URLJoin(globals.Endpoint.Value, "browse", issueResp.Key))
} }
if opts.Browse.Value { if opts.Browse.Value {
+1 -1
View File
@@ -157,7 +157,7 @@ func CmdTransition(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Transit
return jiracli.CliError(err) return jiracli.CliError(err)
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", issueData.Key, globals.Endpoint.Value, issueData.Key) fmt.Printf("OK %s %s\n", issueData.Key, jira.URLJoin(globals.Endpoint.Value, "browse", issueData.Key))
} }
if opts.Browse.Value { if opts.Browse.Value {
+1 -1
View File
@@ -64,7 +64,7 @@ func CmdVote(o *oreo.Client, globals *jiracli.GlobalOptions, opts *VoteOptions)
} }
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue) fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
} }
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue) return CmdBrowse(globals, opts.Issue)
+1 -1
View File
@@ -71,7 +71,7 @@ func CmdWatch(o *oreo.Client, globals *jiracli.GlobalOptions, opts *WatchOptions
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue) fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
} }
if opts.Browse.Value { if opts.Browse.Value {
+1 -1
View File
@@ -59,7 +59,7 @@ func CmdWorklogAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Worklog
return err return err
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue) fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
} }
if opts.Browse.Value { if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue) return CmdBrowse(globals, opts.Issue)
+1 -3
View File
@@ -1,8 +1,6 @@
package jira package jira
import ( import (
"fmt"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata" "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
) )
@@ -12,7 +10,7 @@ func (j *Jira) GetProjectComponents(project string) (*jiradata.Components, error
} }
func GetProjectComponents(ua HttpClient, endpoint string, project string) (*jiradata.Components, error) { func GetProjectComponents(ua HttpClient, endpoint string, project string) (*jiradata.Components, error) {
uri := fmt.Sprintf("%s/rest/api/2/project/%s/components", endpoint, project) uri := URLJoin(endpoint, "rest/api/2/project", project, "components")
resp, err := ua.GetJSON(uri) resp, err := ua.GetJSON(uri)
if err != nil { if err != nil {
return nil, err return nil, err
+1 -1
View File
@@ -83,7 +83,7 @@ func Search(ua HttpClient, endpoint string, sp SearchProvider) (*jiradata.Search
if err != nil { if err != nil {
return nil, err return nil, err
} }
uri := fmt.Sprintf("%s/rest/api/2/search", endpoint) uri := URLJoin(endpoint, "rest/api/2/search")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded)) resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil { if err != nil {
return nil, err return nil, err
+3 -4
View File
@@ -3,7 +3,6 @@ package jira
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata" "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
) )
@@ -35,7 +34,7 @@ func NewSession(ua HttpClient, endpoint string, ap AuthProvider) (*jiradata.Auth
if err != nil { if err != nil {
return nil, err return nil, err
} }
uri := fmt.Sprintf("%s/rest/auth/1/session", endpoint) uri := URLJoin(endpoint, "rest/auth/1/session")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded)) resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil { if err != nil {
return nil, err return nil, err
@@ -55,7 +54,7 @@ func (j *Jira) GetSession() (*jiradata.CurrentUser, error) {
} }
func GetSession(ua HttpClient, endpoint string) (*jiradata.CurrentUser, error) { func GetSession(ua HttpClient, endpoint string) (*jiradata.CurrentUser, error) {
uri := fmt.Sprintf("%s/rest/auth/1/session", endpoint) uri := URLJoin(endpoint, "rest/auth/1/session")
resp, err := ua.GetJSON(uri) resp, err := ua.GetJSON(uri)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -75,7 +74,7 @@ func (j *Jira) DeleteSession() error {
} }
func DeleteSession(ua HttpClient, endpoint string) error { func DeleteSession(ua HttpClient, endpoint string) error {
uri := fmt.Sprintf("%s/rest/auth/1/session", endpoint) uri := URLJoin(endpoint, "rest/auth/1/session")
resp, err := ua.Delete(uri) resp, err := ua.Delete(uri)
if err != nil { if err != nil {
return err return err
+12
View File
@@ -5,6 +5,8 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"net/url"
"path"
) )
func readJSON(input io.Reader, data interface{}) error { func readJSON(input io.Reader, data interface{}) error {
@@ -21,3 +23,13 @@ func readJSON(input io.Reader, data interface{}) error {
} }
return nil return nil
} }
func URLJoin(endpoint string, paths ...string) string {
u, err := url.Parse(endpoint)
if err != nil {
panic(fmt.Errorf("Unable to parse endpoint: %s", endpoint))
}
paths = append([]string{u.Path}, paths...)
u.Path = path.Join(paths...)
return u.String()
}