Coder Social home page Coder Social logo

jira's Introduction

Build Status GoDoc License

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 for jira foobar you would have name: foobar
  • help: string This is help message displayed in the usage for the command
  • hidden: bool This command will be hidden from users, but still executable. Sometimes useful for constructing complex commands where one custom command might call another.
  • default: bool Use this for compound command groups. If you wanted to have jira foo bar and jira foo baz you would have two commands with name: foo bar and name: foo baz. Then if you wanted jira foo baz to be called by default when you type jira foo you would set default: true for that custom command.
  • options: list This is the list of possible option flags that the command will accept
  • args: list This 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, so name: foobar will result in --foobar option.
  • help: string The 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, UINT64 and UINT. Most of these are primitive data types an should be self-explanatory. The default type is STRING. There are some special types:
    • COUNTER will be an integer type that increments each time the option is used. So something like --count --count will results in {{options.count}} of 2.
    • ENUM type is used with the enum property. The raw type is a string and must be one of the values listed in the enum property.
    • STRINGMAP is a string => string map with the format of KEY=VALUE. So --override foo=bar --override bin=baz will allow for {{options.override.foo}} to be bar and {{options.override.bin}} to be baz.
  • short: char The single character option to be used so short: c will allow for -c.
  • required: bool Indicate that this option must be provided on the command line. Conflicts with the default property.
  • default: any Specify the default value for the option. Conflicts with the required property.
  • hidden: bool Hide the option from the usage help message, but otherwise works fine. Sometimes useful for developer options that user should not play with.
  • repeat: bool Indicate that this option can be repeated. Not applicable for COUNTER and STRINGMAP types. This will turn the option value into an array that you can iterate over. So --day Monday --day Thursday can be used like {{range options.day}}Day: {{.}}{{end}}
  • enum: string list Used with the type: ENUM property, 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, so name: ISSUE will show in the usage as jira <command> ISSUE. This also represents the name of the argument to be used in the script template, so {{args.ISSUE}}.
  • help: string The 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, UINT64 and UINT. Most of these are primitive data types an should be self-explanatory. The default type is STRING. There are some special types:
    • COUNTER will be an integer type that increments each the argument is provided So something like jira <command> ISSUE-12 ISSUE-23 will results in {{args.ISSUE}} of 2.
    • ENUM type is used with the enum property. The raw type is a string and must be one of the values listed in the enum property.
    • STRINGMAP is a string => string map with the format of KEY=VALUE. So jira <command> foo=bar bin=baz along with a name: OVERRIDE property will allow for {{args.OVERRIDE.foo}} to be bar and {{args.OVERRIDE.bin}} to be baz.
  • required: bool Indicate that this argument must be provided on the command line. Conflicts with the default property.
  • default: any Specify the default value for the argument. Conflicts with the required property.
  • repeat: bool Indicate that this argument can be repeated. Not applicable for COUNTER and STRINGMAP types. This will turn the template value into an array that you can iterate over. So jira <command> ISSUE-12 ISSUE-23 can be used like {{range args.ISSUE}}Issue: {{.}}{{end}}
  • enum: string list Used with the type: ENUM property, it is a list of strings values that represent the set of possible values for the argument.
Script Template

The script property is a template that would 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:

custom-commands:
  - name: custom-test
    help: Testing the custom commands
    options:
      - name: abc
        short: a
        default: default
      - name: day
        type: ENUM
        enum:
          - Monday
          - Tuesday
          - Wednesday
          - Thursday
          - Friday
        required: true
    args:
      - name: ARG
        required: true
      - name: MORE
        repeat: true
    script: |
      echo COMMAND {{args.ARG}} --abc {{options.abc}} --day {{options.day}} {{range $more := args.MORE}}{{$more}} {{end}}

Then to run it:

$ jira custom-test
ERROR Invalid Usage: required flag --day not provided

$ jira custom-test --day Sunday
ERROR Invalid Usage: enum value must be one of Monday,Tuesday,Wednesday,Thursday,Friday, got 'Sunday'

$ jira custom-test --day Tuesday
ERROR Invalid Usage: required argument 'ARG' not provided

$ jira custom-test --day Tuesday arg1
COMMAND arg1 --abc default --day Tuesday

$ jira custom-test --day Tuesday arg1 more1 more2 more3
COMMAND arg1 --abc default --day Tuesday more1 more2 more3

$ jira custom-test --day Tuesday arg1 more1 more2 more3 --abc non-default
COMMAND arg1 --abc non-default --day Tuesday more1 more2 more3

$ jira custom-test --day Tuesday arg1 more1 more2 more3 -a short-non-default
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:

custom-commands:
  - name: env
    help: print the JIRA environment variables available to custom commands
    script: |
      env | grep JIRA

You could use the environment variables automatically, so if your .jira.d/config.yml looks something like this:

project: PROJECT
custom-commands:
  - name: print-project
    help: print the name of the configured project
    script: "echo $JIRA_PROJECT"
Examples
  • jira mine for listing issues assigned to you
custom-commands:
  - name: mine
    help: display issues assigned to me
    script: |-
      if [ -n "$JIRA_PROJECT" ]; then
          # if `project: ...` configured just list the issues for current project
          {{jira}} list --template table --query "resolution = unresolved and assignee=currentuser() and project = $JIRA_PROJECT ORDER BY priority asc, created"
      else
          # otherwise list issues for all project
          {{jira}} list --template table --query "resolution = unresolved and assignee=currentuser() ORDER BY priority asc, created"
      fi
  • jira sprint for listing issues in your current sprint
custom-commands:
  - name: sprint
    help: display issues for active sprint
    script: |-
      if [ -n "$JIRA_PROJECT" ]; then
          # if `project: ...` configured just list the issues for current project
          {{jira}} list --template table --query "sprint in openSprints() and type != epic and resolution = unresolved and project=$JIRA_PROJECT ORDER BY rank asc, created"
      else
          # otherwise list issues for all project
          {{jira}} list --template table --query "sprint in openSprints() and type != epic and resolution = unresolved ORDER BY rank asc, created"
      fi

Editing

When you run command like jira edit it will open up your favorite editor with the templatized output so you can quickly edit. When the editor closes go-jira will submit the completed form. The order which go-jira attempts to determine your preferred editor is:

  • editor property in any config.yml file
  • JIRA_EDITOR environment variable
  • EDITOR environment variable
  • vim

Templates

go-jira has the ability to customize most output (and editor input) via templates. There are default templates available for all operations, which may or may not work for your actual jira implementation. Jira is endlessly customizable, so it is hard to provide default templates that will work for all issue types.

When running a command like jira edit it will look through the current directory hierarchy trying to find a file that matches .jira.d/templates/edit, if found it will use that file as the template, otherwise it will use the default edit template hard-coded into go-jira. You can export the default hard-coded templates with jira export-templates which will write them to ~/.jira.d/templates/.

Writing/Editing Templates

First the basic templating functionality is defined by the Go language 'text/template' library. The library reference documentation can be found here, and there is a good primer document here. go-jira also provides a few extra helper functions to make it a bit easier to format the data, those functions are defined here.

Knowing what data and fields are available to any given template is not obvious. The easiest approach to determine what is available is to use the debug template on any given operation. For example to find out what is available to the "view" templates, you can use:

jira view GOJIRA-321 -t debug

This will print out the data in JSON format that is available to the template. You can do this for any other operation, like "list":

jira list -t debug

Authentication

Atlassian Cloud

For Atlassian Cloud hosted Jira API Tokens are now required. You will automatically be prompted for an API Token if your jira endpoint ends in .atlassian.net.

Quickstart API Token and Keychain
  1. Edit your config or execute the snippit (make sure to replace <SUBDOMAIN> and <EMAIL>)
export SUBDOMAIN="https://<SUBDOMAIN>.atlassian.net"
export EMAIL="<EMAIL>"
mkdir -p ~/.jira.d
printf "endpoint: $SUBDOMAIN\nuser: $EMAIL\npassword-source: keyring" > ~/.jira.d/config.yml
  1. Create a new API Token at id.atlassian.com
  2. Execute jira session and enter your API Token. jira will add your session to the keyring.

Private Jira Service

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/gopass service as documented below so that it can be programmatically 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.

The API Token authentication requires both the token and the email of the user. The email mut be set in the user: in your config.yml. Failure to provide the user will result in a 401 error.

If your Jira service still allows you to use the Session based authentication 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 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, pass or gopass.

Depending on how your private Jira service is configured, API tokens may require the "Bearer" authentication scheme instead of the traditional "Basic" authentication scheme. In this case, set the authentication-method: bearer-token property in your $HOME/.jira.d/config.yml file.

API token scheme authentication-method Example HTTP request header
Basic api-token Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQK
Bearer bearer-token Authorization: Bearer MY_TOKEN

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 relevant 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 accommodate 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:

user: person
login: [email protected]

You can also override these values on the command line with jira --user person --login [email protected]. 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). To integrate go-jira with a supported keyring just add this configuration to $HOME/.jira.d/config.yml:

password-source: keyring

After setting this and issuing a jira login, your credentials will be stored in your platform's backend (e.g. Keychain for Mac OS X) automatically. Subsequent operations, like a jira ls, should automatically login.

pass password source

An alternative to the keyring password source is the pass tool (documentation here). This uses gpg to encrypt/decrypt passwords on demand and by using gpg-agent you can cache the gpg credentials for a period of time so you will not be prompted repeatedly for decrypting the passwords. The advantage over the keyring integration is that pass can be used on more platforms than OSX and Linux, although it does require more setup. To use pass for password storage and retrieval via go-jira just add this configuration to $HOME/.jira.d/config.yml:

password-source: pass
password-name: jira.example.com/myuser

This assumes you have already setup pass correctly on your system. Specifically you will need to have created a gpg key like this:

$ gpg --gen-key

Then you will need the GPG Key ID you want associated with pass. First list the available keys:

$ gpg --list-keys
/home/gojira/.gnupg/pubring.gpg
-------------------------------------------------
pub   2048R/A307D709 2016-12-18
uid                  Go Jira <[email protected]>
sub   2048R/F9A047B8 2016-12-18

