-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcreate_issues.py
executable file
·144 lines (123 loc) · 5.41 KB
/
create_issues.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
#!/usr/bin/env python
"""Process spreadsheet assigning manual testing issues
to developers and creates issues on GitHub. It requires a GitHub
access token that can be provided on the command line
"""
import argparse
import getpass
import os
import sys
from github import Github
import pandas as pd
# Constants
DEFAULT_REPOSITORY = "mantidproject/mantid"
TOKEN_ENV_NAME = "CREATE_ISSUES_TOKEN"
BODY_TEXT = '''
You have been assigned manual testing. The hope is to catch as many problems with the code before release, so it would be great if you can take some time to give a serious test to your assigned area. Thank you!!
The general guide to manual testing:
* The tests must be performed on the installer versions of the final release candidate. Not on local compiled code.
* Serious errors involving loss of functionality, crashes etc. should be raised
as issues with the current release as a milestone and an email sent to the project manager immediately.
* Minor and cosmetic issues should be raised as issues against the forthcoming
releases.
* First try things that should work, then try to break Mantid, e.g. entering invalid values, unexpected characters etc.
* Don't spend more than a few hours on the testing as fatigue will kick in.
* If you find errors in the documentation, please correct them.
* Comment against this ticket the OS environment you are testing against.
* Disable Usage reporting before you start testing
* Close the this issue once you are done.
* Time how long this manual test takes for you to do and leave a comment about it in this issue.
'''
ISSUE_LABELS = ["Manual Tests"]
def main() -> int:
"""
Main entry point
"""
cmd_args = parse_args()
gh = Github(github_oauth_token())
repo = gh.get_repo(cmd_args.repository)
possible_assignees = repo.get_assignees()
# Lookup milestone string to get number
milestone_title = cmd_args.milestone
gh_milestone = None
for loop_milestone in repo.get_milestones():
if loop_milestone.title == milestone_title:
gh_milestone = loop_milestone
if gh_milestone is None:
print(f"Unable to find a milestone with title '{milestone_title}'",
file=sys.stderr)
return 1
print(
f"Creating manual testing issues for '{milestone_title}' (GitHub milestone number {gh_milestone.number})"
)
# translate the label strings into gh objects
gh_labels = []
for label in ISSUE_LABELS:
gh_label = repo.get_label(label)
if gh_label is not None:
gh_labels.append(gh_label)
print("Labels", gh_labels)
print("\nLoading issue assignment spreadsheet")
df = pd.read_excel(cmd_args.assignment_spreadsheet, "issues")
print(f"\nCreating {len(df.index)} issues")
for _, row in df.iterrows():
title = str(row['Title']).strip()
additional_body = str(row['Additional Body Text']).strip()
gh_labels = [repo.get_label('Manual Tests')]
proposed_assignees = str(row['Assignee']).split(", ")
gh_assignees = []
if pd.notnull(row['Assignee']):
for loop_proposed_assignee in proposed_assignees:
for loop_possible_assignee in possible_assignees:
if loop_possible_assignee.login == loop_proposed_assignee:
gh_assignees.append(loop_proposed_assignee)
if not gh_assignees:
print("could not find gh assignee for ", loop_proposed_assignee,
". Continuing without assignment.")
my_body = BODY_TEXT
if pd.notnull(additional_body):
my_body += "\n\n### Specific Notes:\n\n" + additional_body
print(title, gh_milestone, gh_labels, gh_assignees)
if not cmd_args.dry_run:
issue = repo.create_issue(title,
body=str(my_body).strip(),
milestone=gh_milestone,
labels=gh_labels)
if gh_assignees:
for gh_assignee in gh_assignees:
issue.add_to_assignees(gh_assignee)
print(issue.number, issue.title, issue.assignees)
return 0
def parse_args() -> argparse.Namespace:
"""Parse commandline arguments and return them as a Namespace"""
parser = argparse.ArgumentParser(
description="Create GitHub issues for Manual testing of Mantid")
parser.add_argument("milestone",
help="Title of GitHub milestone for issue assignment")
parser.add_argument("assignment_spreadsheet",
help="Excel spreadsheet defining test assignments")
parser.add_argument(
"--repository",
type=str,
default=DEFAULT_REPOSITORY,
help=
"GitHub repository where issues should be created specified as org/repo"
)
parser.add_argument(
"--dry-run",
action="store_true",
default=False,
help=
"If passed, print what would happen but do not perform issue creation")
return parser.parse_args()
def github_oauth_token() -> str:
"""Retrieve the oauth token for authenticating with GitHub
Checks for CREATE_ISSUES_TOKEN env variable and falls back to
asking on the command line
"""
token = os.environ.get(TOKEN_ENV_NAME, None)
if token is None:
token = getpass.getpass(prompt=f"Enter GitHub personal access token:")
return token
if __name__ == "__main__":
sys.exit(main())