def test_dashboard(self, format_exc):
        format_exc.return_value = "something to do with an exception"

        # Prepare
        repo = self.g.get_repo("lmazuel/TestingRepo")
        issue = repo.get_issue(15)
        initial_size = len(list(issue.get_comments()))
        header = "# MYHEADER"

        dashboard = DashboardCommentableObject(issue, header)

        with exception_to_github(dashboard, "Python bot") as error:
            "Test".fakemethod(12)  # pylint: disable=no-member

        after_size = len(list(issue.get_comments()))
        assert after_size == initial_size + 1

        assert error.comment is not None
        assert "Encountered an unknown error" in error.comment.body

        dashboard.create_comment("New text comment")
        after_size_2 = len(list(issue.get_comments()))
        assert after_size == after_size_2

        # Clean my mess
        error.comment.delete()
Esempio n. 2
0
def rest_handle_action(body, sdkid, sdkbase, sdk_tag):
    """First method in the thread.
    """
    _LOGGER.info("Rest handle action")
    gh_token = os.environ["GH_TOKEN"]
    github_con = Github(gh_token)

    sdk_pr_target_repo = github_con.get_repo(sdkid)

    restapi_repo = github_con.get_repo(body['repository']['full_name'])
    rest_pr = restapi_repo.get_pull(body["number"])
    dashboard = DashboardCommentableObject(
        rest_pr, "# Automation for {}".format(sdk_tag))

    _LOGGER.info("Received PR action %s", body["action"])
    with exception_to_github(dashboard, sdk_tag):
        if body["action"] in ["opened", "reopened"]:
            return rest_pull_open(body, restapi_repo, sdk_pr_target_repo,
                                  sdkbase, sdk_tag)
        if body["action"] == "closed":
            return rest_pull_close(body, restapi_repo, sdk_pr_target_repo,
                                   sdkbase, sdk_tag)
        if body["action"] == "synchronize":  # push to a PR from a fork
            return rest_pull_sync(body, restapi_repo, sdk_pr_target_repo,
                                  sdkbase, sdk_tag)
Esempio n. 3
0
def rest_handle_action(body, sdkid, sdkbase, sdk_tag):
    """First method in the thread.
    """
    _LOGGER.info("Rest handle action")
    gh_token = os.environ["GH_TOKEN"]
    github_con = Github(gh_token)

    sdk_pr_target_repo = github_con.get_repo(sdkid)

    restapi_repo = github_con.get_repo(body['repository']['full_name'])
    rest_pr = restapi_repo.get_pull(body["number"])
    dashboard = DashboardCommentableObject(rest_pr, "# Automation for {}".format(sdk_tag))

    _LOGGER.info("Received PR action %s", body["action"])
    with exception_to_github(dashboard, sdk_tag):
        if body["action"] in ["opened", "reopened"]:
            return rest_pull_open(body, restapi_repo, sdk_pr_target_repo, sdkbase, sdk_tag)
        if body["action"] == "closed":
            return rest_pull_close(body, restapi_repo, sdk_pr_target_repo, sdkbase, sdk_tag)
        if body["action"] == "synchronize": # push to a PR from a fork
            return rest_pull_sync(body, restapi_repo, sdk_pr_target_repo, sdkbase, sdk_tag)
    def test_exception_to_github(self, format_exc):
        format_exc.return_value = "something to do with an exception"

        # Prepare
        repo = self.g.get_repo("lmazuel/TestingRepo")
        issue = repo.get_issue(13)

        # Act
        with exception_to_github(issue) as error:
            pass

        assert error.comment is None

        # Act
        with exception_to_github(issue) as error:
            "Test".fakemethod(12)  # pylint: disable=no-member

        # Test
        assert error.comment is not None
        assert "Encountered an unknown error" in error.comment.body

        # Clean my mess
        error.comment.delete()

        # Act
        with exception_to_github(issue, "Python bot") as error:
            "Test".fakemethod(12)  # pylint: disable=no-member

        # Test
        assert error.comment is not None
        assert "Encountered an unknown error: (Python bot)" in error.comment.body

        # Clean my mess
        error.comment.delete()

        # Act
        with exception_to_github(issue, "Python bot") as error:
            raise CalledProcessError(2, ["autorest", "readme.md"],
                                     "Error line 1\nError line 2")

        # Test
        assert error.comment is not None
        assert "Encountered a Subprocess error: (Python bot)" in error.comment.body
        assert "Error line 1" in error.comment.body

        # Clean my mess
        error.comment.delete()

        # Act
        with exception_to_github(issue, "Python bot") as error:
            raise CalledProcessError(
                2,
                ["autorest", "readme.md"],
            )

        # Test
        assert error.comment is not None
        assert "Encountered a Subprocess error: (Python bot)" in error.comment.body
        assert "no output" in error.comment.body

        # Clean my mess
        error.comment.delete()