Then initialize the pass tool to use the correct key:

$ pass init "Go Jira <[email protected]>"

Now insert your password with the name you configured.

$ pass insert jira.example.com/myuser

You probably want to setup gpg-agent so that you don't have to type in your gpg passphrase all the time. You can get gpg-agent to automatically start by adding something like this to your $HOME/.bashrc

if [ -f $HOME/.gpg-agent-info ]; then
    . $HOME/.gpg-agent-info
    export GPG_AGENT_INFO
fi

if [ ! -f $HOME/.gpg-agent.conf ]; then
  cat <<EOM >$HOME/.gpg-agent.conf
default-cache-ttl 604800
max-cache-ttl 604800
default-cache-ttl-ssh 604800
max-cache-ttl-ssh 604800
EOM
fi

if [ -n "${GPG_AGENT_INFO}" ]; then
    nc  -U "${GPG_AGENT_INFO%%:*}" >/dev/null </dev/null
    if [ ! -S "${GPG_AGENT_INFO%%:*}" -o $? != 0 ]; then
        # set passphrase cache so I only have to type my passphrase once a day
        eval $(gpg-agent --options $HOME/.gpg-agent.conf --daemon --write-env-file $HOME/.gpg-agent-info --use-standard-socket --log-file $HOME/tmp/gpg-agent.log --verbose)
    fi
fi
export GPG_TTY=$(tty)

gopass password source

There is also the possibility to use gopass as a password source. gopass (like pass) uses gpg to encrypt/decrypt passwords. To use gopass for password storagte and retrieval via go-jira just add this configuration to $HOME/.jira.d/config.yml:

password-source: gopass
password-name: jira.example.com/myuser

For this to work, you need a working gopass installation.

To configure your gpg-agent to cache your gpg passphrase take a look at the pass section of the readme.

stdin password source

When password-source is set to stdin, the jira login command will read from stdin until EOF, and the bytes read will be the used as the password. This is useful if you have some other programmatic method for fetching passwords. For example, if password-generator creates a one-time password and prints it to stdout, you could use it like this.

$ ./password-generator | jira login --endpoint=https://my.jira.endpoint.com --user=USERNAME

Switch path used for password source

For gopass and pass it is possible to specify the full path for the password-source tool used for retrieval of the password. This can be accomplised by setting the password-source-path option in the configuration file.

E.g.

password-source: gopass
password-name: jira.example.com/myuser
password-source-path: /path/to/my-special-gopass

This will cause go-jira to use the gopass style cli interaction with the my-special-gopass binary.

If you ommit the password-source-path option, either gopass (for gopass) or pass (for pass) will be used.

jira's People

Contributors

arenstar avatar astrostl avatar bbaugher avatar bbkane avatar blachniet avatar blalor avatar codelingobot avatar colton22 avatar coryb avatar davidreuss avatar deepcube avatar georgettica avatar gvol avatar jaybuff avatar jgraglia avatar jshirley-stripe avatar keien avatar kerhac avatar kojustin avatar ldelossa avatar mbethke avatar mikepea avatar mivok avatar mvdan avatar nyarly avatar pcockwell avatar rvl avatar sylus avatar vanniktech avatar voiski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jira's Issues

jira add worklog + started time.

Hi there! Again many thanks for this awesome tool!

I think I read this in a related issue that adding the 'started' doesn't work for jira add worklog and wasn't needed anymore? I found it is actually useful if you immediately forget to file your issue after a task is done. I was hoping the following would work?

jira add worklog WCMS-2214 -m "Minor JIRA issues + upstream updates" \
                           -T "7h 30m" \
                           -o started="2017-01-29T09:17:00.000-0500" \
                           --noedit

Stock "edit" template doesn't escape or quote "special" characters

The stock 'edit' template doesn't do anything about special characters which means that you can't 'round-trip' an issue that has a summary containing something like Cool:: functions should be cool

I've not written any go before, if there's a particular escaping function that could be plugged into the template I'd gladly send a pull request, I just need some pointers for where to start!

Print Help when no parameters are provided

Calling jira without any parameters result in a runtime error. Recommend spitting out the help text or a clear usage message.

> jira
panic: runtime error: index out of range

goroutine 1 [running]:
main.main()
    /private/tmp/go-jira20151123-82731-1ttgffd/go-jira-0.0.14/src/github.com/Netflix-Skunkworks/go-jira/jira/main.go:220 +0x44bb

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    /usr/local/Cellar/go/1.5.1/libexec/src/runtime/asm_amd64.s:1696 +0x1

Ignore SSL errors

Working on a self-hosted jira installation with some misconfigured SSL certificate. Is there a way to ignore certificate checks?

RFE: Showing issues' related github commits

I was wondering whether you'd be willing to include support for retrieving github commits that are related to a JIRA Issue.

Connecting JIRA to github is outlined here but unfortunately the REST API to retrieve commit details is private/undocumented -- but nevertheless works fine.

As far as I can see this would require introduction of a 'static' schema -- would that be acceptable?
Ideally, listing tickets would allow optional inclusion of commits, merge status, peer review...
I'd happily try to work on it and create a PR but wanted to hear your general thoughts on this first.

