Skip to content

Instantly share code, notes, and snippets.

@shorti1996
Created January 28, 2020 11:45
Show Gist options
  • Save shorti1996/b384148f66d98505e88633cc9cf2a950 to your computer and use it in GitHub Desktop.
Save shorti1996/b384148f66d98505e88633cc9cf2a950 to your computer and use it in GitHub Desktop.
JIRA close subtasks
#!python3
import ctypes
import getpass
import re
from jira import JIRA
ctypes.windll.kernel32.SetConsoleTitleW("JIRA subtask closer")
# region settings
story_key = "xxx"
login = "xxx"
# endregion
user_to_assign_to = login
options = {"server": "https://jira.xxx.net/"}
print(f"Hello, {login}")
jira_password = getpass.getpass("Enter your Jira user password: ")
print("Logging in...")
jira = JIRA(options=options, basic_auth=(login, jira_password))
del jira_password
in_story_key = input("Enter story key: ")
if in_story_key == "":
in_story_key = story_key
print(f"Fetching subtasks of {in_story_key}")
issue = jira.issue(in_story_key)
# "[DEV]" in summary
dev_tasks = [subtask for subtask in issue.fields.subtasks if re.search("\[DEV\].*", subtask.fields.summary)]
# without "[QA]" in summary
dev_tasks = [subtask for subtask in dev_tasks if re.search("^((?!\[QA\]).)*$", subtask.fields.summary)]
# not "closed"
dev_tasks = [subtask for subtask in dev_tasks if subtask.fields.status.name != "Closed"]
print(f"Assign to {user_to_assign_to} and close:")
[print(f"\t{subtask.key} {subtask.fields.summary}") for subtask in dev_tasks]
input("Press ENTER ⏎ to continue...")
fixed_completed_resolution = \
[resolution.id for resolution in jira.resolutions() if resolution.name == "Fixed / Completed"][0]
[jira.transition_issue(subtask, "Close", assignee={'name': user_to_assign_to},
resolution={'id': fixed_completed_resolution}) for subtask in dev_tasks]
print("👍 DONE 🤙")
input()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment