This post describes how to bulk add a link to issues in Jira using the API. This a draft/wip version. Comment if you want me to finalize it.
Problem Description
It is not possible in Jira to bulk edit multiple issues to add a link.
Workaround via Jira REST API
To workaround this missing feature in the UI you can use a scripted solution based on the Jira REST API.
You need to make a POST rest api call as shown in the example below:
{
"type": {
"name": "Duplicate"
},
"inwardIssue": {
"key": "HSP-1"
},
"outwardIssue": {
"key": "MKY-1"
}
}
To set a link between two issues you need to know which issue is on the inward side and which is on the outward side given the Link name you want to use. This logic need to be coded to find out the proper linking.
This is done in this part of the code:
; Get Link definition
sRootUrl := Jira_IssueKey2RootUrl(inwardIssueKey)
sUrl := sRootUrl . "/rest/api/2/issueLinkType"
sResponse:= Jira_Get(sUrl, sBody)
Json := Jxon_Load(sResponse)
JsonLinks := Json["issueLinkTypes"]
; Shorten LinkName matching
sPat:= StrReplace(sLinkName," ","[^\s]*\s")
sPat := RegExReplace(sPat,"\s$") ; remove trailing \s
sPat := "i)^" . sPat . "[^\s]*" ; case insensitive, start with
; Loop on Links to find the relevant one and direction
For i, link in JsonLinks
{
If RegExMatch(link["inward"],sPat,sMatch) { ;(l["inward"] = sLinkName)
If !(StrLen(sMatch) = StrLen(link["inward"])) ; full match only
continue
inwardIssueKey := tgtIssueKey
outwardIssueKey := srcIssueKey
linkName := link["name"]
Break
}
If RegExMatch(link["outward"],sPat,sMatch) {
If !(StrLen(sMatch) = StrLen(link["outward"])) ; full match only
continue
inwardIssueKey := srcIssueKey
outwardIssueKey := tgtIssueKey
linkName := link["name"]
Break
}
}
AutoHotkey Implementation
For a better usability, the script supports shortened link names This means you can stop the word before its end but need to provide the right number of words that matches the link name.
Example: 'is r b' will match the link name 'is reused by'.
The full code is available in the GitHub repository->
Lib/Jira.ahkPart of the code implementing this Add Link feature is extracted in the Gist below:
Usage
Source Issues
Source issues are taken out of the current context:
- In the browser from the current url
- Jira detailed issue view
- Jira filter with multiple keys
- R4J tree view
- This works also from a bulk edit view triggered from the R4J Tree selection
- Excel: from the current select. Key is found intelligently as in the Open Issue feature
- (other application) From the selection, any selected text will be parsed by issue keys
Target Issues
You can enter any text that contains issue keys including multiple one; the text will be parsed by issue keys.
Link name
You will be prompted to enter the link name with which you want to create the link. The link name is a inward or outward link name. For example 'satisfies' or 'is satisfied by'.
Confirmation Question Dialog
Before the links are creates you will be prompted for confirmation.
The link name is confirmed as well as the inward and outward issue keys. The order might look reverse to you depending on the link direction you have entered.
Result
In the notification area you will have a notification about the links that were created by the PowerTool.
See also
No comments:
Post a Comment