btw, thanks a lot for go-jira. It already rocks :)

Creating sub-tasks doesn't work or is not obvious

I tried to create a sub-task without success. Would it be possible to update the documentation for this.

My template:

fields:
  project:
    key: FOOBAR
  issuetype:
    name: Sub-Task
  summary: {{ or .overrides.summary "" }}
  parent:
    key: FOOBAR-307
  priority:
    name: Low
  description: |~

  assignee:
    name:
  reporter:
    name: enricostahn

Error Message:

2017-02-13T13:19:23.274+11:00 ERROR [cli.go:421] Field parent is not editable
2017-02-13T13:19:23.274+11:00 ERROR [main.go:534] Field parent is not editable

Dumping all (populated) fields for a given issue

Howdy,

Is there a mechanism to dump all fields for a given issue? jira [ID] or jira view [ID] only appear to show a sub-set. Populated-only would be ideal, but even showing everything would be helpful for debugging. The specific use-case here is that I have a story issue which I know to have an associated epic, and I can see from jira fields that there are several epic-related fields which are visible to go-jira.

Thanks!

Authentication fails (password not stored/used?)

I'm using version 0.1.9 with a config in ~/.jira.d/config.yml:

endpoint: https://mycompany.atlassian.net
user: myname
password-source: keyring

Then I do jira login which seems to be fine but I can't see any entry being created in my keychain. Even when creating manually an entry under go-jira in the keychain it does not work.

On any request, I need to reenter my password, but the results seem empty:

$ jira -v DEV-1234
2017-02-01T00:07:06.720+01:00 INFO  [cli.go:195] GET https://mycompany.atlassian.net/rest/api/2/issue/DEV-1234
Jira Password [myname]: **************************************************
issue: <no value>
summary: <no value>
project: <no value>
reporter:
description: |

When typing the wrong password I see:

2017-02-01T00:17:00.800+01:00 WARNING [commands.go:68] Login failed

I can see that an authentication cookie is written to ~/.jira.d/cookies.js. It contains a JSESSIONID and has an expire of about 1 week.

Also no entry is added to my keychain (macOS) and even when I add the entry go-jira there myself, it has no visible effect.

Unable to rename file adding the .yml to the end on Windows

Attempting to create a Jira task, I run into the following error when executing jira create -i Request

C:\Users\user01
λ jira login
Enter Password for user01:

C:\Users\user01
λ jira issuetypes
Request:
Incident:
Sub-task:     The sub-task of the issue
Project:
Epic:         Created by JIRA Agile - do not edit or delete. Issue type for a big user story that needs to be broken down.
Task:         A task that needs to be done.

C:\Users\user01
λ jira create -i Task
2016-06-29T20:51:18.200-05:00 ERROR [cli.go:268] Failed to rename C:\Users\user01\.jira.d\tmp\create-task-063183995 to C:\Users\user01\.jira.d\tmp\create-task-063183995.yml: 
  rename C:\Users\user01\.jira.d\tmp\create-task-063183995 C:\Users\user01\.jira.d\tmp\create-task-063183995.yml: 
  The process cannot access the file because it is being used by another process.
2016-06-29T20:51:18.225-05:00 ERROR [main.go:455] rename C:\Users\user01\.jira.d\tmp\create-task-063183995 C:\Users\user01\.jira.d\tmp\create-task-063183995.yml: 
  The process cannot access the file because it is being used by another process.

I believe this is related to a GO function os.Rename() that has had some debate about functioning on Windows and POSIX systems.

Here are the links to the Code Line Numbers from the errors. The main.go error is just the error check, and I linked the create case statement.

Once again though, still working on the learning GO thing, so hopefully I can pitch in soon.

Windows Auth not working when adding watchers to Jira

I think the title is correct in this case. On Windows 7 64bit, I am trying to run a script that runs the jira.exe multiple times to add watchers since I cannot specify multiple of them in a single execution. I've had hit or miss success with when I'm not authenticated go-jira will ask for a password when using a shell script. So, sometimes when I forget to login first, I get the following error without much "simple" detail on what the actual issue excpet for me assuming that Username anonymous means I didn't login.

{"errorMessages":["Internal server error"],"errors":{}}
2016-11-22T09:56:26.577-05:00 ERROR [main.go:532] Unexpected Response From POST
2016-11-22T09:56:26.753-05:00 ERROR [cli.go:222] response status: 500 Internal Server Error
2016-11-22T09:56:26.753-05:00 ERROR [commands.go:598] Unexpected Response From POST:
HTTP/1.1 500 Internal Server Error
Connection: close
Cache-Control: no-cache, no-store, no-transform
Content-Type: application/json;charset=UTF-8
Date: Tue, 22 Nov 2016 14:56:27 GMT
Server: Apache-Coyote/1.1
X-Arequestid: 536x14049182x10
X-Asen: SEN-2245595
X-Ausername: anonymous
X-Content-Type-Options: nosniff

This happens on both the Linux version and Windows version. However, when I run the same thing again after logging in on Windows, I still receive the above error. On Linux the script then works without problem.

