Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharing some Custom Commands #455

Open
AlJohri opened this issue Dec 26, 2021 · 0 comments
Open

Sharing some Custom Commands #455

AlJohri opened this issue Dec 26, 2021 · 0 comments

Comments

@AlJohri
Copy link

AlJohri commented Dec 26, 2021

Hi all, I wanted to just share some custom commands that I pieced together and found useful since documentation was a little hard to come by. I'm using like 0.1% of what this tool has to offer but its proven useful nonetheless.

  1. Create/Edit Jira Ticket using Browser (instead of $EDITOR)

    This opens the browser to the CreateIssueDetails page with several fields pre-populated to make it easier to create tickets without forgetting to add a component, epic, etc.

    Usages: jira qc,jira qc --component1, jira qc --epic PROJ-1234, jira qc --component1 --component2 --summary "this is the title"

    For epics or sprints, check which custom field ID you're using by running: jira createmeta | jq '.fields'. Edit the board name, component id, sprint field name, and epic field name below:

    - name: quick-create
      aliases:
          - qc
      help: quick create jira ticket using web ui
      options:
        - name: type
          default: 3
        - name: priority
          default: 3
        - name: summary
          default: Title
        - name: reporter
          default: $(whoami)
        - name: component1
          type: BOOL
          default: false
        - name: component2
          type: BOOL
          default: false
        - name: epic
    
      script: |
        board_name="!!YOUR BOARD NAME HERE!!"
        board_id=$({{jira}} req "/rest/agile/1.0/board?projectKeyOrId=$JIRA_PROJECT&name=$board_name" --gjq values.0.id)      
        project_id=$({{jira}} req "/rest/agile/1.0/board/$board_id/project/" --gjq values.0.id)      
        sprint_id=$({{jira}} req "/rest/agile/1.0/board/$board_id/sprint?state=active" --gjq values.0.id)
    
        echo "Creaing issue on project $JIRA_PROJECT ($project_id), board $board_name ($board_id), sprint $sprint_id"
    
        url="https://issues.labcollab.net/secure/CreateIssueDetails%21init.jspa?"
        url+="pid=$project_id"
        url+="&customfield_10227=$sprint_id"
        url+="&reporter={{options.reporter}}"
        url+="&issuetype={{options.type}}"
        url+="&summary={{options.summary}}"
        url+="&priority={{options.priority}}"
    
        if [[ "{{ options.component1 }}" == "true" ]]; then
          url+="&components=!!COMPONENT1_IDHERE!!"
        fi
    
        if [[ "{{ options.component2 }}" == "true" ]]; then
          url+="&components=!!COMPONENT2_IDHERE!!"
        fi
    
        if [[ "{{ options.epic }}" != "<no value>" ]]; then
          url+="&customfield_10600=key:{{ options.epic }}"
        fi      
    
        echo "\nURL: $url"
        open "$url"

    Thanks to @coryb for this comment: True life custom commands samples #230 (comment).

  2. Open Named Query using FZF

    Opens a named query using FZF to create a text user interface. You can easily search through issues and use your arrow keys or mouse to click on different issues and see them populate in the sidebar on the right.

    Requires: brew install fzf.

    - name: ls-named-query-fzf
      aliases:
        - lf
      help: ls with named queries using fzf interface
      args:
        - name: query
      script: |
        {{jira}} ls -n {{args.query}} | \
          fzf --preview="echo {} | cut -d : -f 1 | xargs -I % sh -c 'jira view %'"
    

    Credit goes to @itai-stratoscale from tig like interface? #156 (comment).

  3. Auth via Cookies for private Jira.

    Run jira a to grab Jira cookies from Chrome to authenticate with difficult private Jira's behind SSO.

    Requires: brew install jq and pip3 install --user get-browser-cookies.

    - name: auth
      aliases:
        - a
      help: authenticate to jira using cookies
      script: |
        get-browser-cookies \
          --browser chrome \
          --domain !!YOUR_JIRA_DOMAIN_HERE!! | \
          jq 'select(.value | contains("\"") | not)' | \
          jq '{
            "Name": .name,
            "Value": .value,
            "Path": .path,
            "Domain": .domain,
            "Expires": .expires,
            "Secure": .secure}' | \
          jq -s '.' > ~/.jira.d/cookies.js

    Thanks to the folks in Self-hosted Jira behind Okta #241 for the idea. Looks like the folks in Ability to use JSESSION token from Cookie for self-hosted JIRA installs? #231 came to a similar approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant