def test_issue_comment_propose_update_handler( mock_issue_comment_functionality, issue_comment_propose_update_event ): flexmock(PackitAPI).should_receive("sync_release").and_return( PullRequest( title="foo", description="bar", target_branch="baz", source_branch="yet", id=1, status=PRStatus.open, url="https://xyz", author="me", created=datetime.now(), ) ) flexmock( GithubProject, get_files=lambda ref, filter_regex: [], get_web_url=lambda: "https://github.com/the-namespace/the-repo", is_private=lambda: False, ) flexmock(IssueCommentEvent, db_trigger=ProjectReleaseModel()) results = SteveJobs().process_message(issue_comment_propose_update_event) assert first_dict_value(results["jobs"])["success"]
def mocked_pr_create(*args, **kwargs): return PullRequest(title="", id=42, status=PRStatus.open, url="", description="", author="", source_branch="", target_branch="", created=datetime.datetime(1969, 11, 11, 11, 11, 11, 11))
def _pr_from_github_object(self, github_pr: GithubPullRequest) -> PullRequest: return PullRequest( title=github_pr.title, id=github_pr.id, status=PRStatus[github_pr.state], url=github_pr.html_url, description=github_pr.body, author=github_pr.user.name, source_branch=github_pr.head.ref, target_branch=github_pr.base.ref, created=github_pr.created_at, )
def _pr_from_gitlab_object(gitlab_pr) -> PullRequest: return PullRequest( title=gitlab_pr.title, id=gitlab_pr.iid, status=gitlab_pr.state, url=gitlab_pr.web_url, description=gitlab_pr.description, author=gitlab_pr.author["username"], source_branch=gitlab_pr.source_branch, target_branch=gitlab_pr.target_branch, created=gitlab_pr.created_at, )
def _pr_from_pagure_dict(self, pr_dict: dict) -> PullRequest: return PullRequest( title=pr_dict["title"], id=pr_dict["id"], status=PRStatus[pr_dict["status"].lower()], url="/".join([ self.service.instance_url, pr_dict["project"]["url_path"], "pull-request", str(pr_dict["id"]), ]), description=pr_dict["initial_comment"], author=pr_dict["user"]["name"], source_branch=pr_dict["branch_from"], target_branch=pr_dict["branch"], created=datetime.datetime.fromtimestamp( int(pr_dict["date_created"])), )
def pr_create( cls, original_object: Any, title: str, body: str, target_branch: str, source_branch: str, ) -> "PullRequest": output = PullRequest( title=title, description=body, target_branch=target_branch, source_branch=source_branch, id=cls.id, status=PRStatus.open, url=cls.url, author=cls.author, created=datetime.datetime.now(), ) return output
def test_issue_comment_propose_update_handler( mock_issue_comment_functionality, issue_comment_propose_update_event): flexmock(PackitAPI).should_receive("sync_release").and_return( PullRequest( title="foo", description="bar", target_branch="baz", source_branch="yet", id=1, status=PRStatus.open, url="https://xyz", author="me", created=datetime.now(), )) flexmock( GithubProject, get_files=lambda ref, filter_regex: [], ) flexmock(SteveJobs, _is_private=False) results = SteveJobs().process_message(issue_comment_propose_update_event) assert results["jobs"]["pull_request_action"]["success"]
def test_issue_comment_propose_downstream_handler( mock_issue_comment_functionality, issue_comment_propose_downstream_event): flexmock(PackitAPI).should_receive("sync_release").and_return( PullRequest( title="foo", description="bar", target_branch="baz", source_branch="yet", id=1, status=PRStatus.open, url="https://xyz", author="me", created=datetime.now(), )) flexmock( GithubProject, get_files=lambda ref, filter_regex: [], get_web_url=lambda: "https://github.com/the-namespace/the-repo", is_private=lambda: False, ) flexmock(IssueCommentEvent, db_trigger=IssueModel(id=123)) flexmock(IssueModel).should_receive("get_by_id").with_args(123).and_return( flexmock(issue_id=12345)) flexmock(Signature).should_receive("apply_async").once() processing_results = SteveJobs().process_message( issue_comment_propose_downstream_event) event_dict, job, job_config, package_config = get_parameters_from_results( processing_results) results = run_propose_downstream_handler( package_config=package_config, event=event_dict, job_config=job_config, ) assert first_dict_value(results["job"])["success"]
def rebase_pr_branch_and_comment( repo: git.Repo, pr: PullRequest, close_on_failure: bool = True ): """Rebase PR on top of target branch.""" num_behind = num_commits_behind( repo=repo, target_branch=pr.target_branch, source_branch=pr.source_branch ) if num_behind == 0: return None # pr is directly on top of target_branch cur_branch = repo.active_branch.name try: repo.git.checkout(pr.source_branch) repo.git.rebase(pr.target_branch) repo.git.push("origin", pr.source_branch, force=True) pr.comment(f"Rebased PR on top of {pr.target_branch}") except git.GitCommandError as exc: if close_on_failure: pr.comment(f"Failed to rebase PR on top of {pr.target_branch}.") pr.close() else: raise exc finally: repo.git.checkout(cur_branch)
from packit.distgit import DistGit from ogr.services.pagure import PagureProject, PagureService from ogr.abstract import PullRequest, PRStatus @pytest.mark.parametrize( "pr_list,number_prs", [ ( [ PullRequest( id=1, title="PR1", url="URL1", status=PRStatus.all, description="", author="", source_branch="", target_branch="", created=datetime.datetime.fromtimestamp(int(0)), ), PullRequest( id=2, title="PR2", url="URL2", status=PRStatus.all, description="", author="", source_branch="", target_branch="", created=datetime.datetime.fromtimestamp(int(0)),