Windows Error output:

{"errorMessages":["Internal server error"],"errors":{}}
2016-11-22T08:45:21.744-06:00 ERROR [main.go:523] Unexpected Response From POST
2016-11-22T08:45:21.872-06:00 ERROR [cli.go:222] response status: 500 Internal Server Error
2016-11-22T08:45:21.872-06:00 ERROR [commands.go:598] Unexpected Response From POST:
HTTP/1.1 500 Internal Server Error
Connection: close
Cache-Control: no-cache, no-store, no-transform
Content-Type: application/json;charset=UTF-8
Date: Tue, 22 Nov 2016 14:45:21 GMT
Server: Apache-Coyote/1.1
X-Arequestid: 525x14028133x8
X-Asen: SEN-2245595
X-Ausername: anonymous
X-Content-Type-Options: nosniff

{"errorMessages":["Internal server error"],"errors":{}}
2016-11-22T08:45:21.873-06:00 ERROR [main.go:523] Unexpected Response From POST

The script being used to call the jira executable.

@echo off
set JIRA_ISSUE=%1
set USERNAME=user01

jira watch %JIRA_ISSUE% --watcher=%USERNAME%

and Linux Bash

JIRA_ISSUE=$1
USERNAME=user01

jira watch $JIRA_ISSUE --watcher=$USERNAME

add insecure option

For reasons I don't fully understand, yet, I'm unable to get Go to trust the CA that signed the certificate for my company's Jira installation. Having an --insecure-skip-verify config option would be useful (and probably for other folks, too).

CmdList is hardcoded to 500 results.

Noticed this whilst looking thru the commands.go

json, err := jsonEncode(map[string]interface{}{¬
     "jql":        query,
     "startAt":    "0",
     "maxResults": "500",
     "fields":     fields,
})

I know we have projects with more than this open, so it would be great to expose this as an option.

(NB: i plan to submit a PR for this!)

Authentication problem

  1. It asks me for password for current username on my system. Is there a way to specify email?
  2. After you exit from authentication prompt with Ctrl+C, input is frozen and I need to open new terminal

Ubuntu 15.10, used linux 64 bit binary from Releases

Saving cookies fails if ~/.jira.d is not present

If /etc/go-jira.yml is used to set the endpoint, then there is no reason for the user to create their ~/.jira.d directory manually.

This then leads to CmdLogin breaking, as it cannot save the cookies file:

2016-01-29T11:02:54.109Z ERROR [util.go:252] Failed to open /Users/mikepea/.jira.d/cookies.js: open /Users/mikepea/.jira.d/cookies.js: no such file or directory

Defining your own sub-commands?

New to go and this templating thing. Is it possible to define your own subcommands?

I would love to have jira sprint to run jira ls --query="sprint in openSprints() and project=ACME"

I tried to go with something like

case $JIRA_OPERATION in
  sprint)
    echo "wohoo"
    ;;
  list)
    echo "template: table"
    ;;
esac

but that fails.

Create subtask with Original Estimate

Is there a way within the subtask flow to specify a value for the original estimate?

In the jira api, this appears to be under a timetracking field which contains both originalEstimate and remainingEstimate, like this:
"timetracking": {
"originalEstimate": "10",
"remainingEstimate": "5"
}

I have tried a few things with overrides to see if I could get it to set, but it doesn't seem to work, presently.

optionally show the full URL of the issue with the list command

On OSX, if you use iTerm2, the terminal will detect URLs. If doing a jira list, it would be nice to be able to click on a issue without having to issue another command.

I have this working with jira -b list here: https://github.com/mlbright/go-jira/tree/ls-urls. I can open a PR if this is something that you would entertain.

My golang-fu is not the greatest so I'm not sure I'm handling the data with type assertions properly, but it works.

jira login does not ask for an account name just a password

The documentation says to authenticate myself I do the command

jira login

When I do all it asks for is a password. Seems to me that if should ask for my account name before it asks for my password.

To bad I can't get past this initial configuration glitch.... other than that looks like a nice feature complete CLI tool.

Not following keyring usage

Howdy, and thanks for the auth integrations inc. keyring.

https://github.com/Netflix-Skunkworks/go-jira/blob/master/README.md#authentication isn't clear to me in terms of usage, just pointing. Looking over at https://github.com/tmc/keyring and https://godoc.org/github.com/tmc/keyring isn't any more illuminating, as it seems to be focusing on the library rather than the end-user use case.

To start, I've set password-source: keyring in config.yml. Glancing at b8a6e57 , I would expect this to return an error. It instead prompts me for my password, then exits. Any general guidance on how to use keyring for the docs?

Command support for Scrum board commands

Howdy, loving the tool.

The Scrum board type (probably Kanban too, perhaps others) has three states: To Do, In Progress, Done. With spaces and caps, unfortunately. But these don't map to commands like jira resolve, nor are there discrete commands for things like jira done. I've worked around this by using jira trans with shell functions, but since this is a built-in board type, I think support in go-jira would be helpful.

Add worklog

Add worklog to log done work inside issues.

any way to use go-jira by passing a user name?

I can run gojira as whatever user Im logged in as on my linux box, and I can provide a password,

