-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: automated moving of completed jira workflows
Made acording to this request: https://issues.redhat.com/projects/PERFINFRA/issues/PERFINFRA-98w Change-Id: Idbdc09e026bb64f0d11ea8f13da45f83fbde49fa
- Loading branch information
1 parent
1af1897
commit 53586f0
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python3 | ||
import asyncio | ||
import logging | ||
import sys | ||
|
||
from quads.model import Cloud | ||
from jira import Jira, JiraException | ||
from quads.config import Config | ||
|
||
logger = logging.getLogger(__name__) | ||
logging.basicConfig(level=logging.INFO, format="%(levelname)s - %(message)s") | ||
|
||
|
||
async def main(_loop): | ||
try: | ||
jira = Jira( | ||
Config["jira_url"], | ||
loop=_loop, | ||
) | ||
except JiraException as ex: | ||
logger.error(ex) | ||
return 1 | ||
|
||
all_pending_tickets = await jira.get_all_pending_tickets() | ||
all_pending_tickets = all_pending_tickets["issues"] | ||
jira_ticket_keys = [] | ||
for ticket in all_pending_tickets: | ||
ticket_key = ticket.get("key").split("-")[-1] | ||
fields = ticket.get("fields") | ||
parent = fields.get("parent") | ||
if parent is None: | ||
jira_ticket_keys.append(ticket_key) | ||
|
||
clouds = Cloud.objects() | ||
cloud_ticket_keys = [cloud.ticket for cloud in clouds] | ||
expired_keys = [key for key in jira_ticket_keys if key not in cloud_ticket_keys] | ||
|
||
for ticket_key in expired_keys: | ||
transitions = await jira.get_transitions(ticket_key) | ||
transition_result = False | ||
for transition in transitions: | ||
t_name = transition.get("name") | ||
if t_name and t_name.lower() == "done": | ||
transition_id = transition.get("id") | ||
transition_result = await jira.post_transition(ticket_key, transition_id) | ||
break | ||
|
||
if not transition_result: | ||
logger.warning(f"Failed to update ticket status, ticket key {ticket_key}, SKIPPING.") | ||
|
||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
loop = asyncio.get_event_loop() | ||
err = loop.run_until_complete(main(loop)) | ||
sys.exit(err) |