-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
79 lines (62 loc) · 2.94 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import math
import subprocess
import textwrap
import lib.config as cfg
from lib.jiralist import JiraList
def prepare_text_for_new_issue(issue):
header = "~~~ TASK ENTERED SPRINT ~~~".center(cfg.PAGE_WIDTH)
task = textwrap.fill(f"{issue.key} {issue.fields.summary}", width=cfg.PAGE_WIDTH)
details = textwrap.fill(f"Reporter: {issue.fields.creator}", width=cfg.PAGE_WIDTH) + "\n" + \
textwrap.fill(f"Priority: {issue.fields.priority}", width=cfg.PAGE_WIDTH)
footer = "~~~ DO IT NOW ~~~".center(cfg.PAGE_WIDTH)
full_text = "\n".join([header, task, details, footer])
line_count = full_text.count("\n")
top_pad = "\n" * math.floor((cfg.PAGE_HEIGHT - line_count) / 2.0)
padded_text = top_pad + full_text
return padded_text
def prepare_text_for_issue_with_new_pr(issue):
header = "~~~ TASK HAS NEW PR ~~~".center(cfg.PAGE_WIDTH)
task = textwrap.fill(f"{issue.key} {issue.fields.summary}", width=cfg.PAGE_WIDTH)
details = textwrap.fill(f"Assignee: {issue.fields.assignee}", width=cfg.PAGE_WIDTH) + "\n" + \
textwrap.fill(f"Reporter: {issue.fields.creator}", width=cfg.PAGE_WIDTH) + "\n" + \
textwrap.fill(f"Priority: {issue.fields.priority}", width=cfg.PAGE_WIDTH)
footer = "~~~ REVIEW IMMEDIATELY ~~~".center(cfg.PAGE_WIDTH)
full_text = "\n".join([header, task, details, footer])
line_count = full_text.count("\n")
top_pad = "\n" * math.floor((cfg.PAGE_HEIGHT - line_count) / 2.0)
padded_text = top_pad + full_text
return padded_text
def print_text(text):
cmd_list = [cfg.PRINTING_EXECUTABLE]
if cfg.PRINTING_ARGUMENTS:
cmd_list += cfg.PRINTING_ARGUMENTS.split()
process = subprocess.run(
cmd_list,
stdout=subprocess.DEVNULL,
input=text,
encoding='ascii'
)
if process.returncode != 0:
print("Error while printing")
def print_issues(issues, text_generator):
for issue in issues:
text = text_generator(issue)
print_text(text)
if __name__ == "__main__":
jira = JiraList(cfg.JIRA_SERVER_URL, cfg.JIRA_USERNAME, cfg.JIRA_API_TOKEN, cfg.JIRA_PROJECT_PREFIX, cfg.JSON_FILE, cfg.CLEAN_DATA)
issues = jira.get_issues(cfg.JIRA_BOARD_ID)
new_issues = jira.filter_new_issues(issues)
if len(new_issues):
list_of_issue_keys = [issue.key for issue in new_issues]
print(f"New issues entered the sprint. Now printing: {', '.join(list_of_issue_keys)}.")
print_issues(new_issues, prepare_text_for_new_issue)
else:
print("No new issues found.")
issues_with_new_prs = jira.filter_issues_with_new_pull_requests(issues)
if len(issues_with_new_prs):
list_of_issue_keys = ", ".join([issue.key for issue in issues_with_new_prs])
print(f"Some issues have new open PRs: {list_of_issue_keys}.")
print_issues(issues_with_new_prs, prepare_text_for_issue_with_new_pr)
else:
print("No issues have new PRs.")
jira.save_state(issues)