Skip to content

Commit

Permalink
Audit: Also close the pull request and delete the branch
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Aug 6, 2024
1 parent 7dc7430 commit 0c59b00
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion github_app_geo_project/module/audit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 10 additions & 3 deletions github_app_geo_project/module/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 0c59b00

Please sign in to comment.