diff --git a/github_app_geo_project/module/audit/__init__.py b/github_app_geo_project/module/audit/__init__.py index 8d086266fb6..32fc3d66eb8 100644 --- a/github_app_geo_project/module/audit/__init__.py +++ b/github_app_geo_project/module/audit/__init__.py @@ -247,7 +247,7 @@ async def _process_snyk_dpkg( else: _LOGGER.debug("No changes to commit") - module_utils.close_pull_request_issues(f"Audit {key}", context.github_project) + module_utils.close_pull_request_issues(new_branch, f"Audit {key}", context.github_project) full_repo = f"{context.github_project.owner}/{context.github_project.repository}" transversal_message = ", ".join(short_message) diff --git a/github_app_geo_project/module/utils.py b/github_app_geo_project/module/utils.py index 82bca98e3bd..e043c3bc044 100644 --- a/github_app_geo_project/module/utils.py +++ b/github_app_geo_project/module/utils.py @@ -681,12 +681,19 @@ async def create_commit_pull_request( return create_pull_request(branch, new_branch, message, body, project) -def close_pull_request_issues(message: str, project: configuration.GithubProject) -> None: +def close_pull_request_issues(new_branch: str, message: str, project: configuration.GithubProject) -> None: """ - Close the pull request issues. + Close the pull request, issue and delete the branch. - If the pull request is open for 5 days, create an issue. + The 'Pull request is open for 5 days' issue. """ + pulls = project.repo.get_pulls(state="open", head=f"{project.repo.full_name.split('/')[0]}:{new_branch}") + if pulls.totalCount > 0: + pull_request = pulls[0] + pull_request.edit(state="closed") + + project.repo.get_git_ref(f"heads/{new_branch}").delete() + title = f"Pull request {message} is open for 5 days" issues = project.repo.get_issues( state="open", creator=project.application.integration.get_app().slug + "[bot]" # type: ignore[arg-type]