Ejemplo n.º 1
0
def get_events_for_document(raw_document):
    gh = Github(settings.GH_TOKEN)
    document = Issue(gh._Github__requester, {}, raw_document, completed=True)

    raw_document['events'] = []
    for event in document.get_events():
        raw_document['events'].append(event.raw_data)
        wait_for_rate(event)

    return raw_document
Ejemplo n.º 2
0
def get_events_for_document(raw_document):
    gh = get_gh_client()
    document = Issue(gh._Github__requester, {}, raw_document, completed=True)

    raw_document['events'] = []
    try:
        for event in document.get_events():
            raw_document['events'].append(event.raw_data)
            wait_for_rate(event)
    except UnknownObjectException:
        # If this object no longer exist don't do anything
        pass

    return raw_document
Ejemplo n.º 3
0
def process_issue(*, issue: Issue, settings: Settings) -> None:
    logging.info(f"Processing issue: #{issue.number}")
    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)
    for keyword, keyword_meta in settings.input_config.items():
        # Check closable delay, if enough time passed and the issue could be closed
        closable_delay = (
            last_comment is None
            or (datetime.utcnow() - keyword_meta.delay) > last_comment.created_at
        )
        # Check label, optionally removing it if there's a comment after adding it
        if keyword in label_strs:
            logging.info(f'Keyword: "{keyword}" in issue labels')
            keyword_event = get_last_event_for_label(
                labeled_events=labeled_events, label=keyword
            )
            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}"'
                )
                if keyword_meta.remove_label_on_comment:
                    logging.info(f'Removing label: "{keyword}"')
                    issue.remove_from_labels(keyword)
            elif closable_delay:
                close_issue(
                    issue=issue,
                    keyword_meta=keyword_meta,
                    keyword=keyword,
                    label_strs=label_strs,
                )
                break
            else:
                logging.info(
                    f"Not clossing issue: #{issue.number} as the delay hasn't been reached: {keyword_meta.delay}"
                )
Ejemplo n.º 4
0
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()])
    events = list(issue.get_events())
    labeled_events = get_labeled_events(events)
    last_comment = get_last_comment(issue)
    for keyword, keyword_meta in settings.input_config.items():
        # Check closable delay, if enough time passed and the issue could be closed
        closable_delay = False
        if (last_comment is None or (datetime.utcnow() - keyword_meta.delay) >
                last_comment.created_at):
            closable_delay = True
        # Check label, optionally removing it if there's a comment after adding it
        if keyword in label_strs:
            logging.info(f'Keyword: "{keyword}" in issue labels')
            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:
                logging.info(
                    f"Not closing as the last comment was written after adding the "
                    f'label: "{keyword}"')
                if keyword_meta.remove_label:
                    logging.info(f'Removing label: "{keyword}"')
                    issue.remove_from_labels(keyword)
            elif closable_delay:
                close_issue(issue=issue, keyword_meta=keyword_meta)
                break
        # Check HTML comments by allowed users
        if (last_comment
                and f"<!-- issue-manager: {keyword} -->" in last_comment.body
                and closable_delay and last_comment.user.login
                in keyword_meta.users + [owner.login]):
            logging.info(
                f'Last comment by user: "******" had HTML keyword '
                f'comment: "{keyword}" and there\'s a closable delay.')
            close_issue(issue=issue, keyword_meta=keyword_meta)
            break