def pr_push(self, gh_pr): assert isinstance(gh_pr, GitHubPR), gh_pr pr = self._get(gh_pr.source.ref, gh_pr.target_ref) if pr is None: log.warning(f'found new PR {gh_pr.short_str()}') pr = gh_pr.to_PR(start_build=True) else: pr = pr.update_from_github_pr(gh_pr) self._set(gh_pr.source.ref, gh_pr.target_ref, pr)
def refresh_from_github_build_status(self, gh_pr, status): assert isinstance(gh_pr, GitHubPR), gh_pr pr = self._get(gh_pr.source.ref, gh_pr.target_ref) if pr is None: log.warning( f'found new PR during GitHub build status update {gh_pr.short_str()}' ) pr = gh_pr.to_PR() self._set(gh_pr.source.ref, gh_pr.target_ref, pr.update_from_github_status(status))
def refresh_from_ci_job(self, source, target, job): assert isinstance(job, Job), job assert isinstance(source, FQSHA), source assert isinstance(target, FQSHA), target pr = self._get(source.ref, target.ref) if pr is None: log.warning(f'ignoring job {job.id} for unknown source and target') return assert source.sha == pr.source.sha, f'{source} {pr}' assert target.sha == pr.target.sha, f'{target} {pr}' self._set(source.ref, target.ref, pr.refresh_from_batch_job(job))
def review(self, gh_pr, state): assert isinstance(gh_pr, GitHubPR), gh_pr assert state in ['pending', 'approved', 'changes_requested'] pr = self._get(gh_pr.source.ref, gh_pr.target_ref) if pr is None: log.warning(f'found new PR during review update {gh_pr.short_str()}') pr = gh_pr.to_PR(start_build=True) pr = pr.update_from_github_review_state(state) self._set(gh_pr.source.ref, gh_pr.target_ref, pr) if pr.is_mergeable(): self.heal_target(gh_pr.target_ref)
def ci_build_finished(self, source, target, job): assert isinstance(job, Job), job pr = self._get(source.ref, target.ref) if pr is None: log.warning( f'ignoring job {short_str_build_job(job)} for unknown {source.short_str()} ' f'and {target.short_str()}') return self._set(source.ref, target.ref, pr.update_from_completed_batch_job(job)) # eagerly heal because a finished job might mean new work to do self.heal_target(target.ref)
def refresh_from_ci_job(self, source, target, job): assert isinstance(job, Job), job assert isinstance(source, FQSHA), source assert isinstance(target, FQSHA), target pr = self._get(source.ref, target.ref) if pr is None: log.warning( f'ignoring job {job.id} for unknown source and target' ) return assert source.sha == pr.source.sha, f'{source} {pr}' assert target.sha == pr.target.sha, f'{target} {pr}' self._set(source.ref, target.ref, pr.refresh_from_batch_job(job))
def ci_build_finished(self, source, target, job): assert isinstance(job, Job), job pr = self._get(source.ref, target.ref) if pr is None: log.warning( f'ignoring job {short_str_build_job(job)} for unknown {source.short_str()} ' f'and {target.short_str()}' ) return self._set(source.ref, target.ref, pr.update_from_completed_batch_job(job)) # eagerly heal because a finished job might mean new work to do self.heal_target(target.ref)
def merge(self, pr): assert isinstance(pr, PR) log.info(f'merging {pr.short_str()}') (gh_response, status_code) = put_repo(pr.target.ref.repo.qname, f'pulls/{pr.number}/merge', json={ 'merge_method': 'squash', 'sha': pr.source.sha }, status_code=[200, 409]) if status_code == 200: log.info(f'successful merge of {pr.short_str()}') self._set(pr.source.ref, pr.target.ref, pr.merged()) else: assert status_code == 409, f'{status_code} {gh_response}' log.warning( f'failure to merge {pr.short_str()} due to {status_code} {gh_response}, ' f'removing PR, github state refresh will recover and retest ' f'if necessary') self.forget(pr.source.ref, pr.target.ref)
def merge(self, pr): assert isinstance(pr, PR) log.info(f'merging {pr.short_str()}') (gh_response, status_code) = put_repo( pr.target.ref.repo.qname, f'pulls/{pr.number}/merge', json={ 'merge_method': 'squash', 'sha': pr.source.sha }, status_code=[200, 409]) if status_code == 200: log.info(f'successful merge of {pr.short_str()}') self._set(pr.source.ref, pr.target.ref, pr.merged()) else: assert status_code == 409, f'{status_code} {gh_response}' log.warning( f'failure to merge {pr.short_str()} due to {status_code} {gh_response}, ' f'removing PR, github state refresh will recover and retest ' f'if necessary') self.forget(pr.source.ref, pr.target.ref)
def transition(self, other): if not isinstance(other, Merged): log.warning( f'usually Mergeable should go to Merged, but going to {other}') return other
def transition(self, other): if (not isinstance(other, Building) and not isinstance(other, Buildable)): log.warning(f'unusual transition {self} to {other}') return other
def try_to_cancel_job(job): try: job.cancel() job.delete() except requests.exceptions.HTTPError as e: log.warning(f'could not cancel job {job.id} due to {e}')
def transition(self, other): if not isinstance(other, Merged): log.warning( f'usually Mergeable should go to Merged, but going to {other}' ) return other