go-jira

repository·master·Indexed 25 days ago

https://github.com/go-jira/jira

A context-aware command-line interface for interacting with Jira. It features a hierarchical configuration system via .jira.d directories, shell-scriptable custom commands, and customizable output using Go's text/template library. The tool supports Atlassian Cloud authentication via API tokens and integrates with various password sources including system keyrings, pass, and gopass.

Tokens
7.3K
Snippets
17
Records
58
Agent score
83%

What's inside go-jira

  1. Customize Output with Templates

    master

    go-jira uses Go's text/template library for output and editor input.

    1. Customizing a command: Create a file at .jira.d/templates/<command_name> (e.g., .jira.d/templates/edit).
    2. Exporting defaults: Run jira export-templates to write the hard-coded default templates to ~/.jira.d/templates/.
    3. Debugging templates: Use the debug flag to see the JSON data available to a template: jira view GOJIRA-321 -t debug or jira list -t debug.
  2. Use Dynamic Configuration with executable files

    master

    If a .jira.d/config.yml file is executable, go-jira will execute it and use its stdout as the configuration. This allows for dynamic overrides based on the $JIRA_OPERATION environment variable.

    Example: Using a shell script to set a specific template when running the list command:

    #!/bin/sh
    
    echo "endpoint: https://jira.mycompany.com"
    echo "editor: emacs -nw"
    
    case $JIRA_OPERATION in
        list)
          echo "template: table";;
    esac
    #!/bin/sh
    
    echo "endpoint: https://jira.mycompany.com"
    echo "editor: emacs -nw"
    
    case $JIRA_OPERATION in
        list)
          echo "template: table";;
    esac
  3. Set up the Jira Docker test environment

    master

    The tests require a Jira service running in a Docker container. You must manually run the setup script to initialize the test instance. Note that the test instance uses a temporary license (approximately 8 hours), so you will need to re-run the setup script at least once daily.

    ./000setup.t
  4. Configure go-jira using the configuration hierarchy

    master

    go-jira uses a hierarchical configuration system. It recursively searches parent directories for a .jira.d directory, starting from your current working directory and moving up to your home directory.

    1. Command-specific config: It loads <command>.yml from .jira.d/ (e.g., jira list loads .jira.d/list.yml).
    2. Global/Context config: It merges properties from config.yml found in those directories.
    3. Precedence: Files closer to the current working directory take precedence over parent directories. Command-line options have the final precedence.

    You can set context-aware projects by creating ./.jira.d/config.yml in a project workspace:

    project: foo
  5. Configure TAB completion for go-jira

    master

    Since go-jira uses the kingpin library, it supports automatic bash/zsh shell completion. To enable tab completion in bash, add the following line to your .bashrc or .profile (ensure the jira binary is already in your PATH):

    eval "$(jira --completion-script-bash)"
    eval "$(jira --completion-script-bash)"
  6. Install go-jira

    master

    You can install go-jira by either downloading pre-built binaries or building from the source code using Go.

    Download

    Download pre-built binaries from the official releases page.

    Build from source

    To build and install the official repository, ensure GO111MODULE=on is set in your environment, then run:

    go get github.com/go-jira/jira/cmd/jira

    After installation, the binary will be available in $GOPATH/bin/jira.

    go get github.com/go-jira/jira/cmd/jira
  7. Use --login instead of --user for GDPR compliance

    master

    Due to GDPR restrictions, the --user parameter is being phased out in favor of the --login option.

    Commands that previously required a username (such as watch, create, or assign) now expect an email address. When using these commands, use the --login flag instead of --user to ensure compatibility with modern Atlassian API requirements.

  8. Run integration tests

    master

    The integration tests are written using the osht bash testing framework. To run the tests, you must first ensure a Jira service is running via Docker by executing the setup script.

    From the top level of the project, use make to build the local jira binary and prove to run the integration tests located in the _t directory.

  9. Authenticate with Atlassian Cloud

    master

    Atlassian Cloud requires API Tokens. If your endpoint ends in .atlassian.net, you will be prompted for a token.

    Setup Steps:

    1. Configure your endpoint and email in ~/.jira.d/config.yml:
      mkdir -p ~/.jira.d
      printf "endpoint: https://<SUBDOMAIN>.atlassian.net\nuser: <EMAIL>\npassword-source: keyring" > ~/.jira.d/config.yml
    2. Create an API Token at id.atlassian.com.
    3. Run jira session and enter your API Token. This stores the session in your system keyring.

    Note on User vs Login:

    • user: The username used for Jira API calls (e.g., issue assignment).
    • login: The identity used for authentication (e.g., email address).

    Example config:

    user: person_username
    login: person@example.com
    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
  10. Use Atlassian SDK commands for plugin development

    master

    When developing Atlassian plugins, use the following SDK commands to manage the plugin lifecycle and debugging:

    • atlas-run: Installs the plugin into the product and starts it on localhost.
    • atlas-debug: Installs the plugin and starts it on localhost, but also allows a debugger to attach at port 5005.
    • atlas-cli: Opens a Maven command line window after running atlas-run or atlas-debug. Inside this window, you can use the pi command to reinstall the plugin into the running product instance.
    • atlas-help: Prints descriptions for all available commands in the SDK.
    atlas-run
    atlas-debug
    atlas-cli
    atlas-help
  11. Use the go-jira CLI

    master
    The go-jira CLI is a command-line interface for interacting with Jira. It uses a configuration directory named .jira.d located in your home directory. The CLI supports configuration via environment variables with the prefix JIRA_ and uses a cookie file for session management located at ~/.jira.d/cookies.js.