is there a way to run it as a different JIRA user thats not the same as your OS user? Can I pass a username somewhere?

Thanks.

login doesn't work

I'm sort of at a loss, I've tested my password on the web in a browser and it works, but i can't login from go-jira...any thing I can provide to help debug?

panic creating issue when createmeta returns empty issuetypes

> jira create 
panic: runtime error: index out of range

goroutine 1 [running]:
github.com/Netflix-Skunkworks/go-jira.(*Cli).CmdCreate(0xc820017e00, 0x0, 0x0)
    …/go-jira/src/github.com/Netflix-Skunkworks/go-jira/commands.go:236 +0xfc1
main.main()
    …/go-jira/main/main.go:338 +0x3be5

That corresponds to this line

Running that with a few -vs, I ended up with this:

>jira request '/rest/api/2/issue/createmeta?projectKeys=SYS&issuetypeNames=Bug&expand=projects.issuetypes.fields'
{
    "expand": "projects",
    "projects": [
        {
            "avatarUrls": {
                "16x16": "https://jira.example.com/secure/projectavatar?size=xsmall\u0026avatarId=10011",
                "24x24": "https://jira.example.com/secure/projectavatar?size=small\u0026avatarId=10011",
                "32x32": "https://jira.example.com/secure/projectavatar?size=medium\u0026avatarId=10011",
                "48x48": "https://jira.example.com/secure/projectavatar?avatarId=10011"
            },
            "expand": "issuetypes",
            "id": "10070",
            "issuetypes": [],
            "key": "SYS",
            "name": "Sysadmin",
            "self": "https://jira.example.com/rest/api/2/project/10070"
        }
    ]
}

empty jira response body cause jsonDecode failure when use CmdRequest

For example, POST to /rest/api/2/issueLink return nothing.
The request actually success, go-jira fail when parse response body which is nothing to json.

output:

2017-03-11T10:52:16.335+08:00 ERROR [util.go:247] JSON Parse Error: unexpected end of JSON input from
2017-03-11T10:52:16.336+08:00 ERROR [util.go:219] Failed to execute template: template: template:1:7: executing "template" at : wrong number of args for toJson: want 1 got 0
2017-03-11T10:52:16.336+08:00 ERROR [main.go:540] template: template:1:7: executing "template" at : wrong number of args for toJson: want 1 got 0

use default request template:

{{ . | toJson }}

Build instructions are wrong

The simple build instructions say to run:

git clone [email protected]:Netflix-Skunkworks/go-jira.git
cd go-jira
export GOPATH=$(pwd)
export GOBIN=$GOPATH/bin
export PATH=$GOBIN:$PATH
cd src/github.com/Netflix-Skunkworks/go-jira
go get -v

The second cd fails, as there's no src directory in the cloned repo.

make install not working for me on Mac

Howdy,

make clean && make works as expected.

make install yields the following:

/Applications/Xcode.app/Contents/Developer/usr/bin/make GOBIN=~/bin build
go build -v -ldflags "-X jira.VERSION=0.1.3 -w -s" -o '~/bin/jira' main/main.go
command-line-arguments

but no binary in ~/bin/ . ./jira works fine, though, and I can copy it over myself.

Could this be some kind of Go build env issue for my system?

Support for OAuth

Is there a way to get the client to work with jira instances that redirect to SSO/OAuth solutions?

My only thought is to grab my cookie from a valid oauth session and maybe use that in config.yml but I'm not sure that would work.

Wanted to ask here in case there's an existing way to make this work or something I'm not thinking of.

Cannot create issues with required custom fields

I'm trying to create issues with required custom fields. First I tried this figure out how go-jira sees the field:

