-
Notifications
You must be signed in to change notification settings - Fork 7
/
script_app.py
694 lines (610 loc) · 27.2 KB
/
script_app.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
import json
import os
import sys
import webbrowser
from git.exc import GitCommandError
from jira.exceptions import JIRAError
from textual import work
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.containers import *
from textual.reactive import reactive
from textual.widgets import *
root = os.path.dirname(__file__)
sys.path.append(root)
from liferay.apps import (
create_issue,
create_pr_and_forward,
create_test_fix_ticket,
forward_failure_pull_request,
trigger_gauntlet,
write_comments,
write_description,
)
from liferay.csv import convert_commits_to_tickets
from liferay.jira import jira_components_sync
from liferay.jira.jira_constants import *
from liferay.jira.jira_util import *
from liferay.util import credentials
from widgets.form import *
from widgets.menubar import *
from widgets.output import *
from widgets.sidebar import *
from widgets.submit import *
from widgets.text_field import *
from widgets.textarea_field import *
from widgets.toggle_switch import *
class ScriptApp(App):
BINDINGS = [
Binding("ctrl+b", "toggle_sidebar", "More Shortcuts"),
Binding("ctrl+c", "do_not_quit"),
Binding("ctrl+o", "open_credentials", show=False),
Binding("ctrl+s", "sync_components", show=False),
Binding("escape", "quit", "Quit"),
]
CSS_PATH = root + "/liferay/src/css/main.css"
TITLE = "Working with Script"
show_sidebar = reactive(False)
def compose(self) -> ComposeResult:
yield Sidebar(classes="-hidden")
yield Header()
with Horizontal(id="main-content"):
yield Menubar(
MenuItem("Forward Failure PR", "nav-1"),
MenuItem("Create PR and Forward", "nav-2"),
MenuItem("Create TF Ticket", "nav-3"),
MenuItem("Write Comments", "nav-4"),
MenuItem("Write Description", "nav-5"),
MenuItem("Trigger Gauntlet", "nav-6"),
MenuItem("Create Issue", "nav-7"),
MenuItem("RCA", "nav-8"),
)
with ContentSwitcher(initial="nav-1"):
with Form("nav-1"):
yield TextField(
"Enter the failure pull request number: ",
"failure-pull-request-number",
)
yield Submit("button-1")
with Form("nav-2"):
yield TextField("Enter the local branch name: ", "local-branch")
yield TextField(
"Enter the Jira ticket number: ", "jira-ticket-number-2"
)
yield Submit("button-2")
with Form("nav-3"):
PROJECT_KEY = [
("LPD", "LPD"),
("LRQA", "LRQA"),
]
yield TextField("Enter the case result id: ", "case-result-id")
yield Label("Select the project key: ")
yield Select(PROJECT_KEY, id="project-key-1", value="LPD")
yield ToggleSwitch("assign-to-me-1")
yield TextField("Add label (Optional)", "add-label")
yield Submit("button-3")
with Form("nav-4"):
COMMENTS_TYPE = [
(
"PASSED Manual Testing following the steps in the description.",
"PID",
),
(
"FAILED Manual Testing following the steps in the description.",
"FID",
),
(
"No Longer Reproducible through Manual Testing following the steps in the description.",
"NID",
),
("PASSED Manual Testing using the following steps:", "PF"),
("FAILED Manual Testing using the following steps:", "FF"),
(
"No Longer Reproducible through Manual Testing using the following steps:",
"NF",
),
("Reproduced on:", "R"),
("Reproduced on: Upgrade From:", "RU"),
("Test Validation", "TV"),
]
yield TextField(
"Enter the Jira ticket number: ", "jira-ticket-number-4"
)
yield Label("Select the comments type: ")
yield Select(COMMENTS_TYPE, id="comments-type")
yield TextAreaGroup(
"Enter the comments: ", "comments", "unselected"
)
yield Submit("button-4")
with Form("nav-5"):
DESCRIPTION_TYPE = [
("Steps to reproduce", "STR"),
("Test Cases", "TC"),
]
yield TextField(
"Enter the Jira ticket number: ", "jira-ticket-number-5"
)
yield Label("Select the description type: ")
yield Select(DESCRIPTION_TYPE, id="description-type")
yield TextAreaGroup(
"Enter the description: ", "description", "unselected"
)
yield Submit("button-5")
with Form("nav-6"):
yield TextField(
"Enter the legacy repo path: ",
"legacy-repo-path",
value=credentials.get_credentials("LEGACY_REPO_PATH"),
)
yield TextField(
"Enter the target branch: ", "target-branch", value="7.3.x"
)
yield Submit("button-6")
with Form("nav-7"):
PROJECT_KEY = [
("LPD", "LPD"),
("LRQA", "LRQA"),
]
PRODUCT_TEAM = [
("Business Process Management Team", "bpm"),
]
ISSUE_TYPE = [
("Bug", "Bug"),
("Task", "Task"),
("Testing", "Testing"),
]
BUG_TYPE = [
("Default", "Default"),
("Regression Bug", "Regression Bug"),
]
yield Label("Project Key:", id="project-key-label-2")
yield Select(PROJECT_KEY, id="project-key-2")
yield Label("Issue Type:", id="issue-type-label")
yield Select(ISSUE_TYPE, id="issue-type")
yield Label("Bug Type:", id="bug-type-label", classes="unselected")
yield Select(BUG_TYPE, id="bug-type", classes="unselected")
yield Label(
"Product Team:", id="product-team-label", classes="unselected"
)
yield Select(PRODUCT_TEAM, id="product-team", classes="unselected")
yield TextField("Summary:", "summary", "unselected")
yield Label(
"Components:", id="components-label", classes="unselected"
)
yield Select([], id="components", classes="unselected")
yield TextField(
"Affects versions:",
"affects-versions",
"unselected",
value="Master",
)
yield TextAreaGroup(
"Description:", "issue-description", "unselected"
)
yield ToggleSwitch("assign-to-me-2")
yield TextField("Add label (Optional)", "issue-label")
yield Submit("button-7")
with Form("nav-8"):
yield TextField(
"Enter the repo name: ",
"repo-name",
value="liferay/liferay-portal",
)
yield TextField("Enter the last pass sha: ", "base")
yield TextField("Enter the first failure sha: ", "head")
yield Submit("button-8")
yield Output()
yield Footer()
@work(exclusive=True, thread=True)
def action_do_not_quit(self) -> None:
pass
@work(exclusive=True, thread=True)
def action_open_credentials(self) -> None:
self.query_one(RichLog).clear()
self.query_one(RichLog).begin_capture_print()
credentials.open_credentials()
@work(exclusive=True, thread=True)
def action_sync_components(self) -> None:
self.query_one(RichLog).clear()
self.query_one(RichLog).begin_capture_print()
jira_components_sync.main()
@work(exclusive=True, thread=True)
def action_toggle_sidebar(self) -> None:
sidebar = self.query_one(Sidebar)
self.set_focus(None)
if sidebar.has_class("-hidden"):
self.call_from_thread(sidebar.remove_class, "-hidden")
else:
if sidebar.query("*:focus"):
self.screen.set_focus(None)
self.call_from_thread(sidebar.add_class, "-hidden")
@work(exclusive=True, thread=True)
def create_pr_and_forward(self) -> None:
local_branch_name = self.query_one("#local-branch").value
jira_ticket_number = self.query_one("#jira-ticket-number-2").value
self.query_one("#button-2").disabled = True
self.query_one(RichLog).clear()
self.query_one(RichLog).begin_capture_print()
try:
create_pr_and_forward.main(local_branch_name, jira_ticket_number)
self.query_one("#button-2").disabled = False
self.query_one("#local-branch").value = ""
self.query_one("#jira-ticket-number-2").value = ""
except (AssertionError, JIRAError, GitCommandError):
print(
f"\033[1;31mPlease check your credentials in credentials-ext.properties\033[0m"
)
except Exception as e:
print(e)
finally:
self.query_one("#button-2").disabled = False
@work(exclusive=True, thread=True)
def create_test_fix_ticket(self) -> None:
assigned = self.query_one("#assign-to-me-1").value
case_result_id = self.query_one("#case-result-id").value
label = self.query_one("#add-label").value
project_key = self.query_one("#project-key-1").value
self.query_one("#button-3").disabled = True
self.query_one(RichLog).clear()
self.query_one(RichLog).begin_capture_print()
try:
create_test_fix_ticket.main(assigned, case_result_id, label, project_key)
self.query_one("#button-3").disabled = False
self.query_one("#assign-to-me-1").value = False
self.query_one("#case-result-id").value = ""
self.query_one("#add-label").value = ""
self.query_one("#project-key-1").value = "LPD"
except (AssertionError, JIRAError, json.decoder.JSONDecodeError):
print(
f"\033[1;31mPlease check your credentials in credentials-ext.properties\033[0m"
)
except Exception as e:
print(e)
finally:
self.query_one("#button-3").disabled = False
@work(exclusive=True, thread=True)
def create_issue(self) -> None:
affects_versions = self.query_one("#affects-versions").value
assigned = self.query_one("#assign-to-me-2").value
bug_type = self.query_one("#bug-type").value
component = self.query_one("#components").value
description = self.query_one("#issue-description").text
issue_type = self.query_one("#issue-type").value
label = self.query_one("#issue-label").value
project_key = self.query_one("#project-key-2").value
summary = self.query_one("#summary").value
self.query_one("#button-7").disabled = True
self.query_one(RichLog).clear()
self.query_one(RichLog).begin_capture_print()
try:
create_issue.main(
affects_versions,
assigned,
bug_type,
component,
description,
issue_type,
label,
project_key,
summary,
)
self.query_one("#affects-versions").value = "Master"
self.query_one("#assign-to-me-2").value = False
self.query_one("#bug-type").clear()
self.query_one("#components").clear()
self.query_one("#issue-type").clear()
self.query_one("#issue-label").value = ""
self.query_one("#summary").value = ""
self.query_one("#issue-description").clear()
self.query_one("#project-key-2").clear()
self.query_one("#button-7").disabled = False
self.call_from_thread(
self.query_one("#product-team").remove_class, "visible"
)
self.call_from_thread(
self.query_one("#product-team-label").remove_class, "visible"
)
self.call_from_thread(self.query_one("#summary").remove_class, "visible")
self.call_from_thread(
self.query_one("#summary-label").remove_class, "visible"
)
self.call_from_thread(self.query_one("#issue-type").remove_class, "visible")
self.call_from_thread(
self.query_one("#issue-type-label").remove_class, "visible"
)
self.call_from_thread(self.query_one("#bug-type").remove_class, "visible")
self.call_from_thread(
self.query_one("#bug-type-label").remove_class, "visible"
)
self.call_from_thread(
self.query_one("#issue-description").remove_class, "visible"
)
self.call_from_thread(
self.query_one("#issue-description-label").remove_class, "visible"
)
self.call_from_thread(self.query_one("#components").remove_class, "visible")
self.call_from_thread(
self.query_one("#components-label").remove_class, "visible"
)
self.call_from_thread(
self.query_one("#affects-versions").remove_class, "visible"
)
self.call_from_thread(
self.query_one("#affects-versions-label").remove_class, "visible"
)
except JIRAError:
print(
f"\033[1;31mPlease sync Jira project components via \033[1;3;33mCtrl + S\033[0m"
)
except Exception as e:
print(e)
finally:
self.query_one("#button-7").disabled = False
@work(exclusive=True, thread=True)
def conversion(self) -> None:
baseSHA = self.query_one("#base").value
headSHA = self.query_one("#head").value
repo_name = self.query_one("#repo-name").value
self.query_one("#button-8").disabled = True
self.query_one(RichLog).clear()
self.query_one(RichLog).begin_capture_print()
try:
convert_commits_to_tickets.main(baseSHA, headSHA, repo_name)
self.query_one("#base").value = ""
self.query_one("#head").value = ""
self.query_one("#repo-name").value = "liferay/liferay-portal"
except (AssertionError, JIRAError):
print(
f"\033[1;31mPlease check your credentials in credentials-ext.properties\033[0m"
)
except TypeError:
print(
f"\033[1;31mPlease check if the {baseSHA} and\033[0m{os.linesep}\033[1;31mthe {headSHA} are in the same repository!\033[0m"
)
except Exception as e:
print(e)
finally:
self.query_one("#button-8").disabled = False
@work(exclusive=True, thread=True)
def forward_failure_pull_request(self) -> None:
failure_pull_request_number = self.query_one(
"#failure-pull-request-number"
).value
self.query_one("#button-1").disabled = True
self.query_one(RichLog).clear()
self.query_one(RichLog).begin_capture_print()
try:
forward_failure_pull_request.main(failure_pull_request_number)
self.query_one("#failure-pull-request-number").value = ""
except (AssertionError, GitCommandError):
print(
f"\033[1;31mPlease check your credentials in credentials-ext.properties\033[0m"
)
except Exception as e:
print(e)
finally:
self.query_one("#button-1").disabled = False
@work(exclusive=True, thread=True)
def trigger_gauntlet(self) -> None:
legacy_local_path = self.query_one("#legacy-repo-path").value
target_branch = self.query_one("#target-branch").value
self.query_one("#button-6").disabled = True
self.query_one(RichLog).clear()
self.query_one(RichLog).begin_capture_print()
try:
trigger_gauntlet.main(legacy_local_path, target_branch)
self.query_one("#button-6").disabled = False
self.query_one("#legacy-repo-path").value = credentials.get_credentials(
"LEGACY_REPO_PATH"
)
self.query_one("#target-branch").value = "7.3.x"
except (AssertionError, JIRAError, GitCommandError):
print(
f"\033[1;31mPlease check your credentials in credentials-ext.properties\033[0m"
)
except Exception as e:
print(e)
finally:
self.query_one("#button-6").disabled = False
@work(exclusive=True, thread=True)
def write_comments(self) -> None:
ticket_number = self.query_one("#jira-ticket-number-4").value
comments = self.query_one("#comments").text
self.query_one("#button-4").disabled = True
self.query_one(RichLog).clear()
self.query_one(RichLog).begin_capture_print()
try:
write_comments.main(comments, ticket_number)
self.query_one("#button-4").disabled = False
self.query_one("#jira-ticket-number-4").value = ""
self.query_one("#comments-type").clear()
self.call_from_thread(self.query_one("#comments").remove_class, "visible")
self.call_from_thread(
self.query_one("#comments-label").remove_class, "visible"
)
except (AssertionError, JIRAError):
print(
f"\033[1;31mPlease check your credentials in credentials-ext.properties\033[0m"
)
except Exception as e:
print(e)
finally:
self.query_one("#button-4").disabled = False
@work(exclusive=True, thread=True)
def write_description(self) -> None:
ticket_number = self.query_one("#jira-ticket-number-5").value
description = self.query_one("#description").text
self.query_one("#button-5").disabled = True
self.query_one(RichLog).clear()
self.query_one(RichLog).begin_capture_print()
try:
write_description.main(description, ticket_number)
self.query_one("#button-5").disabled = False
self.query_one("#jira-ticket-number-5").value = ""
self.query_one("#description-type").clear()
self.call_from_thread(
self.query_one("#description").remove_class, "visible"
)
self.call_from_thread(
self.query_one("#description-label").remove_class, "visible"
)
except (AssertionError, JIRAError):
print(
f"\033[1;31mPlease check your credentials in credentials-ext.properties\033[0m"
)
except Exception as e:
print(e)
finally:
self.query_one("#button-5").disabled = False
def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "button-1":
self.forward_failure_pull_request()
elif event.button.id == "button-2":
self.create_pr_and_forward()
elif event.button.id == "button-3":
self.create_test_fix_ticket()
elif event.button.id == "button-4":
self.write_comments()
elif event.button.id == "button-5":
self.write_description()
elif event.button.id == "button-6":
self.trigger_gauntlet()
elif event.button.id == "button-7":
self.create_issue()
elif event.button.id == "button-8":
self.conversion()
def on_list_view_selected(self, event: ListView.Selected) -> None:
self.query_one(ContentSwitcher).current = event.item.id
def on_markdown_link_clicked(self, event: Markdown.LinkClicked) -> None:
webbrowser.open(event.href)
def on_select_changed(self, event: Select.Changed) -> None:
self.query_one(RichLog).begin_capture_print()
if event.select.id == "description-type":
try:
description = generate_description(
self.query_one("#description-type").value
)
self.query_one("#description").load_text(description)
except:
pass
self.query_one("#description").set_class(
event.value != Select.BLANK, "visible"
)
self.query_one("#description-label").set_class(
event.value != Select.BLANK, "visible"
)
elif event.select.id == "comments-type":
try:
comment = generate_comment(self.query_one("#comments-type").value)
self.query_one("#comments").load_text(comment)
except:
pass
self.query_one("#comments").set_class(
event.value != Select.BLANK, "visible"
)
self.query_one("#comments-label").set_class(
event.value != Select.BLANK, "visible"
)
elif event.select.id == "issue-type":
try:
comment = generate_comment(self.query_one("#issue-type").value)
self.query_one("#comments").load_text(comment)
except:
pass
self.query_one("#summary-label").set_class(
event.value != Select.BLANK, "visible"
)
self.query_one("#summary").set_class(event.value != Select.BLANK, "visible")
self.query_one("#issue-description-label").set_class(
event.value != Select.BLANK, "visible"
)
self.query_one("#issue-description").set_class(
event.value != Select.BLANK, "visible"
)
self.query_one("#bug-type").set_class(event.value == "Bug", "visible")
self.query_one("#bug-type-label").set_class(event.value == "Bug", "visible")
self.query_one("#components-label").set_class(
event.value != Select.BLANK, "visible"
)
self.query_one("#components").set_class(
event.value != Select.BLANK, "visible"
)
# self.query_one("#product-team").set_class(
# event.value == "Testing", "visible"
# )
# self.query_one("#product-team-label").set_class(
# event.value == "Testing", "visible"
# )
self.query_one("#affects-versions").set_class(
event.value == "Bug", "visible"
)
self.query_one("#affects-versions-label").set_class(
event.value == "Bug", "visible"
)
elif event.select.id == "bug-type":
try:
description = generate_description(self.query_one("#bug-type").value)
self.query_one("#issue-description").load_text(description)
except:
pass
self.query_one("#summary").set_class(event.value != Select.BLANK, "visible")
self.query_one("#summary-label").set_class(
event.value != Select.BLANK, "visible"
)
self.query_one("#components-label").set_class(
event.value != Select.BLANK, "visible"
)
self.query_one("#components").set_class(
event.value != Select.BLANK, "visible"
)
self.query_one("#issue-description-label").set_class(
event.value != Select.BLANK, "visible"
)
self.query_one("#issue-description").set_class(
event.value != Select.BLANK, "visible"
)
elif event.select.id == "product-team":
if self.query_one("#product-team").value == Select.BLANK:
self.query_one("#summary").value = ""
self.query_one("#issue-description").clear()
else:
self.query_one("#summary").value = get_properties(
self.query_one("#product-team").value, "SUMMARY"
)
self.query_one("#issue-description").load_text(
get_properties(self.query_one("#product-team").value, "DESCRIPTION")
)
elif event.select.id == "project-key-2":
if self.query_one("#project-key-2").value != Select.BLANK:
try:
components = get_components(
f'{self.query_one("#project-key-2").value}_COMPONENTS'
)
self.query_one("#components").set_options((eval(components)))
except TypeError:
print(
f"\033[1;31mPlease sync Jira project components via \033[1;3;33mCtrl + S\033[0m"
)
else:
self.query_one("#product-team").clear()
self.query_one("#summary").value = ""
self.query_one("#components").clear()
self.query_one("#issue-type").clear()
self.query_one("#issue-description").clear()
self.query_one("#assign-to-me-2").value = False
self.query_one("#issue-label").value = ""
self.query_one("#components").remove_class("visible")
self.query_one("#components-label").remove_class("visible")
self.query_one("#product-team").remove_class("visible")
self.query_one("#product-team-label").remove_class("visible")
self.query_one("#affects-versions").remove_class("visible")
self.query_one("#affects-versions-label").remove_class("visible")
self.query_one("#bug-type").remove_class("visible")
self.query_one("#bug-type-label").remove_class("visible")
self.query_one("#summary").remove_class("visible")
self.query_one("#summary-label").remove_class("visible")
self.query_one("#issue-description").remove_class("visible")
self.query_one("#issue-description-label").remove_class("visible")
app = ScriptApp()
if __name__ == "__main__":
app.run()