go-jira / jira

simple jira command line client in Go
Apache License 2.0
2.68k stars 328 forks source link

Question: Assign issue to Sprint #135

Closed BrendanThompson closed 6 years ago

BrendanThompson commented 6 years ago

Hi All,

Just wondering what is the best way to go about assigning an issue to a sprint? Currently I'm not able to do this.

Thanks,

Brendan

coryb commented 6 years ago

I have not added this functionality to go-jira because the REST apis are pretty fussy to do this seemingly trivial operation. The basic steps are: 1) identify sprint board id 2) identify active sprint id for given board id 3) assign issues to sprint id

You can do these operations on the command line using the jira request command, something like this:

board_id=$(jira req "/rest/agile/1.0/board?projectKeyOrId=$JIRA_PROJECT" --gjq values.0.id)
sprint_id=$(jira req "/rest/agile/1.0/board/$board_id/sprint?state=active" --gjq values.0.id)
jira req -M POST "/rest/agile/1.0/sprint/$sprint_id/issue" "{\"issues\":[\"ISSUE-123\"]}"
coryb commented 6 years ago

It is a bit fussy because the --gjq filters may not be correct for you if your project has multiple boards, or multiple active sprints. This filters above assume you have one board and one active sprint, or at least the filters only return the first board/sprint found.

You can attempt to wrap the above commands in a custom-command that would look something like this in your .jira.d/config.yml:

custom-commands:
  - name: sprint-add
    help: add issue to active sprint for project
    args:
      - name: ISSUE
        required: true
    script: |
      board_id=$({{jira}} req "/rest/agile/1.0/board?projectKeyOrId=$JIRA_PROJECT" --gjq values.0.id)
      sprint_id=$({{jira}} req "/rest/agile/1.0/board/$board_id/sprint?state=active" --gjq values.0.id)
      {{jira}} req -M POST "/rest/agile/1.0/sprint/$sprint_id/issue" "{\"issues\":[\"{{args.ISSUE}}\"]}"

Then you can run jira sprint-add ISSUE-123 assuming you have project: someproject configured in your .jira.d/config.yml.

danaelhe commented 3 years ago

It is a bit fussy because the --gjq filters may not be correct for you if your project has multiple boards, or multiple active sprints. This filters above assume you have one board and one active sprint, or at least the filters only return the first board/sprint found.

You can attempt to wrap the above commands in a custom-command that would look something like this in your .jira.d/config.yml:

custom-commands:
  - name: sprint-add
    help: add issue to active sprint for project
    args:
      - name: ISSUE
        required: true
    script: |
      board_id=$({{jira}} req "/rest/agile/1.0/board?projectKeyOrId=$JIRA_PROJECT" --gjq values.0.id)
      sprint_id=$({{jira}} req "/rest/agile/1.0/board/$board_id/sprint?state=active" --gjq values.0.id)
      {{jira}} req -M POST "/rest/agile/1.0/sprint/$sprint_id/issue" "{\"issues\":[\"{{args.ISSUE}}\"]}"

Then you can run jira sprint-add ISSUE-123 assuming you have project: someproject configured in your .jira.d/config.yml.

Does this still work for anybody? Running into the following error: ERROR Invalid Usage: JSON Parse Error: invalid character '<' looking for beginning of value

msummers42 commented 2 years ago

Does this still work for anybody? Running into the following error: ERROR Invalid Usage: JSON Parse Error: invalid character '<' looking for beginning of value

Hi @danaelhe , I do have this working but I hard-coded my project key (i.e. ENG or whatever) in place of $JIRA_PROJECT. It think it might be nicer to make it an arg instead.

Thanks for posting this @coryb , it saved me a fair bit of time!