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

Determine if a new PR was created #698

Closed
sheurich opened this issue Jan 22, 2021 · 5 comments · Fixed by #712
Closed

Determine if a new PR was created #698

sheurich opened this issue Jan 22, 2021 · 5 comments · Fixed by #712
Labels
enhancement New feature or request

Comments

@sheurich
Copy link

Subject of the issue

I would like to inform the next step in the workflow whether create-pull-request created a new PR, updated an existing PR or (successfully) did nothing. Ideally this would be implemented as an output from the action step.

This could be used e.g. by a subsequent non-idempotent step which should only run when a new PR has been created.

Steps to reproduce

The current set of outputs do not provide enough information about the action status; the pull-request-number and pull-request-url outputs are the same regardless of new, update or no-op activity.

@peter-evans peter-evans added the enhancement New feature or request label Jan 25, 2021
@peter-evans
Copy link
Owner

peter-evans commented Jan 25, 2021

Hi @sheurich

I've avoided adding this up to now because it is not quite as easy at it appears to implement. Firstly, the action handles create/update/delete of the git branch, and the create/update of the pull request on GitHub's API. So what use cases like yours are interested in is presumably a combination of these states. Secondly, there is the problem of what counts as "updated." For the update of the PR on GitHub's API the action doesn't check the current state of the title, body, labels, etc., it just sends a PATCH which would overwrite if there were changes. If there wasn't any changes the action would still consider that "updated." I'm not sure if users would find that satisfactory.

If would be helpful if you could explain what subsequent non-idempotent step you are planning to run.

@sheurich
Copy link
Author

If would be helpful if you could explain what subsequent non-idempotent step you are planning to run.

👋🏽 @peter-evans

I want to notify an external system, e.g. using the Jira API to create a ticket, only when a PR is created or updated.

One use-case might be tracking an upstream repository and updating a fork using the c-p-r action. Running this on a timed basis should create a ticket for a person to review the PR when created or when updated with additional upstream changes.

@peter-evans
Copy link
Owner

Would it work for you if the action returned an output with one of following values?

created - The action only returns this if a new pull request has been created. What this means is that a new PR is created via the GitHub API, regardless of the state of the pull request branch.
updated - The action returns this if the pull request branch is updated. This means there are changes to the PR diff. (This will not be returned if other inputs like title, body, labels, etc., are updated.)
closed - The action returns this when it deletes the pull request branch. This causes GitHub to automatically close the associated pull request if it exists.
- The action returns an empty string if none of the above are true.

@sheurich
Copy link
Author

Your proposed change would fix my issue perfectly. Thanks!

@peter-evans
Copy link
Owner

Released as v3.8.0 / v3.

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

Successfully merging a pull request may close this issue.

2 participants