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

[ISSUE-44] Get commit SHA from pull_request.merge_commit_sha #72

Merged
merged 2 commits into from
Feb 10, 2023
Merged

[ISSUE-44] Get commit SHA from pull_request.merge_commit_sha #72

merged 2 commits into from
Feb 10, 2023

Conversation

lampajr
Copy link
Contributor

@lampajr lampajr commented Feb 10, 2023

Fixes #44

As per linked issue, this PR aims to update the way in which the commit SHA to be cherry picked is retrieved.

Instead of getting it from process.env.GITHUB_SHA, it retrieves that SHA from contex.payload.pull_request.merge_commit_sha, whose value change depending on the pull request status [1]

In this way it is possible to cherry-pick pull requests that have merged some time ago, even if new commits have been added on top of the original PR's target branch. This was not possible if using pull_request_target workflow.

[1] https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request does not contain a valid label. Please add one of the following labels: bug, enhancement, maintenance

@lampajr
Copy link
Contributor Author

lampajr commented Feb 10, 2023

@carloscastrojumo here it is, I tried an example here where I exeuted the following actions:

  1. Merge this first PR Update file1.txt lampajr/backporting-example#41 without backporting it
  2. Merge and backport this PR Update file2.txt lampajr/backporting-example#42
  3. Add the labels on the first PR in order to backport it, this correctly generated [cherry-pick] Update file1.txt lampajr/backporting-example#46 and [cherry-pick] Update file1.txt lampajr/backporting-example#45 even if on the main branch a new commit was added by the second PR.

NOTE: the backport is triggered using labels, see the workflow definition for more details.

Copy link
Owner

@carloscastrojumo carloscastrojumo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome @lampajr. Thank you for showing the working example btw.

@carloscastrojumo carloscastrojumo added the enhancement New feature or request label Feb 10, 2023
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 this pull request may close these issues.

Use pull_request.merge_commit_sha instead of process.env.GITHUB_SHA
3 participants