Skip to content

Commit

Permalink
Multithreading in linking multiple issues (#66)
Browse files Browse the repository at this point in the history
* Changed the linking of multiple issue functianlity with usage of multithreading to speed up the results

* Formatted code

* Change log modified to minor version instead of patch version

* Changed pack version

* Added inward and outward keys in output for better debug

* Code formatting
  • Loading branch information
karamveer28 authored Oct 20, 2023
1 parent 7ba2014 commit 6ee14d3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 2.5.0

- Added multithreading in linking multiple issue functionality to speed up the response.

## 2.4.2

- Update `formatters.py` to include `priority` field
Expand Down
61 changes: 45 additions & 16 deletions actions/bulk_link_issue.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,50 @@
import threading
from threading import Semaphore
from lib.base import BaseJiraAction

__all__ = [
'BulkLinkJiraIssueAction'
]


class BulkLinkJiraIssueAction(BaseJiraAction):
def link_issues(
self,
semaphore,
issue_key=None,
target_issue=None,
direction=None,
link_type=None,
):
with semaphore:
outward_issue_key = ""
inward_issue_key = ""
if direction == "outward":
outward_issue_key = issue_key
inward_issue_key = target_issue
response = self._client.create_issue_link(
link_type, inward_issue_key, outward_issue_key
)

if direction == "inward":
inward_issue_key = issue_key
outward_issue_key = target_issue
response = self._client.create_issue_link(
link_type, inward_issue_key, outward_issue_key
)
response_output = {
"inward_issue": inward_issue_key,
"outward_issue": outward_issue_key,
"response": response,
}
print(response_output)

def run(self, issue_key_list, target_issue, direction, link_type):
threads = list()
semaphore = Semaphore(10)
for issue_key in issue_key_list:
x = threading.Thread(
target=self.link_issues,
args=(semaphore, issue_key, target_issue, direction, link_type),
)
threads.append(x)
x.start()

def run(self, issue_key_list=None, target_issue=None, direction=None, link_type=None):
if direction == 'outward':
inward_issue_key = target_issue
for outward_issue_key in issue_key_list:
issue = self._client.create_issue_link(link_type, inward_issue_key,
outward_issue_key)
if direction == 'inward':
outward_issue_key = target_issue
for inward_issue_key in issue_key_list:
issue = self._client.create_issue_link(link_type, inward_issue_key,
outward_issue_key)
return issue
for thread in threads:
thread.join()
2 changes: 1 addition & 1 deletion actions/bulk_link_issue.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ parameters:
type: string
description: The type of link to create.
required: true
default: relates
default: relates to
1 change: 1 addition & 0 deletions actions/link_issue.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ parameters:
type: string
description: The type of link to create.
required: true
default: relates to
2 changes: 1 addition & 1 deletion pack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ keywords:
- issues
- ticket management
- project management
version: 2.4.2
version: 2.5.0
python_versions:
- "3"
author : StackStorm, Inc.
Expand Down

0 comments on commit 6ee14d3

Please sign in to comment.