mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-19 20:53:27 +02:00
Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b98da3612d | |||
| 7f9595cf15 | |||
| 09584981b6 | |||
| 1bc6b55b85 | |||
| d787ac030c | |||
| 09a61c3ea1 | |||
| 64ce3812a6 | |||
| 9146346e2f | |||
| e639cce9af | |||
| 06b26c9e00 | |||
| ac39f9ae1d | |||
| bd3cf994b8 | |||
| 91059b3578 | |||
| 4b9873b323 | |||
| cd106df78a | |||
| 50b5360cfe | |||
| 359bec2fdf | |||
| 79c83f6911 | |||
| 585382eaea | |||
| 9c818d427c | |||
| 8621d9e698 | |||
| 5610707c30 | |||
| 0b4e16a35d | |||
| 57bc97a378 | |||
| 2d02cf8132 | |||
| 18a687e78a | |||
| 5d058536d2 | |||
| d4153be0ec | |||
| edb06621f8 | |||
| 161a68920d | |||
| fd30bc1392 | |||
| 84f77be87c | |||
| dea794f037 | |||
| 43ebc846b1 | |||
| 0d7c1a7931 | |||
| 80325a5955 | |||
| 20a9666fcd | |||
| 4ae760f18f | |||
| 6da9974380 | |||
| 8c7ca383f6 | |||
| 425fa63d33 | |||
| 464742c9ba |
@@ -3,6 +3,7 @@ config:
|
||||
password-source: pass
|
||||
endpoint: https://go-jira.atlassian.net
|
||||
user: admin
|
||||
login: atlassian@corybennett.org
|
||||
|
||||
queries:
|
||||
todo: |
|
||||
|
||||
@@ -1,5 +1,31 @@
|
||||
# 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
|
||||
|
||||
* [[#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)]
|
||||
* refactor to simplify main [Cory Bennett] [[43ebc84](https://github.com/Netflix-Skunkworks/go-jira/commit/43ebc84)] [[0d7c1a7](https://github.com/Netflix-Skunkworks/go-jira/commit/0d7c1a7)]
|
||||
* [[#145](https://github.com/Netflix-Skunkworks/go-jira/issues/145)] fix to match AuthProvider interface [Cory Bennett] [[80325a5](https://github.com/Netflix-Skunkworks/go-jira/commit/80325a5)]
|
||||
* [[#141](https://github.com/Netflix-Skunkworks/go-jira/issues/141)] better handling in responseError for non-json error responses [Cory Bennett] [[20a9666](https://github.com/Netflix-Skunkworks/go-jira/commit/20a9666)]
|
||||
* Update unexportTemplates.go [GitHub] [[6da9974](https://github.com/Netflix-Skunkworks/go-jira/commit/6da9974)]
|
||||
* [[#139](https://github.com/Netflix-Skunkworks/go-jira/issues/139)] add shellquote and toMinJson template functions [Cory Bennett] [[8c7ca38](https://github.com/Netflix-Skunkworks/go-jira/commit/8c7ca38)]
|
||||
* [[#137](https://github.com/Netflix-Skunkworks/go-jira/issues/137)] update kingpeon dep to allow access to dynamic command structure [Cory Bennett] [[425fa63](https://github.com/Netflix-Skunkworks/go-jira/commit/425fa63)]
|
||||
* field name is "comment" not "comments" [Cory Bennett] [[464742c](https://github.com/Netflix-Skunkworks/go-jira/commit/464742c)]
|
||||
|
||||
## 1.0.14 - 2017-11-04
|
||||
|
||||
* [[#131](https://github.com/Netflix-Skunkworks/go-jira/issues/131)] fix parsing global options before command execution (allow unixproxy/socksproxy to be set in config.yml) [Cory Bennett] [[042bc48](https://github.com/Netflix-Skunkworks/go-jira/commit/042bc48)]
|
||||
|
||||
Generated
+1
-1
@@ -29,7 +29,7 @@
|
||||
branch = "master"
|
||||
name = "github.com/coryb/kingpeon"
|
||||
packages = ["."]
|
||||
revision = "64b561ae2d0f895b94719c486bed798f4236a4b3"
|
||||
revision = "9a669f143f2e7454e80064c47365d139420a3fff"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
NAME=jira
|
||||
GO?=go
|
||||
|
||||
OS=$(shell uname -s)
|
||||
ifeq ($(filter CYGWIN%,$(OS)),$(OS))
|
||||
@@ -20,17 +21,17 @@ CURVER ?= $(patsubst v%,%,$(shell [ -d .git ] && git describe --abbrev=0 --tags
|
||||
LDFLAGS:= -w
|
||||
|
||||
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:
|
||||
@go vet .
|
||||
@go vet ./jiracli
|
||||
@go vet ./jiracmd
|
||||
@go vet ./jiradata
|
||||
@go vet ./cmd/jira
|
||||
@$(GO) vet .
|
||||
@$(GO) vet ./jiracli
|
||||
@$(GO) vet ./jiracmd
|
||||
@$(GO) vet ./jiradata
|
||||
@$(GO) vet ./cmd/jira
|
||||
|
||||
lint:
|
||||
@go get github.com/golang/lint/golint
|
||||
@$(GO) get github.com/golang/lint/golint
|
||||
@golint .
|
||||
@golint ./jiracli
|
||||
@golint ./jiracmd
|
||||
@@ -38,10 +39,10 @@ lint:
|
||||
@golint ./cmd/jira
|
||||
|
||||
all:
|
||||
go get -u github.com/karalabe/xgo
|
||||
$(GO) get -u github.com/karalabe/xgo
|
||||
rm -rf 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:
|
||||
${MAKE} GOBIN=$$HOME/bin build
|
||||
|
||||
@@ -27,9 +27,11 @@
|
||||
* [Templates](#templates)
|
||||
* [Writing/Editing Templates](#writingediting-templates)
|
||||
* [Authentication](#authentication)
|
||||
* [user vs login](#user-vs-login)
|
||||
* [keyring password source](#keyring-password-source)
|
||||
* [pass password source](#pass-password-source)
|
||||
* [Usage](#usage)
|
||||
* [TAB completion](#setting-up-tab-completion)
|
||||
|
||||
# go-jira
|
||||
simple command line client for Atlassian's Jira service written in Go
|
||||
@@ -42,11 +44,23 @@ You can download one of the pre-built binaries for **go-jira** [here](https://gi
|
||||
|
||||
### Build
|
||||
|
||||
You can build and install with [Go](https://golang.org/dl/):
|
||||
You can build and install the official repository with [Go](https://golang.org/dl/):
|
||||
|
||||
```
|
||||
go get gopkg.in/Netflix-Skunkworks/go-jira.v1/cmd/jira
|
||||
```
|
||||
This will checkout this repository into `$GOPATH/src/gopkg.in/Netflix-Skunkworks/go-jira.v1`, build, and install it.
|
||||
|
||||
Because golang likes fully qualified import paths, forking and contributing can be a bit tricky.
|
||||
|
||||
If you want to tinker or hack on go-jira, the [easiest way to do so](http://code.openark.org/blog/development/forking-golang-repositories-on-github-and-managing-the-import-path) is to fork the repository and clone directly into the official path like this:
|
||||
|
||||
`git clone https://github.com/YOUR_USER_NAME_HERE/go-jira $GOPATH/src/gopkg.in/Netflix-Skunkworks/go-jira.v1`
|
||||
|
||||
From within that source dir you can build and install modifications from within that directory like:
|
||||
|
||||
`go install ./...`
|
||||
|
||||
|
||||
## v1 vs v0 changes
|
||||
|
||||
@@ -79,7 +93,7 @@ esac
|
||||
|
||||
###### **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:
|
||||
```
|
||||
```yaml
|
||||
custom-commands:
|
||||
- name: mine
|
||||
help: display issues assigned to me
|
||||
@@ -103,7 +117,7 @@ Flags:
|
||||
```
|
||||
|
||||
###### **Incompatible command changes**
|
||||
Unfortunately during the rewrite between v0 and v1 there were some changes necessary that broke backwards compatibility with existing commands. Specifically the `dups`, `blocks`, `add worklog` and `add|remove|set labels` commands have had the command word swapped around:
|
||||
Unfortunately during the rewrite between v0 and v1 there were some necessary changes that broke backwards compatibility with existing commands. Specifically the `dups`, `blocks`, `add worklog` and `add|remove|set labels` commands have had the command word swapped around:
|
||||
* `jira DUPLICATE dups ISSUE` => `jira dup DUPLICATE ISSUE`
|
||||
* `jira BLOCKER blocks ISSUE` => `jira block BLOCKER ISSUE`
|
||||
* `jira add worklog` => `jira worklog add`
|
||||
@@ -112,22 +126,19 @@ Unfortunately during the rewrite between v0 and v1 there were some changes neces
|
||||
* `jira set labels` => `jira labels set`
|
||||
|
||||
###### **Login process change**
|
||||
We have, once again, changed how login happens for Jira. When authenticating against Atlassian Cloud Jira [API Tokens are now required](https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-basic-auth-and-cookie-based-auth/). Please read [the Authentication section](#authentication) below for more information.
|
||||
|
||||
If you use a privately hosted Jira service, you can chose to use the API Token method or continue using the session login api. Please read [the Authentication section](#authentication) below for more information.
|
||||
|
||||
Previously `jira` used attempt to get a `JSESSION` cookies by authenticating with the webservice standard GUI login process. This has been especially problematic as users need to authenticate with various credential providers (google auth, etc). We now attempt to authenticate via the [session login api](https://docs.atlassian.com/jira/REST/cloud/#auth/1/session-login). This may be problematic for users if admins have locked down the session-login api, so we might have to bring back the error-prone Basic-Auth approach. For users that are unable to authenticate via `jira` hopefully someone in your organization can provide me with details on a process for you to authenticate and we can try to update `jira`.
|
||||
|
||||
## Configuration
|
||||
|
||||
**go-jira** uses a configuration hierarchy. When loading the configuration from disk it will recursively look through
|
||||
all parent directories in your current path looking for a **.jira.d** directory. If your current directory is not
|
||||
a child directory of your homedir, then your homedir will also be inspected for a **.jira.d** directory. From all of **.jira.d** directories
|
||||
discovered **go-jira** will load a **<command>.yml** file (ie for `jira list` it will load `.jira.d/list.yml`) then it will merge in any properties from the **config.yml** if found. The configuration properties found in a file closests to your current working directory
|
||||
will have precedence. Properties overriden with command line options will have final precedence.
|
||||
**go-jira** uses a configuration hierarchy. When loading the configuration from disk it will recursively look through all parent directories in your current path looking for a **.jira.d** directory. If your current directory is not a child directory of your homedir, then your homedir will also be inspected for a **.jira.d** directory. From all of **.jira.d** directories discovered **go-jira** will load a **<command>.yml** file (ie for `jira list` it will load `.jira.d/list.yml`) then it will merge in any properties from the **config.yml** if found. The configuration properties found in a file closests to your current working directory will have precedence. Properties overriden with command line options will have final precedence.
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
@@ -175,7 +186,7 @@ esac
|
||||
|
||||
### 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:
|
||||
```
|
||||
```yaml
|
||||
custom-commands:
|
||||
- command1
|
||||
- command2
|
||||
@@ -223,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.
|
||||
|
||||
To demonstrate how you might use args and options here is a `custom-test` command:
|
||||
```
|
||||
```yaml
|
||||
custom-commands:
|
||||
- name: custom-test
|
||||
help: Testing the custom commands
|
||||
@@ -274,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:
|
||||
```
|
||||
```yaml
|
||||
custom-commands:
|
||||
- name: env
|
||||
help: print the JIRA environment variables available to custom commands
|
||||
@@ -283,7 +294,7 @@ custom-commands:
|
||||
```
|
||||
|
||||
You could use the environment variables automatically, so if your `.jira.d/config.yml` looks something like this:
|
||||
```
|
||||
```yaml
|
||||
project: PROJECT
|
||||
custom-commands:
|
||||
- name: print-project
|
||||
@@ -294,7 +305,7 @@ custom-commands:
|
||||
##### Examples
|
||||
|
||||
* `jira mine` for listing issues assigned to you
|
||||
```
|
||||
```yaml
|
||||
custom-commands:
|
||||
- name: mine
|
||||
help: display issues assigned to me
|
||||
@@ -308,7 +319,7 @@ custom-commands:
|
||||
fi
|
||||
```
|
||||
* `jira sprint` for listing issues in your current sprint
|
||||
```
|
||||
```yaml
|
||||
custom-commands:
|
||||
- name: sprint
|
||||
help: display issues for active sprint
|
||||
@@ -358,7 +369,18 @@ jira list -t debug
|
||||
|
||||
### Authentication
|
||||
|
||||
By default `go-jira` will prompt for a password automatically when get a response header from the Jira service that indicates you do not have an active session (ie the `X-Ausername` header is set to `anonymous`). Then after authentication we cache the `cloud.session.token` cookie returned by the service [session login api](https://docs.atlassian.com/jira/REST/cloud/#auth/1/session-login) and reuse that on subsequent requests. Typically this cookie will be valid for several hours (depending on the service configuration). To automatically securely store your password for easy reuse by jira You can enable a `password-source` via `.jira.d/config.yml` with possible values of `keyring` or `pass`.
|
||||
For Atlassian Cloud hosted Jira [API Tokens are now required](https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-basic-auth-and-cookie-based-auth/). You will automatically be prompted for an API Token if your jira endoint ends in `.atlassian.net`. If you are using a private Jira service, you can force `jira` to use an api-token by setting the `authentication-method: api-token` property in your `$HOME/.jira.d/config.yml` file. The API Token needs to be presented to the Jira service on every request, so it is recommended to store this API Token security within your OS's keyring, or using the `pass` service as documented below so that it can be programatically accessed via `jira` and not prompt you every time. For a less-secure option you can also provide the API token via a `JIRA_API_TOKEN` environment variable. If you are unable to use an api-token for an Atlassian Cloud hosted Jira then you can still force `jira` to use the old session based authentication (until it the hosted system stops accepting it) by setting `authentication-method: session`.
|
||||
|
||||
If your Jira service still allows you to use the Session based authention method then `jira` will prompt for a password automatically when get a response header from the Jira service that indicates you do not have an active session (ie the `X-Ausername` header is set to `anonymous`). Then after authentication we cache the `cloud.session.token` cookie returned by the service [session login api](https://docs.atlassian.com/jira/REST/cloud/#auth/1/session-login) and reuse that on subsequent requests. Typically this cookie will be valid for several hours (depending on the service configuration). To automatically securely store your password for easy reuse by jira You can enable a `password-source` via `.jira.d/config.yml` with possible values of `keyring` or `pass`.
|
||||
|
||||
#### 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:
|
||||
```yaml
|
||||
user: person
|
||||
login: person@example.com
|
||||
```
|
||||
|
||||
You can also override these values on the command line with `jira --user person --login person@example.com`. The `login` value will be used only for authentication purposes, the `user` value will be used when a user name is required for any Jira service API calls.
|
||||
|
||||
#### keyring password source
|
||||
On OSX and Linux there are a few keyring providers that `go-jira` can use (via this [golang module](https://github.com/tmc/keyring)). To integrate `go-jira` with a supported keyring just add this configuration to `$HOME/.jira.d/config.yml`:
|
||||
@@ -422,6 +444,19 @@ export GPG_TTY=$(tty)
|
||||
|
||||
## 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> ...]
|
||||
|
||||
@@ -435,7 +470,8 @@ Global flags:
|
||||
-Q, --quiet Suppress output to console
|
||||
--unixproxy=UNIXPROXY Path for a unix-socket proxy
|
||||
--socksproxy=SOCKSPROXY Address for a socks proxy
|
||||
-u, --user=USER Login name used for authentication with Jira service
|
||||
-u, --user=USER user name used within the Jira service
|
||||
--login=LOGIN login name that corresponds to the user used for authentication
|
||||
|
||||
Commands:
|
||||
help: Show help.
|
||||
|
||||
+2
-4
@@ -1,8 +1,6 @@
|
||||
package jira
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"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) {
|
||||
uri := fmt.Sprintf("%s/rest/api/2/attachment/%s", endpoint, id)
|
||||
uri := URLJoin(endpoint, "rest/api/2/attachment", id)
|
||||
resp, err := ua.GetJSON(uri)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -32,7 +30,7 @@ func (j *Jira) RemoveAttachment(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)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
+5
-275
@@ -3,34 +3,19 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
"github.com/coryb/kingpeon"
|
||||
"github.com/coryb/oreo"
|
||||
|
||||
jira "gopkg.in/Netflix-Skunkworks/go-jira.v1"
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracmd"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
"gopkg.in/op/go-logging.v1"
|
||||
)
|
||||
|
||||
var (
|
||||
log = logging.MustGetLogger("jira")
|
||||
defaultFormat = func() string {
|
||||
format := os.Getenv("JIRA_LOG_FORMAT")
|
||||
if format != "" {
|
||||
return format
|
||||
}
|
||||
return "%{color}%{level:-5s}%{color:reset} %{message}"
|
||||
}()
|
||||
log = logging.MustGetLogger("jira")
|
||||
)
|
||||
|
||||
func handleExit() {
|
||||
@@ -44,138 +29,10 @@ func handleExit() {
|
||||
}
|
||||
}
|
||||
|
||||
func increaseLogLevel(verbosity int) {
|
||||
logging.SetLevel(logging.GetLevel("")+logging.Level(verbosity), "")
|
||||
if logging.GetLevel("") > logging.DEBUG {
|
||||
oreo.TraceRequestBody = true
|
||||
oreo.TraceResponseBody = true
|
||||
}
|
||||
}
|
||||
|
||||
var usage = `{{define "FormatCommand"}}\
|
||||
{{if .FlagSummary}} {{.FlagSummary}}{{end}}\
|
||||
{{range .Args}} {{if not .Required}}[{{end}}<{{.Name}}>{{if .Value|IsCumulative}}...{{end}}{{if not .Required}}]{{end}}{{end}}\
|
||||
{{end}}\
|
||||
|
||||
{{define "FormatBriefCommands"}}\
|
||||
{{range .FlattenedCommands}}\
|
||||
{{if not .Hidden}}\
|
||||
{{ print .FullCommand ":" | printf "%-20s"}} {{.Help}}
|
||||
{{end}}\
|
||||
{{end}}\
|
||||
{{end}}\
|
||||
|
||||
{{define "FormatCommands"}}\
|
||||
{{range .FlattenedCommands}}\
|
||||
{{if not .Hidden}}\
|
||||
{{.FullCommand}}{{if .Default}}*{{end}}{{template "FormatCommand" .}}
|
||||
{{.Help|Wrap 4}}
|
||||
{{with .Flags|FlagsToTwoColumns}}{{FormatTwoColumnsWithIndent . 4 2}}{{end}}
|
||||
{{end}}\
|
||||
{{end}}\
|
||||
{{end}}\
|
||||
|
||||
{{define "FormatUsage"}}\
|
||||
{{template "FormatCommand" .}}{{if .Commands}} <command> [<args> ...]{{end}}
|
||||
{{if .Help}}
|
||||
{{.Help|Wrap 0}}\
|
||||
{{end}}\
|
||||
|
||||
{{end}}\
|
||||
|
||||
{{if .Context.SelectedCommand}}\
|
||||
usage: {{.App.Name}} {{.Context.SelectedCommand}}{{template "FormatCommand" .Context.SelectedCommand}}
|
||||
{{if .Context.SelectedCommand.Aliases }}\
|
||||
{{range $top := .App.Commands}}\
|
||||
{{if eq $top.FullCommand $.Context.SelectedCommand.FullCommand}}\
|
||||
{{range $alias := $.Context.SelectedCommand.Aliases}}\
|
||||
alias: {{$.App.Name}} {{$alias}}{{template "FormatCommand" $.Context.SelectedCommand}}
|
||||
{{end}}\
|
||||
{{else}}\
|
||||
{{range $sub := $top.Commands}}\
|
||||
{{if eq $sub.FullCommand $.Context.SelectedCommand.FullCommand}}\
|
||||
{{range $alias := $.Context.SelectedCommand.Aliases}}\
|
||||
alias: {{$.App.Name}} {{$top.Name}} {{$alias}}{{template "FormatCommand" $.Context.SelectedCommand}}
|
||||
{{end}}\
|
||||
{{end}}\
|
||||
{{end}}\
|
||||
{{end}}\
|
||||
{{end}}\
|
||||
{{end}}
|
||||
{{if .Context.SelectedCommand.Help}}\
|
||||
{{.Context.SelectedCommand.Help|Wrap 0}}
|
||||
{{end}}\
|
||||
{{else}}\
|
||||
usage: {{.App.Name}}{{template "FormatUsage" .App}}
|
||||
{{end}}\
|
||||
|
||||
{{if .App.Flags}}\
|
||||
Global flags:
|
||||
{{.App.Flags|FlagsToTwoColumns|FormatTwoColumns}}
|
||||
{{end}}\
|
||||
{{if .Context.SelectedCommand}}\
|
||||
{{if and .Context.SelectedCommand.Flags|RequiredFlags}}\
|
||||
Required flags:
|
||||
{{.Context.SelectedCommand.Flags|RequiredFlags|FlagsToTwoColumns|FormatTwoColumns}}
|
||||
{{end}}\
|
||||
{{if .Context.SelectedCommand.Flags|OptionalFlags}}\
|
||||
Optional flags:
|
||||
{{.Context.SelectedCommand.Flags|OptionalFlags|FlagsToTwoColumns|FormatTwoColumns}}
|
||||
{{end}}\
|
||||
{{end}}\
|
||||
{{if .Context.Args}}\
|
||||
Args:
|
||||
{{.Context.Args|ArgsToTwoColumns|FormatTwoColumns}}
|
||||
{{end}}\
|
||||
{{if .Context.SelectedCommand}}\
|
||||
{{if .Context.SelectedCommand.Commands}}\
|
||||
Subcommands:
|
||||
{{template "FormatCommands" .Context.SelectedCommand}}
|
||||
{{end}}\
|
||||
{{else if .App.Commands}}\
|
||||
Commands:
|
||||
{{template "FormatBriefCommands" .App}}
|
||||
{{end}}\
|
||||
`
|
||||
|
||||
func main() {
|
||||
defer handleExit()
|
||||
logBackend := logging.NewLogBackend(os.Stderr, "", 0)
|
||||
format := os.Getenv("JIRA_LOG_FORMAT")
|
||||
if format == "" {
|
||||
format = defaultFormat
|
||||
}
|
||||
logging.SetBackend(
|
||||
logging.NewBackendFormatter(
|
||||
logBackend,
|
||||
logging.MustStringFormatter(format),
|
||||
),
|
||||
)
|
||||
if os.Getenv("JIRA_DEBUG") == "" {
|
||||
logging.SetLevel(logging.NOTICE, "")
|
||||
} else {
|
||||
logging.SetLevel(logging.DEBUG, "")
|
||||
}
|
||||
|
||||
app := kingpin.New("jira", "Jira Command Line Interface")
|
||||
app.Command("version", "Prints version").PreAction(func(*kingpin.ParseContext) error {
|
||||
fmt.Println(jira.VERSION)
|
||||
panic(jiracli.Exit{Code: 0})
|
||||
})
|
||||
app.UsageTemplate(usage)
|
||||
|
||||
var verbosity int
|
||||
app.Flag("verbose", "Increase verbosity for debugging").Short('v').PreAction(func(_ *kingpin.ParseContext) error {
|
||||
os.Setenv("JIRA_DEBUG", fmt.Sprintf("%d", verbosity))
|
||||
increaseLogLevel(1)
|
||||
return nil
|
||||
}).CounterVar(&verbosity)
|
||||
|
||||
if os.Getenv("JIRA_DEBUG") != "" {
|
||||
if verbosity, err := strconv.Atoi(os.Getenv("JIRA_DEBUG")); err == nil {
|
||||
increaseLogLevel(verbosity)
|
||||
}
|
||||
}
|
||||
jiracli.InitLogging()
|
||||
|
||||
fig := figtree.NewFigTree()
|
||||
fig.EnvPrefix = "JIRA"
|
||||
@@ -188,135 +45,8 @@ func main() {
|
||||
|
||||
o := oreo.New().WithCookieFile(filepath.Join(jiracli.Homedir(), fig.ConfigDir, "cookies.js"))
|
||||
|
||||
registry := []jiracli.CommandRegistry{
|
||||
{Command: "acknowledge", Entry: jiracmd.CmdTransitionRegistry("acknowledge"), Aliases: []string{"ack"}},
|
||||
{Command: "assign", Entry: jiracmd.CmdAssignRegistry(), Aliases: []string{"give"}},
|
||||
{Command: "attach create", Entry: jiracmd.CmdAttachCreateRegistry()},
|
||||
{Command: "attach get", Entry: jiracmd.CmdAttachGetRegistry()},
|
||||
{Command: "attach list", Entry: jiracmd.CmdAttachListRegistry(), Aliases: []string{"ls"}},
|
||||
{Command: "attach remove", Entry: jiracmd.CmdAttachRemoveRegistry(), Aliases: []string{"rm"}},
|
||||
{Command: "backlog", Entry: jiracmd.CmdTransitionRegistry("Backlog")},
|
||||
{Command: "block", Entry: jiracmd.CmdBlockRegistry()},
|
||||
{Command: "browse", Entry: jiracmd.CmdBrowseRegistry(), Aliases: []string{"b"}},
|
||||
{Command: "close", Entry: jiracmd.CmdTransitionRegistry("close")},
|
||||
{Command: "comment", Entry: jiracmd.CmdCommentRegistry()},
|
||||
{Command: "component add", Entry: jiracmd.CmdComponentAddRegistry()},
|
||||
{Command: "components", Entry: jiracmd.CmdComponentsRegistry()},
|
||||
{Command: "create", Entry: jiracmd.CmdCreateRegistry()},
|
||||
{Command: "createmeta", Entry: jiracmd.CmdCreateMetaRegistry()},
|
||||
{Command: "done", Entry: jiracmd.CmdTransitionRegistry("Done")},
|
||||
{Command: "dup", Entry: jiracmd.CmdDupRegistry()},
|
||||
{Command: "edit", Entry: jiracmd.CmdEditRegistry()},
|
||||
{Command: "editmeta", Entry: jiracmd.CmdEditMetaRegistry()},
|
||||
{Command: "epic add", Entry: jiracmd.CmdEpicAddRegistry()},
|
||||
{Command: "epic create", Entry: jiracmd.CmdEpicCreateRegistry()},
|
||||
{Command: "epic list", Entry: jiracmd.CmdEpicListRegistry(), Aliases: []string{"ls"}},
|
||||
{Command: "epic remove", Entry: jiracmd.CmdEpicRemoveRegistry(), Aliases: []string{"rm"}},
|
||||
{Command: "export-templates", Entry: jiracmd.CmdExportTemplatesRegistry()},
|
||||
{Command: "fields", Entry: jiracmd.CmdFieldsRegistry()},
|
||||
{Command: "in-progress", Entry: jiracmd.CmdTransitionRegistry("Progress"), Aliases: []string{"prog", "progress"}},
|
||||
{Command: "issuelink", Entry: jiracmd.CmdIssueLinkRegistry()},
|
||||
{Command: "issuelinktypes", Entry: jiracmd.CmdIssueLinkTypesRegistry()},
|
||||
{Command: "issuetypes", Entry: jiracmd.CmdIssueTypesRegistry()},
|
||||
{Command: "labels add", Entry: jiracmd.CmdLabelsAddRegistry()},
|
||||
{Command: "labels remove", Entry: jiracmd.CmdLabelsRemoveRegistry(), Aliases: []string{"rm"}},
|
||||
{Command: "labels set", Entry: jiracmd.CmdLabelsSetRegistry()},
|
||||
{Command: "list", Entry: jiracmd.CmdListRegistry(), Aliases: []string{"ls"}},
|
||||
{Command: "login", Entry: jiracmd.CmdLoginRegistry()},
|
||||
{Command: "logout", Entry: jiracmd.CmdLogoutRegistry()},
|
||||
{Command: "rank", Entry: jiracmd.CmdRankRegistry()},
|
||||
{Command: "reopen", Entry: jiracmd.CmdTransitionRegistry("reopen")},
|
||||
{Command: "request", Entry: jiracmd.CmdRequestRegistry(), Aliases: []string{"req"}},
|
||||
{Command: "resolve", Entry: jiracmd.CmdTransitionRegistry("resolve")},
|
||||
{Command: "start", Entry: jiracmd.CmdTransitionRegistry("start")},
|
||||
{Command: "stop", Entry: jiracmd.CmdTransitionRegistry("stop")},
|
||||
{Command: "subtask", Entry: jiracmd.CmdSubtaskRegistry()},
|
||||
{Command: "take", Entry: jiracmd.CmdTakeRegistry()},
|
||||
{Command: "todo", Entry: jiracmd.CmdTransitionRegistry("To Do")},
|
||||
{Command: "transition", Entry: jiracmd.CmdTransitionRegistry(""), Aliases: []string{"trans"}},
|
||||
{Command: "transitions", Entry: jiracmd.CmdTransitionsRegistry("transitions")},
|
||||
{Command: "transmeta", Entry: jiracmd.CmdTransitionsRegistry("debug")},
|
||||
{Command: "unassign", Entry: jiracmd.CmdUnassignRegistry()},
|
||||
{Command: "unexport-templates", Entry: jiracmd.CmdUnexportTemplatesRegistry()},
|
||||
{Command: "view", Entry: jiracmd.CmdViewRegistry()},
|
||||
{Command: "vote", Entry: jiracmd.CmdVoteRegistry()},
|
||||
{Command: "watch", Entry: jiracmd.CmdWatchRegistry()},
|
||||
{Command: "worklog add", Entry: jiracmd.CmdWorklogAddRegistry()},
|
||||
{Command: "worklog list", Entry: jiracmd.CmdWorklogListRegistry(), Default: true},
|
||||
}
|
||||
jiracmd.RegisterAllCommands()
|
||||
|
||||
jiracli.Register(app, o, fig, registry)
|
||||
|
||||
// register custom commands
|
||||
data := struct {
|
||||
CustomCommands kingpeon.DynamicCommands `yaml:"custom-commands" json:"custom-commands"`
|
||||
}{}
|
||||
|
||||
if err := fig.LoadAllConfigs("config.yml", &data); err != nil {
|
||||
log.Errorf("%s", err)
|
||||
panic(jiracli.Exit{Code: 1})
|
||||
}
|
||||
|
||||
if len(data.CustomCommands) > 0 {
|
||||
runner := syscall.Exec
|
||||
if runtime.GOOS == "windows" {
|
||||
runner = func(binary string, cmd []string, env []string) error {
|
||||
command := exec.Command(binary, cmd[1:]...)
|
||||
command.Stdin = os.Stdin
|
||||
command.Stdout = os.Stdout
|
||||
command.Stderr = os.Stderr
|
||||
command.Env = env
|
||||
return command.Run()
|
||||
}
|
||||
}
|
||||
|
||||
tmp := map[string]interface{}{}
|
||||
fig.LoadAllConfigs("config.yml", &tmp)
|
||||
kingpeon.RegisterDynamicCommandsWithRunner(runner, app, data.CustomCommands, jiracli.TemplateProcessor())
|
||||
}
|
||||
|
||||
app.Terminate(func(status int) {
|
||||
for _, arg := range os.Args {
|
||||
if arg == "-h" || arg == "--help" || len(os.Args) == 1 {
|
||||
panic(jiracli.Exit{Code: 0})
|
||||
}
|
||||
}
|
||||
panic(jiracli.Exit{Code: 1})
|
||||
})
|
||||
|
||||
// checking for default usage of `jira ISSUE-123` but need to allow
|
||||
// for global options first like: `jira --user mothra ISSUE-123`
|
||||
ctx, err := app.ParseContext(os.Args[1:])
|
||||
if err != nil && ctx == nil {
|
||||
// This is an internal kingpin usage error, duplicate options/commands
|
||||
log.Fatalf("error: %s, ctx: %v", err, ctx)
|
||||
}
|
||||
|
||||
if ctx != nil {
|
||||
if ctx.SelectedCommand == nil {
|
||||
next := ctx.Next()
|
||||
if next != nil {
|
||||
if ok, err := regexp.MatchString("^[A-Z]+-[0-9]+$", next.Value); err != nil {
|
||||
log.Errorf("Invalid Regex: %s", err)
|
||||
} else if ok {
|
||||
// insert "view" at i=1 (2nd position)
|
||||
os.Args = append(os.Args[:1], append([]string{"view"}, os.Args[1:]...)...)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := app.Parse(os.Args[1:]); err != nil {
|
||||
if _, ok := err.(*jiracli.Error); ok {
|
||||
log.Errorf("%s", err)
|
||||
panic(jiracli.Exit{Code: 1})
|
||||
} else {
|
||||
ctx, _ := app.ParseContext(os.Args[1:])
|
||||
if ctx != nil {
|
||||
app.UsageForContext(ctx)
|
||||
}
|
||||
log.Errorf("Invalid Usage: %s", err)
|
||||
panic(jiracli.Exit{Code: 1})
|
||||
}
|
||||
}
|
||||
app := jiracli.CommandLine(fig, o)
|
||||
jiracli.ParseCommandLine(app, os.Args[1:])
|
||||
}
|
||||
|
||||
+1
-2
@@ -3,7 +3,6 @@ package jira
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
||||
)
|
||||
@@ -23,7 +22,7 @@ func CreateComponent(ua HttpClient, endpoint string, cp ComponentProvider) (*jir
|
||||
if err != nil {
|
||||
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))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -23,7 +23,7 @@ func EpicSearch(ua HttpClient, endpoint string, epic string, sp SearchProvider)
|
||||
// if err != nil {
|
||||
// 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 {
|
||||
return nil, err
|
||||
}
|
||||
@@ -74,7 +74,7 @@ func EpicAddIssues(ua HttpClient, endpoint string, epic string, eip EpicIssuesPr
|
||||
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))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -99,7 +99,7 @@ func EpicRemoveIssues(ua HttpClient, endpoint string, eip EpicIssuesProvider) er
|
||||
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))
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package jira
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
||||
@@ -10,10 +9,12 @@ import (
|
||||
func responseError(resp *http.Response) error {
|
||||
results := &jiradata.ErrorCollection{}
|
||||
if err := readJSON(resp.Body, results); err != nil {
|
||||
return err
|
||||
results.Status = resp.StatusCode
|
||||
results.ErrorMessages = append(results.ErrorMessages, err.Error())
|
||||
}
|
||||
if len(results.ErrorMessages) == 0 && len(results.Errors) == 0 {
|
||||
return fmt.Errorf(resp.Status)
|
||||
results.Status = resp.StatusCode
|
||||
results.ErrorMessages = append(results.ErrorMessages, resp.Status)
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package jira
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"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) {
|
||||
uri := fmt.Sprintf("%s/rest/api/2/field", endpoint)
|
||||
uri := URLJoin(endpoint, "rest/api/2/field")
|
||||
resp, err := ua.GetJSON(uri)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -59,7 +59,8 @@ func GetIssue(ua HttpClient, endpoint string, issue string, iqg IssueQueryProvid
|
||||
if iqg != nil {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -84,7 +85,8 @@ func GetIssueWorklog(ua HttpClient, endpoint string, issue string) (*jiradata.Wo
|
||||
maxResults := 100
|
||||
worklogs := jiradata.Worklogs{}
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -124,7 +126,7 @@ func AddIssueWorklog(ua HttpClient, endpoint string, issue string, wp WorklogPro
|
||||
if err != nil {
|
||||
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))
|
||||
if err != nil {
|
||||
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) {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -173,7 +175,7 @@ func EditIssue(ua HttpClient, endpoint string, issue string, iup IssueUpdateProv
|
||||
if err != nil {
|
||||
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))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -197,7 +199,7 @@ func CreateIssue(ua HttpClient, endpoint string, iup IssueUpdateProvider) (*jira
|
||||
if err != nil {
|
||||
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))
|
||||
if err != nil {
|
||||
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) {
|
||||
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)
|
||||
if err != nil {
|
||||
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) {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -288,7 +292,7 @@ func LinkIssues(ua HttpClient, endpoint string, lip LinkIssueProvider) error {
|
||||
if err != nil {
|
||||
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))
|
||||
if err != nil {
|
||||
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) {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -332,7 +337,7 @@ func TransitionIssue(ua HttpClient, endpoint string, issue string, iup IssueUpda
|
||||
if err != nil {
|
||||
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))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -351,7 +356,7 @@ func (j *Jira) GetIssueLinkTypes() (*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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -375,7 +380,7 @@ func (j *Jira) IssueAddVote(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("{}"))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -394,7 +399,7 @@ func (j *Jira) IssueRemoveVote(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)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -422,7 +427,7 @@ func RankIssues(ua HttpClient, endpoint string, rrp RankRequestProvider) error {
|
||||
if err != nil {
|
||||
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))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -441,7 +446,7 @@ func (j *Jira) IssueAddWatcher(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)))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -460,7 +465,8 @@ func (j *Jira) IssueRemoveWatcher(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)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -488,7 +494,7 @@ func IssueAddComment(ua HttpClient, endpoint string, issue string, cp CommentPro
|
||||
if err != nil {
|
||||
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))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -526,7 +532,7 @@ func IssueAssign(ua HttpClient, endpoint string, issue, name string) error {
|
||||
if err != nil {
|
||||
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))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -556,7 +562,7 @@ func IssueAttachFile(ua HttpClient, endpoint string, issue, filename string, con
|
||||
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(
|
||||
"X-Atlassian-Token", "no-check",
|
||||
).WithHeader(
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
var log = logging.MustGetLogger("jira")
|
||||
|
||||
const VERSION = "1.0.14"
|
||||
const VERSION = "1.0.17"
|
||||
|
||||
type Jira struct {
|
||||
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
|
||||
|
||||
+64
-25
@@ -3,6 +3,7 @@ package jiracli
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -20,23 +21,23 @@ import (
|
||||
"gopkg.in/AlecAivazis/survey.v1"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
yaml "gopkg.in/coryb/yaml.v2"
|
||||
logging "gopkg.in/op/go-logging.v1"
|
||||
)
|
||||
|
||||
var log = logging.MustGetLogger("jira")
|
||||
|
||||
type Exit struct {
|
||||
Code int
|
||||
}
|
||||
|
||||
type GlobalOptions struct {
|
||||
Endpoint figtree.StringOption `yaml:"endpoint,omitempty" json:"endpoint,omitempty"`
|
||||
Insecure figtree.BoolOption `yaml:"insecure,omitempty" json:"insecure,omitempty"`
|
||||
PasswordSource figtree.StringOption `yaml:"password-source,omitempty" json:"password-source,omitempty"`
|
||||
Quiet figtree.BoolOption `yaml:"quiet,omitempty" json:"quiet,omitempty"`
|
||||
UnixProxy figtree.StringOption `yaml:"unixproxy,omitempty" json:"unixproxy,omitempty"`
|
||||
SocksProxy figtree.StringOption `yaml:"socksproxy,omitempty" json:"socksproxy,omitempty"`
|
||||
User figtree.StringOption `yaml:"user,omitempty" json:"user,omitempty"`
|
||||
AuthenticationMethod figtree.StringOption `yaml:"authentication-method,omitempty" json:"authentication-method,omitempty"`
|
||||
Endpoint figtree.StringOption `yaml:"endpoint,omitempty" json:"endpoint,omitempty"`
|
||||
Insecure figtree.BoolOption `yaml:"insecure,omitempty" json:"insecure,omitempty"`
|
||||
Login figtree.StringOption `yaml:"login,omitempty" json:"login,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"`
|
||||
SocksProxy figtree.StringOption `yaml:"socksproxy,omitempty" json:"socksproxy,omitempty"`
|
||||
UnixProxy figtree.StringOption `yaml:"unixproxy,omitempty" json:"unixproxy,omitempty"`
|
||||
User figtree.StringOption `yaml:"user,omitempty" json:"user,omitempty"`
|
||||
}
|
||||
|
||||
type CommonOptions struct {
|
||||
@@ -66,39 +67,71 @@ type kingpinAppOrCommand interface {
|
||||
GetCommand(string) *kingpin.CmdClause
|
||||
}
|
||||
|
||||
func Register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree, reg []CommandRegistry) {
|
||||
var globalCommandRegistry = []CommandRegistry{}
|
||||
|
||||
func RegisterCommand(regEntry CommandRegistry) {
|
||||
globalCommandRegistry = append(globalCommandRegistry, regEntry)
|
||||
}
|
||||
|
||||
func (o *GlobalOptions) AuthMethod() string {
|
||||
if strings.Contains(o.Endpoint.Value, ".atlassian.net") && o.AuthenticationMethod.Source == "default" {
|
||||
return "api-token"
|
||||
}
|
||||
return o.AuthenticationMethod.Value
|
||||
}
|
||||
|
||||
func register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree) {
|
||||
globals := GlobalOptions{
|
||||
User: figtree.NewStringOption(os.Getenv("USER")),
|
||||
User: figtree.NewStringOption(os.Getenv("USER")),
|
||||
AuthenticationMethod: figtree.NewStringOption("session"),
|
||||
}
|
||||
app.Flag("endpoint", "Base URI to use for Jira").Short('e').SetValue(&globals.Endpoint)
|
||||
app.Flag("insecure", "Disable TLS certificate verification").Short('k').SetValue(&globals.Insecure)
|
||||
app.Flag("quiet", "Suppress output to console").Short('Q').SetValue(&globals.Quiet)
|
||||
app.Flag("unixproxy", "Path for a unix-socket proxy").SetValue(&globals.UnixProxy)
|
||||
app.Flag("socksproxy", "Address for a socks proxy").SetValue(&globals.SocksProxy)
|
||||
app.Flag("user", "Login name used for authentication with Jira service").Short('u').SetValue(&globals.User)
|
||||
app.Flag("user", "user name used within the Jira service").Short('u').SetValue(&globals.User)
|
||||
app.Flag("login", "login name that corresponds to the user used for authentication").SetValue(&globals.Login)
|
||||
|
||||
o = o.WithPreCallback(
|
||||
func(req *http.Request) (*http.Request, error) {
|
||||
if globals.AuthMethod() == "api-token" {
|
||||
// need to set basic auth header with user@domain:api-token
|
||||
token := globals.GetPass()
|
||||
authHeader := fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", globals.Login.Value, token))))
|
||||
req.Header.Add("Authorization", authHeader)
|
||||
}
|
||||
return req, nil
|
||||
},
|
||||
)
|
||||
|
||||
o = o.WithPostCallback(
|
||||
func(req *http.Request, resp *http.Response) (*http.Response, error) {
|
||||
authUser := resp.Header.Get("X-Ausername")
|
||||
if authUser == "" || authUser == "anonymous" {
|
||||
// preserve the --quiet value, we need to temporarily disable it so
|
||||
// the normal login output is surpressed
|
||||
defer func(quiet bool) {
|
||||
globals.Quiet.Value = quiet
|
||||
}(globals.Quiet.Value)
|
||||
globals.Quiet.Value = true
|
||||
if globals.AuthMethod() == "session" {
|
||||
authUser := resp.Header.Get("X-Ausername")
|
||||
if authUser == "" || authUser == "anonymous" {
|
||||
// preserve the --quiet value, we need to temporarily disable it so
|
||||
// the normal login output is surpressed
|
||||
defer func(quiet bool) {
|
||||
globals.Quiet.Value = quiet
|
||||
}(globals.Quiet.Value)
|
||||
globals.Quiet.Value = true
|
||||
|
||||
// we are not logged in, so force login now by running the "login" command
|
||||
app.Parse([]string{"login"})
|
||||
// we are not logged in, so force login now by running the "login" command
|
||||
app.Parse([]string{"login"})
|
||||
|
||||
// rerun the original request
|
||||
// rerun the original request
|
||||
return o.Do(req)
|
||||
}
|
||||
} else if globals.AuthMethod() == "api-token" && resp.StatusCode == 401 {
|
||||
globals.SetPass("")
|
||||
return o.Do(req)
|
||||
}
|
||||
return resp, nil
|
||||
},
|
||||
)
|
||||
|
||||
for _, command := range reg {
|
||||
for _, command := range globalCommandRegistry {
|
||||
copy := command
|
||||
commandFields := strings.Fields(copy.Command)
|
||||
var appOrCmd kingpinAppOrCommand = app
|
||||
@@ -129,6 +162,12 @@ func Register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree, re
|
||||
} else if globals.SocksProxy.Value != "" {
|
||||
o = o.WithTransport(socksProxy(globals.SocksProxy.Value))
|
||||
}
|
||||
if globals.AuthMethod() == "api-token" {
|
||||
o = o.WithCookieFile("")
|
||||
}
|
||||
if globals.Login.Value == "" {
|
||||
globals.Login = globals.User
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package jiracli
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/coryb/oreo"
|
||||
logging "gopkg.in/op/go-logging.v1"
|
||||
)
|
||||
|
||||
var (
|
||||
log = logging.MustGetLogger("jira")
|
||||
)
|
||||
|
||||
func IncreaseLogLevel(verbosity int) {
|
||||
logging.SetLevel(logging.GetLevel("")+logging.Level(verbosity), "")
|
||||
if logging.GetLevel("") > logging.DEBUG {
|
||||
oreo.TraceRequestBody = true
|
||||
oreo.TraceResponseBody = true
|
||||
}
|
||||
}
|
||||
|
||||
func InitLogging() {
|
||||
logBackend := logging.NewLogBackend(os.Stderr, "", 0)
|
||||
format := os.Getenv("JIRA_LOG_FORMAT")
|
||||
if format == "" {
|
||||
format = "%{color}%{level:-5s}%{color:reset} %{message}"
|
||||
}
|
||||
logging.SetBackend(
|
||||
logging.NewBackendFormatter(
|
||||
logBackend,
|
||||
logging.MustStringFormatter(format),
|
||||
),
|
||||
)
|
||||
if os.Getenv("JIRA_DEBUG") == "" {
|
||||
logging.SetLevel(logging.NOTICE, "")
|
||||
} else {
|
||||
logging.SetLevel(logging.DEBUG, "")
|
||||
if verbosity, err := strconv.Atoi(os.Getenv("JIRA_DEBUG")); err == nil {
|
||||
IncreaseLogLevel(verbosity)
|
||||
}
|
||||
}
|
||||
}
|
||||
+43
-6
@@ -3,6 +3,7 @@ package jiracli
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
@@ -12,24 +13,41 @@ import (
|
||||
|
||||
func (o *GlobalOptions) ProvideAuthParams() *jiradata.AuthParams {
|
||||
return &jiradata.AuthParams{
|
||||
Username: o.User.Value,
|
||||
Username: o.Login.Value,
|
||||
Password: o.GetPass(),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *GlobalOptions) keyName() string {
|
||||
user := o.Login.Value
|
||||
if o.AuthMethod() == "api-token" {
|
||||
user = "api-token:" + user
|
||||
}
|
||||
|
||||
if o.PasswordSource.Value == "pass" {
|
||||
return fmt.Sprintf("GoJira/%s", user)
|
||||
}
|
||||
return user
|
||||
}
|
||||
|
||||
func (o *GlobalOptions) GetPass() string {
|
||||
passwd := ""
|
||||
if o.PasswordSource.Value != "" {
|
||||
if o.PasswordSource.Value == "keyring" {
|
||||
var err error
|
||||
passwd, err = keyringGet(o.User.Value)
|
||||
passwd, err = keyringGet(o.keyName())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
} 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 {
|
||||
buf := bytes.NewBufferString("")
|
||||
cmd := exec.Command(bin, fmt.Sprintf("GoJira/%s", o.User))
|
||||
cmd := exec.Command(bin, o.keyName())
|
||||
cmd.Stdout = buf
|
||||
cmd.Stderr = buf
|
||||
if err := cmd.Run(); err == nil {
|
||||
@@ -44,9 +62,23 @@ func (o *GlobalOptions) GetPass() string {
|
||||
if passwd != "" {
|
||||
return passwd
|
||||
}
|
||||
|
||||
if passwd = os.Getenv("JIRA_API_TOKEN"); passwd != "" && o.AuthMethod() == "api-token" {
|
||||
return passwd
|
||||
}
|
||||
|
||||
prompt := fmt.Sprintf("Jira Password [%s]: ", o.Login)
|
||||
help := ""
|
||||
|
||||
if o.AuthMethod() == "api-token" {
|
||||
prompt = fmt.Sprintf("Jira API-Token [%s]: ", o.Login)
|
||||
help = "API Tokens may be required by your Jira service endpoint: https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-basic-auth-and-cookie-based-auth/"
|
||||
}
|
||||
|
||||
err := survey.AskOne(
|
||||
&survey.Password{
|
||||
Message: fmt.Sprintf("Jira Password [%s]: ", o.User),
|
||||
Message: prompt,
|
||||
Help: help,
|
||||
},
|
||||
&passwd,
|
||||
nil,
|
||||
@@ -62,15 +94,20 @@ func (o *GlobalOptions) GetPass() string {
|
||||
func (o *GlobalOptions) SetPass(passwd string) error {
|
||||
if o.PasswordSource.Value == "keyring" {
|
||||
// save password in keychain so that it can be used for subsequent http requests
|
||||
err := keyringSet(o.User.Value, passwd)
|
||||
err := keyringSet(o.keyName(), passwd)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to set password in keyring: %s", err)
|
||||
return err
|
||||
}
|
||||
} 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 {
|
||||
log.Debugf("using %s", bin)
|
||||
passName := fmt.Sprintf("GoJira/%s", o.User)
|
||||
passName := o.keyName()
|
||||
if passwd != "" {
|
||||
in := bytes.NewBufferString(fmt.Sprintf("%s\n%s\n", passwd, passwd))
|
||||
out := bytes.NewBufferString("")
|
||||
|
||||
+14
-3
@@ -8,8 +8,8 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
yaml "gopkg.in/coryb/yaml.v2"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
shellquote "github.com/kballard/go-shellquote"
|
||||
"github.com/mgutz/ansi"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
)
|
||||
@@ -74,6 +75,16 @@ func TemplateProcessor() *template.Template {
|
||||
}
|
||||
return out
|
||||
},
|
||||
"shellquote": func(content string) string {
|
||||
return shellquote.Join(content)
|
||||
},
|
||||
"toMinJson": func(content interface{}) (string, error) {
|
||||
bytes, err := json.Marshal(content)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(bytes), nil
|
||||
},
|
||||
"toJson": func(content interface{}) (string, error) {
|
||||
bytes, err := json.MarshalIndent(content, "", " ")
|
||||
if err != nil {
|
||||
@@ -147,7 +158,7 @@ func TemplateProcessor() *template.Template {
|
||||
return strings.Join(vals, sep)
|
||||
},
|
||||
"abbrev": func(max int, content string) string {
|
||||
if len(content) > max {
|
||||
if len(content) > max && max > 2 {
|
||||
var buffer bytes.Buffer
|
||||
buffer.WriteString(content[:max-3])
|
||||
buffer.WriteString("...")
|
||||
@@ -279,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" }} |
|
||||
+{{ "-" | rep 16 }}+{{ "-" | rep $w }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 12 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+
|
||||
{{ 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 -}}
|
||||
+{{ "-" | rep 16 }}+{{ "-" | rep $w }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+{{ "-" | rep 12 }}+{{ "-" | rep 14 }}+{{ "-" | rep 14 }}+
|
||||
`
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
package jiracli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"syscall"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
"github.com/coryb/kingpeon"
|
||||
"github.com/coryb/oreo"
|
||||
jira "gopkg.in/Netflix-Skunkworks/go-jira.v1"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
var usage = `{{define "FormatCommand"}}\
|
||||
{{if .FlagSummary}} {{.FlagSummary}}{{end}}\
|
||||
{{range .Args}} {{if not .Required}}[{{end}}<{{.Name}}>{{if .Value|IsCumulative}}...{{end}}{{if not .Required}}]{{end}}{{end}}\
|
||||
{{end}}\
|
||||
|
||||
{{define "FormatBriefCommands"}}\
|
||||
{{range .FlattenedCommands}}\
|
||||
{{if not .Hidden}}\
|
||||
{{ print .FullCommand ":" | printf "%-20s"}} {{.Help}}
|
||||
{{end}}\
|
||||
{{end}}\
|
||||
{{end}}\
|
||||
|
||||
{{define "FormatCommands"}}\
|
||||
{{range .FlattenedCommands}}\
|
||||
{{if not .Hidden}}\
|
||||
{{.FullCommand}}{{if .Default}}*{{end}}{{template "FormatCommand" .}}
|
||||
{{.Help|Wrap 4}}
|
||||
{{with .Flags|FlagsToTwoColumns}}{{FormatTwoColumnsWithIndent . 4 2}}{{end}}
|
||||
{{end}}\
|
||||
{{end}}\
|
||||
{{end}}\
|
||||
|
||||
{{define "FormatUsage"}}\
|
||||
{{template "FormatCommand" .}}{{if .Commands}} <command> [<args> ...]{{end}}
|
||||
{{if .Help}}
|
||||
{{.Help|Wrap 0}}\
|
||||
{{end}}\
|
||||
|
||||
{{end}}\
|
||||
|
||||
{{if .Context.SelectedCommand}}\
|
||||
usage: {{.App.Name}} {{.Context.SelectedCommand}}{{template "FormatCommand" .Context.SelectedCommand}}
|
||||
{{if .Context.SelectedCommand.Aliases }}\
|
||||
{{range $top := .App.Commands}}\
|
||||
{{if eq $top.FullCommand $.Context.SelectedCommand.FullCommand}}\
|
||||
{{range $alias := $.Context.SelectedCommand.Aliases}}\
|
||||
alias: {{$.App.Name}} {{$alias}}{{template "FormatCommand" $.Context.SelectedCommand}}
|
||||
{{end}}\
|
||||
{{else}}\
|
||||
{{range $sub := $top.Commands}}\
|
||||
{{if eq $sub.FullCommand $.Context.SelectedCommand.FullCommand}}\
|
||||
{{range $alias := $.Context.SelectedCommand.Aliases}}\
|
||||
alias: {{$.App.Name}} {{$top.Name}} {{$alias}}{{template "FormatCommand" $.Context.SelectedCommand}}
|
||||
{{end}}\
|
||||
{{end}}\
|
||||
{{end}}\
|
||||
{{end}}\
|
||||
{{end}}\
|
||||
{{end}}
|
||||
{{if .Context.SelectedCommand.Help}}\
|
||||
{{.Context.SelectedCommand.Help|Wrap 0}}
|
||||
{{end}}\
|
||||
{{else}}\
|
||||
usage: {{.App.Name}}{{template "FormatUsage" .App}}
|
||||
{{end}}\
|
||||
|
||||
{{if .App.Flags}}\
|
||||
Global flags:
|
||||
{{.App.Flags|FlagsToTwoColumns|FormatTwoColumns}}
|
||||
{{end}}\
|
||||
{{if .Context.SelectedCommand}}\
|
||||
{{if and .Context.SelectedCommand.Flags|RequiredFlags}}\
|
||||
Required flags:
|
||||
{{.Context.SelectedCommand.Flags|RequiredFlags|FlagsToTwoColumns|FormatTwoColumns}}
|
||||
{{end}}\
|
||||
{{if .Context.SelectedCommand.Flags|OptionalFlags}}\
|
||||
Optional flags:
|
||||
{{.Context.SelectedCommand.Flags|OptionalFlags|FlagsToTwoColumns|FormatTwoColumns}}
|
||||
{{end}}\
|
||||
{{end}}\
|
||||
{{if .Context.Args}}\
|
||||
Args:
|
||||
{{.Context.Args|ArgsToTwoColumns|FormatTwoColumns}}
|
||||
{{end}}\
|
||||
{{if .Context.SelectedCommand}}\
|
||||
{{if .Context.SelectedCommand.Commands}}\
|
||||
Subcommands:
|
||||
{{template "FormatCommands" .Context.SelectedCommand}}
|
||||
{{end}}\
|
||||
{{else if .App.Commands}}\
|
||||
Commands:
|
||||
{{template "FormatBriefCommands" .App}}
|
||||
{{end}}\
|
||||
`
|
||||
|
||||
func CommandLine(fig *figtree.FigTree, o *oreo.Client) *kingpin.Application {
|
||||
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 {
|
||||
fmt.Println(jira.VERSION)
|
||||
panic(Exit{Code: 0})
|
||||
})
|
||||
app.UsageTemplate(usage)
|
||||
|
||||
var verbosity int
|
||||
app.Flag("verbose", "Increase verbosity for debugging").Short('v').PreAction(func(_ *kingpin.ParseContext) error {
|
||||
os.Setenv("JIRA_DEBUG", fmt.Sprintf("%d", verbosity))
|
||||
IncreaseLogLevel(1)
|
||||
return nil
|
||||
}).CounterVar(&verbosity)
|
||||
|
||||
app.Terminate(func(status int) {
|
||||
for _, arg := range os.Args {
|
||||
if arg == "-h" || arg == "--help" || len(os.Args) == 1 {
|
||||
panic(Exit{Code: 0})
|
||||
}
|
||||
}
|
||||
panic(Exit{Code: 1})
|
||||
})
|
||||
|
||||
register(app, o, fig)
|
||||
|
||||
// register custom commands
|
||||
data := struct {
|
||||
CustomCommands kingpeon.DynamicCommands `yaml:"custom-commands" json:"custom-commands"`
|
||||
}{}
|
||||
|
||||
if err := fig.LoadAllConfigs("config.yml", &data); err != nil {
|
||||
log.Errorf("%s", err)
|
||||
panic(Exit{Code: 1})
|
||||
}
|
||||
|
||||
if len(data.CustomCommands) > 0 {
|
||||
runner := syscall.Exec
|
||||
if runtime.GOOS == "windows" {
|
||||
runner = func(binary string, cmd []string, env []string) error {
|
||||
command := exec.Command(binary, cmd[1:]...)
|
||||
command.Stdin = os.Stdin
|
||||
command.Stdout = os.Stdout
|
||||
command.Stderr = os.Stderr
|
||||
command.Env = env
|
||||
return command.Run()
|
||||
}
|
||||
}
|
||||
|
||||
tmp := map[string]interface{}{}
|
||||
fig.LoadAllConfigs("config.yml", &tmp)
|
||||
kingpeon.RegisterDynamicCommandsWithRunner(runner, app, data.CustomCommands, TemplateProcessor())
|
||||
}
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
func ParseCommandLine(app *kingpin.Application, args []string) {
|
||||
// checking for default usage of `jira ISSUE-123` but need to allow
|
||||
// for global options first like: `jira --user mothra ISSUE-123`
|
||||
ctx, err := app.ParseContext(args)
|
||||
if err != nil && ctx == nil {
|
||||
// This is an internal kingpin usage error, duplicate options/commands
|
||||
log.Fatalf("error: %s, ctx: %v", err, ctx)
|
||||
}
|
||||
|
||||
if ctx != nil {
|
||||
if ctx.SelectedCommand == nil {
|
||||
next := ctx.Next()
|
||||
if next != nil {
|
||||
if ok, err := regexp.MatchString("^[A-Z]+-[0-9]+$", next.Value); err != nil {
|
||||
log.Errorf("Invalid Regex: %s", err)
|
||||
} else if ok {
|
||||
// insert "view" at i=1 (2nd position)
|
||||
os.Args = append(os.Args[:1], append([]string{"view"}, os.Args[1:]...)...)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := app.Parse(os.Args[1:]); err != nil {
|
||||
if _, ok := err.(*Error); ok {
|
||||
log.Errorf("%s", err)
|
||||
panic(Exit{Code: 1})
|
||||
} else {
|
||||
ctx, _ := app.ParseContext(os.Args[1:])
|
||||
if ctx != nil {
|
||||
app.UsageForContext(ctx)
|
||||
}
|
||||
log.Errorf("Invalid Usage: %s", err)
|
||||
panic(Exit{Code: 1})
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
@@ -30,7 +31,7 @@ func findClosestParentPath(fileName string) (string, error) {
|
||||
}
|
||||
|
||||
func tmpYml(tmpFilePrefix string) (*os.File, error) {
|
||||
fh, err := ioutil.TempFile("", tmpFilePrefix)
|
||||
fh, err := ioutil.TempFile("", filepath.Base(tmpFilePrefix))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ func CmdAssign(o *oreo.Client, globals *jiracli.GlobalOptions, opts *AssignOptio
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
+2
-2
@@ -66,8 +66,8 @@ func CmdBlock(o *oreo.Client, globals *jiracli.GlobalOptions, opts *BlockOptions
|
||||
}
|
||||
|
||||
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/browse/%s\n", opts.OutwardIssue.Key, globals.Endpoint.Value, opts.OutwardIssue.Key)
|
||||
fmt.Printf("OK %s %s\n", opts.InwardIssue.Key, jira.URLJoin(globals.Endpoint.Value, "browse", opts.InwardIssue.Key))
|
||||
fmt.Printf("OK %s %s\n", opts.OutwardIssue.Key, jira.URLJoin(globals.Endpoint.Value, "browse", opts.OutwardIssue.Key))
|
||||
}
|
||||
|
||||
if opts.Browse.Value {
|
||||
|
||||
+2
-3
@@ -1,11 +1,10 @@
|
||||
package jiracmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
"github.com/coryb/oreo"
|
||||
"github.com/pkg/browser"
|
||||
jira "gopkg.in/Netflix-Skunkworks/go-jira.v1"
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
@@ -27,5 +26,5 @@ func CmdBrowseRegistry() *jiracli.CommandRegistryEntry {
|
||||
|
||||
// CmdBrowse open the default system browser to the provided issue
|
||||
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
@@ -68,7 +68,7 @@ func CmdComment(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CommentOpt
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
+3
-2
@@ -93,8 +93,9 @@ func CmdCreate(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CreateOptio
|
||||
return err
|
||||
}
|
||||
|
||||
browseLink := jira.URLJoin(globals.Endpoint.Value, "browse", issueResp.Key)
|
||||
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 != "" {
|
||||
@@ -105,7 +106,7 @@ func CmdCreate(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CreateOptio
|
||||
defer fh.Close()
|
||||
out, err := yaml.Marshal(map[string]string{
|
||||
"issue": issueResp.Key,
|
||||
"link": fmt.Sprintf("%s/browse/%s", globals.Endpoint.Value, issueResp.Key),
|
||||
"link": browseLink,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
+2
-2
@@ -67,7 +67,7 @@ func CmdDup(o *oreo.Client, globals *jiracli.GlobalOptions, opts *DupOptions) er
|
||||
return err
|
||||
}
|
||||
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)
|
||||
@@ -103,7 +103,7 @@ func CmdDup(o *oreo.Client, globals *jiracli.GlobalOptions, opts *DupOptions) er
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
+3
-3
@@ -37,7 +37,7 @@ func CmdEditRegistry() *jiracli.CommandRegistryEntry {
|
||||
},
|
||||
func(o *oreo.Client, globals *jiracli.GlobalOptions) error {
|
||||
if opts.QueryFields == "" {
|
||||
opts.QueryFields = "assignee,created,priority,reporter,status,summary,updated,issuetype,comments,description,votes,created,customfield_10110,components"
|
||||
opts.QueryFields = "assignee,created,priority,reporter,status,summary,updated,issuetype,comment,description,votes,created,customfield_10110,components"
|
||||
}
|
||||
return CmdEdit(o, globals, &opts)
|
||||
},
|
||||
@@ -98,7 +98,7 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions)
|
||||
return err
|
||||
}
|
||||
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 {
|
||||
return CmdBrowse(globals, opts.Issue)
|
||||
@@ -145,7 +145,7 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions)
|
||||
return err
|
||||
}
|
||||
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 {
|
||||
return CmdBrowse(globals, issueData.Key)
|
||||
|
||||
+2
-2
@@ -44,9 +44,9 @@ func CmdEpicAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EpicAddOpt
|
||||
}
|
||||
|
||||
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 {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ func CmdEpicRemove(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EpicRem
|
||||
|
||||
if !globals.Quiet.Value {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,8 +62,8 @@ func CmdIssueLink(o *oreo.Client, globals *jiracli.GlobalOptions, opts *IssueLin
|
||||
}
|
||||
|
||||
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/browse/%s\n", opts.OutwardIssue.Key, globals.Endpoint.Value, opts.OutwardIssue.Key)
|
||||
fmt.Printf("OK %s %s\n", opts.InwardIssue.Key, jira.URLJoin(globals.Endpoint.Value, "browse", opts.InwardIssue.Key))
|
||||
fmt.Printf("OK %s %s\n", opts.OutwardIssue.Key, jira.URLJoin(globals.Endpoint.Value, "browse", opts.OutwardIssue.Key))
|
||||
}
|
||||
|
||||
if opts.Browse.Value {
|
||||
|
||||
@@ -57,7 +57,7 @@ func CmdLabelsAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *LabelsAd
|
||||
return err
|
||||
}
|
||||
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 {
|
||||
return CmdBrowse(globals, opts.Issue)
|
||||
|
||||
@@ -58,7 +58,7 @@ func CmdLabelsRemove(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Label
|
||||
return err
|
||||
}
|
||||
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 {
|
||||
return CmdBrowse(globals, opts.Issue)
|
||||
|
||||
@@ -55,7 +55,7 @@ func CmdLabelsSet(o *oreo.Client, globals *jiracli.GlobalOptions, opts *LabelsSe
|
||||
return err
|
||||
}
|
||||
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 {
|
||||
return CmdBrowse(globals, opts.Issue)
|
||||
|
||||
@@ -46,6 +46,11 @@ func authCallback(req *http.Request, resp *http.Response) (*http.Response, error
|
||||
|
||||
// CmdLogin will attempt to login into jira server
|
||||
func CmdLogin(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.CommonOptions) error {
|
||||
if globals.AuthMethod() == "api-token" {
|
||||
log.Noticef("No need to login when using api-token authentication method")
|
||||
return nil
|
||||
}
|
||||
|
||||
ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks().WithPostCallback(authCallback)
|
||||
for {
|
||||
if session, err := jira.GetSession(o, globals.Endpoint.Value); err != nil {
|
||||
|
||||
@@ -2,10 +2,13 @@ package jiracmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/coryb/figtree"
|
||||
"github.com/coryb/oreo"
|
||||
"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/jiracli"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
@@ -27,6 +30,28 @@ func CmdLogoutRegistry() *jiracli.CommandRegistryEntry {
|
||||
|
||||
// CmdLogout will attempt to terminate an active Jira session
|
||||
func CmdLogout(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.CommonOptions) error {
|
||||
if globals.AuthMethod() == "api-token" {
|
||||
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
|
||||
}
|
||||
ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks()
|
||||
err := jira.DeleteSession(ua, globals.Endpoint.Value)
|
||||
if err == nil {
|
||||
|
||||
+2
-2
@@ -59,8 +59,8 @@ func CmdRank(o *oreo.Client, globals *jiracli.GlobalOptions, opts *RankOptions)
|
||||
}
|
||||
|
||||
if !globals.Quiet.Value {
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.First, globals.Endpoint.Value, opts.First)
|
||||
fmt.Printf("OK %s %s/browse/%s\n", opts.Second, globals.Endpoint.Value, opts.Second)
|
||||
fmt.Printf("OK %s %s\n", opts.First, jira.URLJoin(globals.Endpoint.Value, "browse", opts.First))
|
||||
fmt.Printf("OK %s %s\n", opts.Second, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Second))
|
||||
}
|
||||
|
||||
if opts.Browse.Value {
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package jiracmd
|
||||
|
||||
import "gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
|
||||
|
||||
func RegisterAllCommands() {
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "acknowledge", Entry: CmdTransitionRegistry("acknowledge"), Aliases: []string{"ack"}})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "assign", Entry: CmdAssignRegistry(), Aliases: []string{"give"}})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "attach create", Entry: CmdAttachCreateRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "attach get", Entry: CmdAttachGetRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "attach list", Entry: CmdAttachListRegistry(), Aliases: []string{"ls"}})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "attach remove", Entry: CmdAttachRemoveRegistry(), Aliases: []string{"rm"}})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "backlog", Entry: CmdTransitionRegistry("Backlog")})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "block", Entry: CmdBlockRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "browse", Entry: CmdBrowseRegistry(), Aliases: []string{"b"}})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "close", Entry: CmdTransitionRegistry("close")})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "comment", Entry: CmdCommentRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "component add", Entry: CmdComponentAddRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "components", Entry: CmdComponentsRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "create", Entry: CmdCreateRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "createmeta", Entry: CmdCreateMetaRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "done", Entry: CmdTransitionRegistry("Done")})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "dup", Entry: CmdDupRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "edit", Entry: CmdEditRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "editmeta", Entry: CmdEditMetaRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "epic add", Entry: CmdEpicAddRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "epic create", Entry: CmdEpicCreateRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "epic list", Entry: CmdEpicListRegistry(), Aliases: []string{"ls"}})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "epic remove", Entry: CmdEpicRemoveRegistry(), Aliases: []string{"rm"}})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "export-templates", Entry: CmdExportTemplatesRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "fields", Entry: CmdFieldsRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "in-progress", Entry: CmdTransitionRegistry("Progress"), Aliases: []string{"prog", "progress"}})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "issuelink", Entry: CmdIssueLinkRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "issuelinktypes", Entry: CmdIssueLinkTypesRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "issuetypes", Entry: CmdIssueTypesRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "labels add", Entry: CmdLabelsAddRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "labels remove", Entry: CmdLabelsRemoveRegistry(), Aliases: []string{"rm"}})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "labels set", Entry: CmdLabelsSetRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "list", Entry: CmdListRegistry(), Aliases: []string{"ls"}})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "login", Entry: CmdLoginRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "logout", Entry: CmdLogoutRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "rank", Entry: CmdRankRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "reopen", Entry: CmdTransitionRegistry("reopen")})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "request", Entry: CmdRequestRegistry(), Aliases: []string{"req"}})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "resolve", Entry: CmdTransitionRegistry("resolve")})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "start", Entry: CmdTransitionRegistry("start")})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "stop", Entry: CmdTransitionRegistry("stop")})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "subtask", Entry: CmdSubtaskRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "take", Entry: CmdTakeRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "todo", Entry: CmdTransitionRegistry("To Do")})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "transition", Entry: CmdTransitionRegistry(""), Aliases: []string{"trans"}})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "transitions", Entry: CmdTransitionsRegistry("transitions")})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "transmeta", Entry: CmdTransitionsRegistry("debug")})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "unassign", Entry: CmdUnassignRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "unexport-templates", Entry: CmdUnexportTemplatesRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "view", Entry: CmdViewRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "vote", Entry: CmdVoteRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "watch", Entry: CmdWatchRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "worklog add", Entry: CmdWorklogAddRegistry()})
|
||||
jiracli.RegisterCommand(jiracli.CommandRegistry{Command: "worklog list", Entry: CmdWorklogListRegistry(), Default: true})
|
||||
}
|
||||
+1
-1
@@ -108,7 +108,7 @@ func CmdSubtask(o *oreo.Client, globals *jiracli.GlobalOptions, opts *SubtaskOpt
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
+3
-1
@@ -17,7 +17,9 @@ func CmdTakeRegistry() *jiracli.CommandRegistryEntry {
|
||||
return CmdAssignUsage(cmd, &opts)
|
||||
},
|
||||
func(o *oreo.Client, globals *jiracli.GlobalOptions) error {
|
||||
opts.Assignee = globals.User.Value
|
||||
if opts.Assignee == "" {
|
||||
opts.Assignee = globals.User.Value
|
||||
}
|
||||
return CmdAssign(o, globals, &opts)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ func CmdTransition(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Transit
|
||||
return jiracli.CliError(err)
|
||||
}
|
||||
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 {
|
||||
|
||||
@@ -23,7 +23,7 @@ func CmdUnexportTemplatesRegistry() *jiracli.CommandRegistryEntry {
|
||||
return CmdExportTemplatesUsage(cmd, &opts)
|
||||
},
|
||||
func(o *oreo.Client, globals *jiracli.GlobalOptions) error {
|
||||
if opts.Dir != "" {
|
||||
if opts.Dir == "" {
|
||||
opts.Dir = fmt.Sprintf("%s/.jira.d/templates", jiracli.Homedir())
|
||||
}
|
||||
return CmdUnexportTemplates(globals, &opts)
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ func CmdVote(o *oreo.Client, globals *jiracli.GlobalOptions, opts *VoteOptions)
|
||||
}
|
||||
}
|
||||
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 {
|
||||
return CmdBrowse(globals, opts.Issue)
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ func CmdWatch(o *oreo.Client, globals *jiracli.GlobalOptions, opts *WatchOptions
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@@ -59,7 +59,7 @@ func CmdWorklogAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Worklog
|
||||
return err
|
||||
}
|
||||
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 {
|
||||
return CmdBrowse(globals, opts.Issue)
|
||||
|
||||
+1
-3
@@ -1,8 +1,6 @@
|
||||
package jira
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"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) {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -83,7 +83,7 @@ func Search(ua HttpClient, endpoint string, sp SearchProvider) (*jiradata.Search
|
||||
if err != nil {
|
||||
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))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+4
-5
@@ -3,7 +3,6 @@ package jira
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
|
||||
)
|
||||
@@ -17,7 +16,7 @@ type AuthOptions struct {
|
||||
Password string
|
||||
}
|
||||
|
||||
func (a *AuthOptions) AuthParams() *jiradata.AuthParams {
|
||||
func (a *AuthOptions) ProvideAuthParams() *jiradata.AuthParams {
|
||||
return &jiradata.AuthParams{
|
||||
Username: a.Username,
|
||||
Password: a.Password,
|
||||
@@ -35,7 +34,7 @@ func NewSession(ua HttpClient, endpoint string, ap AuthProvider) (*jiradata.Auth
|
||||
if err != nil {
|
||||
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))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -55,7 +54,7 @@ func (j *Jira) GetSession() (*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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -75,7 +74,7 @@ func (j *Jira) DeleteSession() 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)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -3,6 +3,7 @@ config:
|
||||
password-source: pass
|
||||
endpoint: https://go-jira.atlassian.net
|
||||
user: gojira
|
||||
login: gojira@corybennett.org
|
||||
|
||||
project: BASIC
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+1
-1
@@ -245,7 +245,7 @@ EOF
|
||||
# reset login for mothra for voting
|
||||
###############################################################################
|
||||
|
||||
jira="$jira --user mothra"
|
||||
jira="$jira --user mothra --login mothra@corybennett.org"
|
||||
|
||||
RUNS $jira logout
|
||||
RUNS $jira login
|
||||
|
||||
+1
-1
@@ -185,7 +185,7 @@ EOF
|
||||
# reset login for mothra for voting
|
||||
###############################################################################
|
||||
|
||||
jira="$jira --user mothra"
|
||||
jira="$jira --user mothra --login mothra@corybennett.org"
|
||||
|
||||
RUNS $jira logout
|
||||
echo "mothra123" | RUNS $jira login
|
||||
|
||||
+1
-1
@@ -185,7 +185,7 @@ EOF
|
||||
# reset login for mothra for voting
|
||||
###############################################################################
|
||||
|
||||
jira="$jira --user mothra"
|
||||
jira="$jira --user mothra --login mothra@corybennett.org"
|
||||
|
||||
RUNS $jira logout
|
||||
echo "mothra123" | RUNS $jira login
|
||||
|
||||
+1
-1
@@ -185,7 +185,7 @@ EOF
|
||||
# reset login for mothra for voting
|
||||
###############################################################################
|
||||
|
||||
jira="$jira --user mothra"
|
||||
jira="$jira --user mothra --login mothra@corybennett.org"
|
||||
|
||||
RUNS $jira logout
|
||||
echo "mothra123" | RUNS $jira login
|
||||
|
||||
+1
-1
@@ -194,7 +194,7 @@ EOF
|
||||
# reset login for mothra for voting
|
||||
###############################################################################
|
||||
|
||||
jira="$jira --user mothra"
|
||||
jira="$jira --user mothra --login mothra@corybennett.org"
|
||||
|
||||
RUNS $jira logout
|
||||
echo "mothra123" | RUNS $jira login
|
||||
|
||||
+1
-1
@@ -187,7 +187,7 @@ EOF
|
||||
# reset login for mothra for voting
|
||||
###############################################################################
|
||||
|
||||
jira="$jira --user mothra"
|
||||
jira="$jira --user mothra --login mothra@corybennett.org"
|
||||
|
||||
RUNS $jira logout
|
||||
echo "mothra123" | RUNS $jira login
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"path"
|
||||
)
|
||||
|
||||
func readJSON(input io.Reader, data interface{}) error {
|
||||
@@ -21,3 +23,13 @@ func readJSON(input io.Reader, data interface{}) error {
|
||||
}
|
||||
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()
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ func runDynamicCommand(run runner, dynamiccommand *DynamicCommand, t *template.T
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = t.Execute(buf, nil)
|
||||
err = t.Execute(buf, dynamiccommand)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user