4 ms·
Yes, exactly that. Basically wire up very simple commands with curl and jq that do the transitions you need, pulling data from other rest apis as necessary. Th
by JoshuaDavid 6y ago
Yes, exactly that. Basically wire up very simple commands with curl and jq that do the transitions you need, pulling data from other rest apis as necessary.
The two workhorses of my integration are two methods named jira_get and jira_post.
function jira_get {
ENDPOINT="$1"
PAYLOAD="$2"
URL="https://your-org.atlassian.net/rest/api/2/$ENDPOINT"
QUERY_STRING="$(jq --null-input --raw-output --argjson x "$PAYLOAD" '$x|[to_entries[]|((.key|@uri)+"="+(.value|@uri))]|join("&")')"
curl \
--silent \
--request "GET" \
--header "Content-Type: application/json" \
--user "$JIRA_USER:$JIRA_TOKEN" \
"$URL?$QUERY_STRING";
}
function jira_post {
ENDPOINT="$1"
PAYLOAD="$2"
URL="https://your-org.atlassian.net/rest/api/2/$ENDPOINT"
QUERY_STRING="$(jq --null-input --raw-output --argjson x "$PAYLOAD" '$x|[to_entries[]|((.key|@uri)+"="+(.value|@uri))]|join("&")')"
curl \
--silent \
--request "POST" \
--user "$JIRA_USER:$JIRA_TOKEN" \
--header "Content-Type: application/json" \
"$URL" \
--data "$PAYLOAD";
}
Then if you want to get the available transitions, and required fields for those transitions, you can do
ISSUE=PRJ-1234
ISSUE_JSON="$(jira_get "issue/$ISSUE/transitions" '{"expand":"transitions.fields"}'
TRANSITION_NAMES="$(echo "$ISSUE_JSON" | jq '.transitions[].name')"
and then given the transition in question, you can look at the fields required for the transition, and figure out where you get the data that goes in those fields normally. Any time the data that goes in those fields is obtained through a rote process, you automate that process, and then prompt for any fields you can't get in an automated fashion (e.g. "signed off by" you can fetch the reviewer names from the github api for the associated pull request).
But yeah, a slack bot that issues requests to the JIRA api is a perfectly workable solution, and I think you'd be surprised at how much of a quality of life improvement you'll get by continuing to add capabilities to it that reflect your specific workflow.