Jira
simple jira command line client in Go
Install / Use
/learn @go-jira/JiraREADME
go-jira
Simple command line client for Atlassian's Jira service written in Go.
GDPR USERNAME DISCLAIMER
When this tool was initial written the "username" parameter was widely used in the Atlassian API. Due to GDPR restrictions this parameter was been almost completely phased out other then V1 login. The "--user" field is still provided as a default global, however moving forward any usage of this field should be phased out in favor of the "--login" option.
Commands which previously took a username will now expect an email address such as watch, create, assign, etc...
Install
Download
You can download one of the pre-built binaries for go-jira here.
Build
You can build and install the official repository with Go (before running the below command, ensure you have GO111MODULE=on set in your environment):
go get github.com/go-jira/jira/cmd/jira
This will checkout this repository into $GOPATH/src/github.com/go-jira/jira/, build, and install it.
It should then be available in $GOPATH/bin/jira.
Usage
Setting up TAB completion
Since go-jira is built with the "kingpin" golang command line library we support bash/zsh shell completion automatically:
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.
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 closest to your current working directory will have precedence. Properties overridden 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:
project: foo
You will need to specify your local jira endpoint first, typically in your homedir like:
mkdir ~/.jira.d
cat <<EOM >~/.jira.d/config.yml
endpoint: https://jira.mycompany.com
EOM
Then use jira login to authenticate yourself as $USER. To change your username, use the -u CLI flag or set user: in your config.yml
Dynamic Configuration
If the .jira.d/config.yml file is executable, then go-jira will attempt to execute the file and use the stdout for configuration. You can use this to customize templates or other overrides depending on what type of operation you are running. For example if you would like to use the "table" template when ever you run jira ls, then you can create a template like this:
#!/bin/sh
echo "endpoint: https://jira.mycompany.com"
echo "editor: emacs -nw"
case $JIRA_OPERATION in
list)
echo "template: table";;
esac
Or if you always set the same overrides when you create an issue for your project you can do something like this:
#!/bin/sh
echo "project: GOJIRA"
case $JIRA_OPERATION in
create)
echo "assignee: $USER"
echo "watchers: mothra"
;;
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:
custom-commands:
- command1
- command2
Commands
Where the individual commands are maps with these keys:
name: string[required] This is the command name, so forjira foobaryou would havename: foobarhelp: stringThis is help message displayed in the usage for the commandhidden: boolThis command will be hidden from users, but still executable. Sometimes useful for constructing complex commands where one custom command might call another.default: boolUse this for compound command groups. If you wanted to havejira foo barandjira foo bazyou would have two commands withname: foo barandname: foo baz. Then if you wantedjira foo bazto be called by default when you typejira fooyou would setdefault: truefor that custom command.options: listThis is the list of possible option flags that the command will acceptargs: listThis is the list of command arguments (like the ISSUE) that the command will accept.aliases: string list: This is a list of alternate names that the user can provide on the command line to run the same command. Typically used to shorten the command name or provide alternatives that users might expect.script: string[required] This is the script that will be executed as the action for this command. The value will be treated as a template and substitutions for options and arguments will be made before executing.
Options
These are possible keys under the command options property:
name: string[required] Name of the option, soname: foobarwill result in--foobaroption.help: stringThe help message displayed in usage for the option.type: string: The type of the option, can be one of these values:BOOL,COUNTER,ENUM,FLOAT32,FLOAT64,INT8,INT16,INT32,INT64,INT,STRING,STRINGMAP,UINT8,UINT16,UINT32,UINT64andUINT. Most of these are primitive data types an should be self-explanatory. The default type isSTRING. There are some special types:COUNTERwill be an integer type that increments each time the option is used. So something like--count --countwill results in{{options.count}}of2.ENUMtype is used with theenumproperty. The raw type is a string and must be one of the values listed in theenumproperty.STRINGMAPis astring => stringmap with the format ofKEY=VALUE. So--override foo=bar --override bin=bazwill allow for{{options.override.foo}}to bebarand{{options.override.bin}}to bebaz.
short: charThe single character option to be used soshort: cwill allow for-c.required: boolIndicate that this option must be provided on the command line. Conflicts with thedefaultproperty.default: anySpecify the default value for the option. Conflicts with therequiredproperty.hidden: boolHide the option from the usage help message, but otherwise works fine. Sometimes useful for developer options that user should not play with.repeat: boolIndicate that this option can be repeated. Not applicable forCOUNTERandSTRINGMAPtypes. This will turn the option value into an array that you can iterate over. So--day Monday --day Thursdaycan be used like{{range options.day}}Day: {{.}}{{end}}enum: string listUsed with thetype: ENUMproperty, it is a list of strings values that represent the set of possible values the option accepts.
Arguments
These are possible keys under the command args property:
name: string[required] Name of the option, soname: ISSUEwill show in the usage asjira <command> ISSUE. This also represents the name of the argument to be used in the script template, so{{args.ISSUE}}.help: stringThe help message displayed in usage for the argument.type: string: The type of the argument, can be one of these values:BOOL,COUNTER,ENUM,FLOAT32,FLOAT64,INT8,INT16,INT32,INT64,INT,STRING,STRINGMAP,UINT8,UINT16,UINT32,UINT64andUINT. Most of these are primitive data types an should be self-explanatory. The default type isSTRING. There are some special types:COUNTERwill be an integer type that increments each the argument is provided So something likejira <command> ISSUE-12 ISSUE-23will results in{{args.ISSUE}}of2.ENUMtype is used with theenumproperty. The raw type is a string and must be one of the values listed in theenumproperty.STRINGMAPis astring => stringmap with the format ofKEY=VALUE. Sojira <command> foo=bar bin=bazalong with aname: OVERRIDEproperty will allow for{{args.OVERRIDE.foo}}to bebarand{{args.OVERRIDE.bin}}to bebaz.
required: boolIndicate that this argument must be provided on the command line. Conflicts with thedefaultproperty.default: anySpecify the default value for the argument. Conflicts with therequiredproperty.repeat: boolIndicate that this argument can be repeated. Not applicable forCOUNTERandSTRINGMAPtypes. This will turn the template value into an array that you can iterate over. Sojira <command> ISSUE-12 ISSUE-23can be used like{{range args.ISSUE}}Issue: {{.}}{{end}}- `enum: string li
