diff --git a/src/lando/api/legacy/workers/landing_worker.py b/src/lando/api/legacy/workers/landing_worker.py index 26b3abae3..e4084a689 100644 --- a/src/lando/api/legacy/workers/landing_worker.py +++ b/src/lando/api/legacy/workers/landing_worker.py @@ -50,6 +50,7 @@ ) from lando.pushlog.pushlog import PushLog, PushLogForRepo from lando.utils.config import read_lando_config +from lando.utils.github import GitHubAPIClient from lando.utils.tasks import phab_trigger_repo_update logger = logging.getLogger(__name__) @@ -144,6 +145,15 @@ def run_job(self, job: LandingJob) -> bool: job.set_landed_commit_ids() job.transition_status(JobAction.LAND, commit_id=commit_id) + if job.is_pull_request_job: + # TODO: move this to different method, and retry if needed. + # NOTE: This may need to happen on the revision-level when stack support is added. + pull_number = job.revisions.first().pull_number + message = f"Pull request closed by commit {commit_id}" + client = GitHubAPIClient(job.target_repo) + client.add_comment_to_pull_request(pull_number, message) + client.close_pull_request(pull_number) + mots_path = Path(repo.path) / "mots.yaml" if mots_path.exists(): logger.info(f"{mots_path} found, setting reviewer data.") diff --git a/src/lando/main/models/landing_job.py b/src/lando/main/models/landing_job.py index 4b28b4428..2ae4be170 100644 --- a/src/lando/main/models/landing_job.py +++ b/src/lando/main/models/landing_job.py @@ -47,6 +47,11 @@ class LandingJob(BaseJob): Revision, through="RevisionLandingJob", related_name="landing_jobs" ) + @property + def is_pull_request_job(self) -> bool: + """Return True if all revisions in the landing job have a pull_number set.""" + return not self.revisions.filter(pull_number__isnull=True).exists() + @property def landed_phabricator_revisions(self) -> dict: """Return a mapping associating Phabricator revision IDs with the ID of the landed Diff."""