octokit.rest.pulls.updateBranch() only when there are new commits in a PR's base branch #2682
Unanswered
thomasleplus
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I am working on a GitHub workflow based on
github-script
/octokit.js
. I am trying to automatically update a PR branch if there is a new commit in it's base branch. I am almost able to make it work using a scheduled workflow that regularly checks for open PRs and usesoctokit.rest.pulls.updateBranch()
to update the corresponding branch. But there's an issue: I expected the call to do nothing when there is no new commit but it doesn't seem to be the case. Instead it seems to always create a new merge commit in the PR branch, including an empty commit with there is nothing to update. I don't like this behavior because each empty commit triggers a bunch of workflows which is wasteful.Since I have the SHA of the latest commit on the base branch, I am thinking one solution would be to check if the PR branch contains the last commit from the base branch. I know how to do this using the CLI:
git branch <pr-branch> --contains <latest-base-sha>
But I couldn't find the equivalent in the octokit.js API. Does it exist? Or does anyone see a better way to achieve what I am trying to do?
For reference, this is the current draft of my
github-script
action:Excuse my poor node.js coding skills, I am new to this language. Also the reason why I am using a scheduled workflow to trigger this instead of doing it on each push to the base branch is that I am using various bots that push security updates via PRs that are auto-merged. Auto-merged pushes do not trigger workflows so that approach didn't work for me although it would have been much more elegant.
Cheers,
Tom
Beta Was this translation helpful? Give feedback.
All reactions