Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Handle renamed labels that don't show up in the labels for an issue #9

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def get_labeled_events(events: List[IssueEvent]) -> List[IssueEvent]:

def get_last_event_for_label(
*, labeled_events: List[IssueEvent], label: str
) -> IssueEvent:
) -> Optional[IssueEvent]:
last_event: Optional[IssueEvent] = None
for event in labeled_events:
if event.label.name == label:
if event.label and event.label.name == label:
if not last_event:
last_event = event
continue
Expand All @@ -83,7 +83,7 @@ def close_issue(*, issue: Issue, keyword_meta: KeywordMeta) -> None:

def process_issue(*, issue: Issue, settings: Settings, owner: NamedUser) -> None:
logging.info(f"Processing issue: #{issue.number}")
label_strs = set([l.name for l in issue.get_labels()])
label_strs = set([label.name for label in issue.get_labels()])
events = list(issue.get_events())
labeled_events = get_labeled_events(events)
last_comment = get_last_comment(issue)
Expand All @@ -101,7 +101,11 @@ def process_issue(*, issue: Issue, settings: Settings, owner: NamedUser) -> None
keyword_event = get_last_event_for_label(
labeled_events=labeled_events, label=keyword
)
if last_comment and last_comment.created_at > keyword_event.created_at:
if (
last_comment
and keyword_event
and last_comment.created_at > keyword_event.created_at
):
logging.info(
f"Not closing as the last comment was written after adding the "
f'label: "{keyword}"'
Expand Down Expand Up @@ -149,4 +153,4 @@ def process_issue(*, issue: Issue, settings: Settings, owner: NamedUser) -> None
else:
for issue in repo.get_issues(state="open"):
process_issue(issue=issue, settings=settings, owner=owner)
logging.info(f"Finished")
logging.info("Finished")