-> ./go-jira create --dryrun -t debug --editor /bin/cat | less
... trim the output ...
"customfield_11348": {
"allowedValues": [
    {
        "id": "10310",
        "self": "https://jira.gsc.wustl.edu/rest/api/2/customFieldOption/10310",
        "value": "Account Management"
    },
... more output trimmed ...
    "hasDefaultValue": false,
    "name": "IT Service",
    "operations": [
        "set"
    ],
    "required": true,
    "schema": {
        "custom": "com.atlassian.jira.plugin.system.customfieldtypes:select",
        "customId": 11348,
        "type": "option"
    }
},
... more output trimmed ...

So now I want to set "customfield_11348" during creation. Each of these three possible attempts fail in the same way:

-> ./go-jira create -o summary=test -o "IT Service"="Account Management" --noedit
-> ./go-jira create -o summary=test -o "customfield_11348"="Account Management" --noedit
-> ./go-jira create -o summary=test -o "cf[11348]"="Account Management" --noedit

The error is:

{"errorMessages":[],"errors":{"customfield_11348":"IT Service is required."}}

How does one set custom fields?

panic when running commands via ssh

When I try to run a command I get the following error

panic: runtime error: slice bounds out of range

goroutine 1 [running]:
github.com/guelfey/go%2edbus.sessionBusPlatform(0x80f61e, 0x18, 0x0)
	/home/dn/git/go-jira/src/github.com/guelfey/go.dbus/conn_other.go:26 +0x1fd
github.com/guelfey/go%2edbus.SessionBusPrivate(0x8, 0x820470, 0xc42004be10)
	/home/dn/git/go-jira/src/github.com/guelfey/go.dbus/conn.go:99 +0xc0
github.com/guelfey/go%2edbus.SessionBus(0x0, 0x0, 0x0)
	/home/dn/git/go-jira/src/github.com/guelfey/go.dbus/conn.go:76 +0xc0
github.com/tmc/keyring.init.1()
	/home/dn/git/go-jira/src/github.com/tmc/keyring/keyring_linux.go:144 +0x34
github.com/tmc/keyring.init()
	/home/dn/git/go-jira/src/github.com/tmc/keyring/keyring_linux.go:162 +0xcb
gopkg.in/Netflix-Skunkworks/go-jira%2ev0.init()
	/home/dn/git/go-jira/src/gopkg.in/Netflix-Skunkworks/go-jira.v0/util.go:386 +0xb4
main.init()
	/home/dn/git/go-jira/main/main.go:612 +0x6e

Using current master (git commit e80d17d).
When issuing the same command not via ssh it works.

uname -a - Linux dn-VirtualBox 4.2.0-27-generic #32~14.04.1-Ubuntu SMP Fri Jan 22 15:32:26 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Moving tasks in structure

Feature request

It would be nice to have the ability to move a task to a story or to another task as a subtask in structure. Currently that functionality is missing as far as I'm concerned.

Project 'TEL' or issuetype 'Task' unknown. Unable to create issue.

I have set up my ~/.jira.d/config.yml and successfully logged in via jira login. However, when I try to create tickets, I get the following error:

$ jira create -p TEL -i Task
2017-05-22T10:40:14.998-07:00 ERROR [commands.go:443] Project 'TEL' or issuetype 'Task' unknown.  Unable to create issue.
2017-05-22T10:40:14.998-07:00 ERROR [main.go:557] Project 'TEL' or issuetype 'Task' unknown.  Unable to create issue.

Using the web interface I can confirm that there is a project with key TEL. I have also tried using the full name of the project:

$ jira create -p Teleop -i Task
2017-05-22T10:48:56.130-07:00 ERROR [commands.go:443] Project 'TELEOP' or issuetype 'Task' unknown.  Unable to create issue.
2017-05-22T10:48:56.130-07:00 ERROR [main.go:557] Project 'TELEOP' or issuetype 'Task' unknown.  Unable to create issue.

I have also tried:

$ jira create -p Teleop
2017-05-22T10:49:30.769-07:00 ERROR [commands.go:443] Project 'TELEOP' or issuetype '' unknown.  Unable to create issue.
2017-05-22T10:49:30.769-07:00 ERROR [main.go:557] Project 'TELEOP' or issuetype '' unknown.  Unable to create issue.
$ jira create -p TEL
2017-05-22T10:49:30.769-07:00 ERROR [commands.go:443] Project 'TEL' or issuetype '' unknown.  Unable to create issue.
2017-05-22T10:49:30.769-07:00 ERROR [main.go:557] Project 'TEL' or issuetype '' unknown.  Unable to create issue.

User password expiration

is there a way to store a logged in users creds indefinitely?

Im lookign at cookies.js and it has an expiration date for the provided password. Can I increase this range?

jira ls `POST` to search endpoint?

I'm trying to us this cli but am running into some issues.

It looks like doing an ls is trying to POST to an endpoint that to me seems like it should be a GET
jira ls -v

2017-02-07T22:40:09.585-05:00 INFO  [cli.go:179] POST https://notionai.atlassian.net/rest/api/2/search
2017-02-07T22:40:10.053-05:00 ERROR [cli.go:244] response status: 400 Bad Request
2017-02-07T22:40:10.053-05:00 ERROR [util.go:234] Field 'resolution' does not exist or this field cannot be viewed by anonymous users.
2017-02-07T22:40:10.053-05:00 ERROR [util.go:234] The value 'NOTION' does not exist for the field 'project'.
2017-02-07T22:40:10.053-05:00 ERROR [util.go:234] Not able to sort using field 'priority'.

add spenttime to issue

Hi,
is there any option to assign time to worklog in issue using this tool?
I try to play with edit command, but without success

thanks
Peter

support password in config.yml to work around WebSudo

Many Jira servers have WebSudo enabled which prevents Cookie based authentication from working and requires a username/password on every request. To support this go-jira should allow a password property in the $HOME/.jira.d/config.yml file, and allow for JIRA_PASSWORD environment variable to be used.

For security/safety we will need to validate that $HOME/.jira.d/config.yml has secure file permissions (600).

If a Jira admin wants to disable requiring WebSudo they can follow the instructions here:
https://answers.atlassian.com/questions/51786/turn-off-administrator-access-login

default edit template is problematic

The standard permissions set on our Jira instance do not allow for update of reporter. I'm fairly confident this will be a commonplace limitation for unprivileged users.

This means that every 'edit' operation initially fails with:

{"errorMessages":[],"errors":{"reporter":"Field 'reporter' cannot be set. It is not on the appropriate screen, or unknown."}}

I appreciate that a custom edit template can be provided to remove this, but in my mind it makes more sense for the default edit template to fit a lower common denominator.

go-jira cannot be used as a library.

I'd like to use the core logic and API abstraction provided in go-jira to create an ncurses style JIRA browser, but AIUI the way it's written right now prevents this: CmdList et al produce output, rather than data.

I previously have made a branch that split the API requests and output logic, so this should be possible and relatively straightforward. Just wanted to check with you that this would be something you'd be interested in, before I whack together a reasonable sized PR.

'Pass' authentication asks for passwords for every command

I've set up pass as an authentication method, and use jira login which asks for a password and appears to work.

Then I do jira list and it asks for a password again... and for every command. The command works when I enter the password but asks every single time. Not sure what I've done wrong as I've followed every step in the README for the set-up for this. Any ideas?

mistyping password does not give Authentication Failed error.

Awesome, Jira gives you an HTTP 200 when you provide bad u/p:

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Cache-Control: no-cache, no-store, no-transform
Content-Type: application/json;charset=UTF-8
Date: Thu, 19 Feb 2015 00:53:58 GMT
Server: Apache-Coyote/1.1
X-Arequestid: 53x17037965x1
X-Asen: SEN-2062203
X-Asessionid: 14tags9
X-Ausername: jaybuff
X-Content-Type-Options: nosniff
X-Seraph-Loginreason: AUTHENTICATION_DENIED

fd
{"self":"https://issues.apache.org/jira/rest/api/latest/user?username=jaybuff","name":"jaybuff","loginInfo":{"failedLoginCount":12,"loginCount":240,"lastFailedLoginTime":"2015-02-19T00:53:59.600+0000","previousLoginTime":"2015-02-19T00:09:15.895+0000"}}
0

jira.exe unable to read %HOME%\.jira.d\config.yml

I seem to be having an issue where the jira.exe executable is unable to find the %HOME%\.jira.d\config.yml file.

C:\Users\user01\Downloads
λ jira-windows-amd64.exe
2016-04-22T17:36:08.031-05:00 ERROR [main.go:270] endpoint option required.  Either use --endpoint or set a endpoint option in your ~/.jira.d/config.yml file

I have created the %HOME%\.jira.d\config.yml and at least put endpoint: in there. When I specify the command line arguments, it works as expected.

I am using Windows 7 with Go 1.6

C:\Users\user01
λ go version
go version go1.6 windows/amd64

400 Bad Request

my company is using the cloud version of jira. our url is: https://my-company.atlassian.net
so have a single line in config.yml:

endpoint: https://my-company.atlassian.net
jira ls -u=my-name -p=my-project

ERROR [cli.go:163] response status: 400 Bad Request
ERROR [util.go:196] Field 'resolution' does not exist or this field cannot be viewed by anonymous users.
ERROR [util.go:196] The value '=SANGRE' does not exist for the field 'project'.
ERROR [util.go:196] Not able to sort using field 'priority'.

any idea what could it be? Also, I couldn't find a password arguments in the --help or the readme.

Thanks!

Missing package go-jira/data

I cloned a copy of the repo (tag is v0.1.4) and when running make I get a failure with the following message:

src/github.com/Netflix-Skunkworks/go-jira/commands.go:8:2: cannot find package "github.com/Netflix-Skunkworks/go-jira/data"

It looks like the data subdirectory is missing from this repo.

if create template is not saved, consider the create aborted

If I run "jira create" then do not save my changes, the client should not attempt to POST to jira or offer me the option to edit again.

Right now, I get this output after I do ":q!" in vi:

2015-02-18T11:25:40.059-08:00 INFO  [cli.go:105] POST https://issues.apache.org/jira/rest/api/2/issue
2015-02-18T11:25:40.111-08:00 ERROR [cli.go:158] response status: 400 Bad Request
2015-02-18T11:25:40.111-08:00 ERROR [commands.go:290] Unexpected Response From POST:
HTTP/1.1 400 Bad Request
Connection: close
Transfer-Encoding: chunked
Cache-Control: no-cache, no-store, no-transform
Content-Type: application/json;charset=UTF-8
Date: Wed, 18 Feb 2015 19:25:37 GMT
Server: Apache-Coyote/1.1
X-Arequestid: 1165x16501598x2
X-Asen: SEN-2062203
X-Asessionid: 14tags9
X-Ausername: jaybuff
X-Content-Type-Options: nosniff
X-Seraph-Loginreason: OK

75
{"errorMessages":[],"errors":{"project":"project is required","issuetype":"Could not find issuetype by id or name."}}
0

2015-02-18T11:25:40.111-08:00 ERROR [cli.go:303] Unexpected Response From POST
edit again? [Y/n]: n

Transition not updating comments

Howdy,

When I jira trans "Done" ID, I get an expected

update:
  comment:
    - add:
        body: |~

fields:
transition:
  id: 31
  name: Done

While the transition is successful, any comments put into the comment body don't appear anywhere in the JIRA GUI (Activity/All). I know this is a "custom" (default Scrum board) transition to a "Done" status, but aren't the comments a generic property of issues?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.