def test_report_status_by_comment( commit_sha, pr_id, state, check_names, url, result, ): project = GitlabProject(None, None, None) reporter = StatusReporter.get_instance(project=project, commit_sha=commit_sha, pr_id=pr_id) act_upon = flexmock(GitlabProject) comment_body = "\n".join(( "| Job | Result |", "| ------------- | ------------ |", f"| [{check_names}]({url}) | {result} |", "### Description\n", "should include this", )) if pr_id: act_upon.should_receive("get_pr").with_args(pr_id=pr_id).and_return( flexmock().should_receive("comment").with_args( body=comment_body).mock()).once() else: act_upon.should_receive("commit_comment").with_args( commit=commit_sha, body=comment_body, ).once() reporter.report_status_by_comment(state, url, check_names, "should include this")
def test_set_status_gitlab( commit_sha, pr_id, pr_object, state, description, check_name, url, ): project = GitlabProject(None, None, None) reporter = StatusReporter(project, commit_sha, pr_id) act_upon = flexmock( pr_object.source_project) if pr_id else flexmock(GitlabProject) act_upon.should_receive("set_commit_status").with_args(commit_sha, state, url, description, check_name, trim=True).once() if pr_id is not None: flexmock(GitlabProject).should_receive("get_pr").with_args( pr_id).and_return(pr_object) reporter.set_status(state, description, check_name, url)
instance_url="https://host2.name", hostname="host2.name", get_project_from_url=lambda url: "right-project", ), ], True, "right-project", ), ( "https://gitlab.gnome.org/lbarcziova/testing-ogr-repo", None, None, True, GitlabProject( repo="testing-ogr-repo", namespace="lbarcziova", service=GitlabService(instance_url="https://gitlab.gnome.org"), ), ), ( "https://src.stg.fedoraproject.org/rpms/python-dockerpty.git", None, [PagureService(instance_url="https://src.stg.fedoraproject.org")], True, PagureProject( repo="python-dockerpty", namespace="rpms", service=PagureService(instance_url="https://src.stg.fedoraproject.org"), ), ), (
def update_project(self, project: GitlabProject, conversion_tag: str): self.cleanup() # Clone repo from rpms/ and checkout the branch. dist_git_repo = git.Repo.clone_from( f"https://{self.cfg.dist_git_host}/{self.fullname}.git", self.dist_git_dir ) dist_git_repo.git.checkout(self.branch) # Check if the commit is the one we are expecting. if dist_git_repo.branches[self.branch].commit.hexsha != self.end_commit: logger.warning( f"Abandon updating {self.name}. " f"HEAD of {self.branch!r} is not matching commit " f"{self.end_commit!r} for which this updated was started." ) Pushgateway().push_abandoned_update() return # Clone repo from source-git/ using ssh, so it can be pushed later on. src_git_ssh_url = project.get_git_urls()["ssh"] src_git_repo = git.Repo.clone_from( src_git_ssh_url, self.src_git_dir, ) # Check-out the source-git branch, if already exists, # so that 'convert' knows that this is an update. remote_heads = [ ref.remote_head for ref in src_git_repo.references if isinstance(ref, git.RemoteReference) ] if self.branch in remote_heads: src_git_repo.git.checkout(self.branch) d2s = Dist2Src( dist_git_path=self.dist_git_dir, source_git_path=self.src_git_dir, ) d2s.convert(self.branch, self.branch) try: src_git_repo.git.tag( "--annotate", "--message", f"Converted from commit {self.end_commit},\nfrom branch {self.branch}.", conversion_tag, src_git_repo.heads[self.branch].commit, ) except git.GitCommandError as ex: if "already exists" in ex.stderr: # It might happen that an another task already updated the repo. # If this is the case, do nothing. return else: raise # Push the result to source-git. # Update moves the upstream ref tag, we need --tags --force to move it in remote. src_git_repo.git.push("origin", self.branch, tags=True, force=True) Pushgateway().push_created_update()