Skip to content

Commit e0c09d4

Browse files
committed
Add flags to select whether to include area owners or components
1 parent f62e686 commit e0c09d4

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

scripts/import.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,29 @@ def parse_args() -> argparse.Namespace:
163163
default=None,
164164
)
165165

166+
parser.add_argument(
167+
'--area-owners',
168+
help="Include area owners in the generated tickets",
169+
action='store_true',
170+
)
171+
parser.add_argument(
172+
'--components',
173+
help="Include components in the generated tickets",
174+
action='store_true',
175+
)
176+
166177
return parser.parse_args()
167178

168179

169180
def main(arguments: argparse.Namespace) -> None:
170181
if arguments.trac_root is not None:
171182
backend: 'Backend' = RealTracBackend(arguments.trac_root)
172183
elif arguments.github_repo is not None:
173-
backend = GitHubBackend(arguments.github_repo)
184+
backend = GitHubBackend(
185+
arguments.github_repo,
186+
include_area_owners=arguments.area_owners,
187+
include_components=arguments.components,
188+
)
174189
else:
175190
backend = FakeTracBackend()
176191

scripts/import_backends.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,28 +165,42 @@ class GitHubBackend:
165165
'livestream': 'AO: Livestream',
166166
}
167167

168-
def __init__(self, repo_name: str) -> None:
168+
def __init__(
169+
self,
170+
repo_name: str,
171+
include_area_owners: bool = False,
172+
include_components: bool = False,
173+
) -> None:
169174
self.github = github.Github(get_github_credential())
170175
self.repo = self.github.get_repo(repo_name)
171176
self.milestones: Dict[str, github.Milestone.Milestone] = {
172177
x.title: x for x in self.repo.get_milestones()
173178
}
174179

180+
self.include_area_owners = include_area_owners
181+
self.include_components = include_components
182+
175183
labels: Dict[str, github.Label.Label] = {
176184
x.name: x for x in self.repo.get_labels()
177185
}
178186

179187
try:
180-
self._component_label_mapping = {
181-
k: [labels[x] for x in v]
182-
for k, v in self.COMPONENT_LABEL_MAPPING.items()
183-
}
188+
if include_components:
189+
self._component_label_mapping = {
190+
k: [labels[x] for x in v]
191+
for k, v in self.COMPONENT_LABEL_MAPPING.items()
192+
}
193+
else:
194+
self._component_label_mapping = {}
184195
self._component_priority_mapping = {
185196
k: labels[v] for k, v in self.COMPONENT_PRIORITY_MAPPING.items()
186197
}
187-
self._area_owner_mapping = {
188-
k: labels[v] for k, v in self.AREA_OWNER_MAPPING.items()
189-
}
198+
if include_area_owners:
199+
self._area_owner_mapping = {
200+
k: labels[v] for k, v in self.AREA_OWNER_MAPPING.items()
201+
}
202+
else:
203+
self._area_owner_mapping = {}
190204
except KeyError as e:
191205
raise ValueError(
192206
f"Label {e} does not exist within {repo_name!r}",
@@ -229,8 +243,10 @@ def get_or_create_milestone(self, title: str) -> github.Milestone.Milestone:
229243

230244
def labels(self, ticket: Ticket) -> List[github.Label.Label]:
231245
labels = [self._component_priority_mapping[ticket.priority]]
232-
labels += self._component_label_mapping[ticket.component]
233-
labels.append(self._area_owner_mapping[ticket.area_owner])
246+
if self.include_components:
247+
labels += self._component_label_mapping[ticket.component]
248+
if self.include_area_owners:
249+
labels.append(self._area_owner_mapping[ticket.area_owner])
234250
return labels
235251

236252
def submit(self, ticket: Ticket) -> int:

0 commit comments

Comments
 (0)