Beispiel #1
0
def events(request) -> List[Tuple[AbstractGithubEvent, bool]]:
    """
    :param request: event type to create Event instances of that type
    :return: list of Events that check_and_report accepts together with whether they should pass
    """
    approved_accounts = [
        ("foo", "bar", False),
        ("foo", "lojzo", True),
        ("lojzo", "bar", True),
        ("lojzo", "fero", True),
    ]

    if request.param == "release":
        return [
            (ReleaseEvent("foo", "", "", ""), False),
            (ReleaseEvent("lojzo", "", "", ""), True),
        ]
    elif request.param == "pr":
        return [(
            PullRequestEvent(PullRequestAction.opened, 1, namespace, "", "",
                             "", "", "", login),
            approved,
        ) for namespace, login, approved in approved_accounts]
    elif request.param == "pr_comment":
        return [(
            PullRequestCommentEvent(
                PullRequestCommentAction.created,
                1,
                namespace,
                "",
                "",
                "",
                "",
                login,
                "",
            ),
            approved,
        ) for namespace, login, approved in approved_accounts]
    elif request.param == "issue_comment":
        return [(
            IssueCommentEvent(
                IssueCommentAction.created,
                1,
                namespace,
                "",
                "",
                "",
                login,
                "",
            ),
            approved,
        ) for namespace, login, approved in approved_accounts]
    return []
    def parse_issue_comment_event(event) -> Optional[IssueCommentEvent]:
        """ Look into the provided event and see if it is Github issue comment event. """
        if nested_get(event, "issue", "pull_request"):
            return None

        issue_id = nested_get(event, "issue", "number")
        action = event.get("action")
        comment = nested_get(event, "comment", "body")
        if action != "created" or not issue_id or not comment:
            return None

        logger.info(
            f"Github issue#{issue_id} comment: {comment!r} {action!r} event.")

        base_repo_namespace = nested_get(event, "repository", "owner", "login")
        base_repo_name = nested_get(event, "repository", "name")
        if not (base_repo_namespace and base_repo_name):
            logger.warning("No full name of the repository.")

        user_login = nested_get(event, "comment", "user", "login")
        if not user_login:
            logger.warning("No Github login name from event.")
            return None

        target_repo = nested_get(event, "repository", "full_name")
        logger.info(f"Target repo: {target_repo}.")
        https_url = nested_get(event, "repository", "html_url")
        return IssueCommentEvent(
            IssueCommentAction[action],
            issue_id,
            base_repo_namespace,
            base_repo_name,
            target_repo,
            https_url,
            user_login,
            comment,
        )
Beispiel #3
0
         "",
         "",
         "",
         "",
         "bar",
         "",
     ),
     "pr_comment",
     False,
 ),
 (
     IssueCommentEvent(
         IssueCommentAction.created,
         0,
         "foo",
         "",
         "",
         "",
         "bar",
         "",
     ),
     "issue_comment",
     False,
 ),
 (
     PullRequestCommentEvent(
         PullRequestCommentAction.created,
         0,
         "",
         "",
         "",
         "",
Beispiel #4
0
def events(request) -> List[Tuple[AbstractGithubEvent, bool]]:
    """
    :param request: event type to create Event instances of that type
    :return: list of Events that check_and_report accepts together with whether they should pass
    """
    approved_accounts = [
        ("foo", "bar", False),
        ("foo", "lojzo", True),
        ("lojzo", "bar", True),
        ("lojzo", "fero", True),
    ]

    if request.param == "release":
        return [
            (ReleaseEvent("foo", "", "", ""), False),
            (ReleaseEvent("lojzo", "", "", ""), True),
        ]
    elif request.param == "pr":
        return [(
            PullRequestGithubEvent(
                action=PullRequestAction.opened,
                pr_id=1,
                base_repo_namespace="",
                base_repo_name="",
                target_repo_namespace=namespace,
                target_repo_name="",
                https_url="",
                commit_sha="",
                user_login=login,
                base_ref="",
            ),
            approved,
        ) for namespace, login, approved in approved_accounts]
    elif request.param == "pr_comment":
        return [(
            PullRequestCommentGithubEvent(
                action=PullRequestCommentAction.created,
                pr_id=1,
                base_repo_namespace=namespace,
                base_repo_name="",
                base_ref="",
                target_repo_namespace="",
                target_repo_name="",
                project_url="",
                user_login=login,
                comment="",
            ),
            approved,
        ) for namespace, login, approved in approved_accounts]
    elif request.param == "issue_comment":
        return [(
            IssueCommentEvent(
                action=IssueCommentAction.created,
                issue_id=1,
                repo_namespace=namespace,
                repo_name="",
                target_repo="",
                project_url="",
                user_login=login,
                comment="",
            ),
            approved,
        ) for namespace, login, approved in approved_accounts]
    return []