Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support commenting on a PR when closing it #2415

Closed
bgilbert opened this issue Sep 29, 2023 · 4 comments
Closed

Support commenting on a PR when closing it #2415

bgilbert opened this issue Sep 29, 2023 · 4 comments

Comments

@bgilbert
Copy link
Contributor

Subject of the issue

create-pull-request doesn't comment on a PR when closing it. While it's possible to infer why the PR was closed, it'd be great if there were a way to configure some comment text to post to the PR.

@peter-evans
Copy link
Owner

Hi @bgilbert

There is only one case where the action causes a pull request to close. That is when there is no longer a diff with the base branch. The action updates the PR branch and when GitHub sees that it has no diff anymore GitHub automatically closes the PR.

If you want to handle this case and add a comment in the PR, this is how I would recommend achieving it.

permissions:
  pull-requests: write

...

      - name: Create Pull Request
        id: cpr
        uses: peter-evans/create-pull-request@v5

      - if: steps.cpr.outputs.pull-request-operation = 'closed'
        uses: peter-evans/create-or-update-comment@v3
        with:
          issue-number: ${{ steps.cpr.outputs.pull-request-number }}
          body: Pull request was closed because there was no longer a diff with the base branch.

@bgilbert
Copy link
Contributor Author

bgilbert commented Oct 4, 2023

That approach sounds reasonable to me, but it currently doesn't work: pull-request-number and pull-request-url aren't set when pull-request-operation is closed.

@peter-evans
Copy link
Owner

Oh, you're right. 🤦‍♂️

After thinking about this some more, I think this case is not easy to handle in the action because the action only indirectly causes the PR to close. I can't be 100% sure that when the branch is updated it caused the PR to close. A user could have closed it before that and left the branch undeleted. Sorry, but I don't think I have a good solution.

@bgilbert
Copy link
Contributor Author

bgilbert commented Oct 4, 2023

In the updated case, we query the API for the PR corresponding to the head branch. Would it make sense to also do that before deleting the branch, and if a PR is found, put its details in pull-request-{number,url}?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants