Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
name: Syncing branches
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 12
node-version: 22
- name: Opening pull request
id: pull
uses: ./
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ jobs:
name: Syncing branches
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 12
node-version: 22
- name: Create Sync PR
uses: sudoStatus200/create-sync-pr@0.3.0
uses: sudoStatus200/create-sync-pr@0.3.1
with:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
SOURCE_BRANCH: "master"
Expand Down
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ inputs:
TARGET_BRANCH:
description: "Branch to make the pull-request against"
required: true
REVIEWERS:
description: "Users to review the pull-request"
required: false
TEAM_REVIEWERS:
description: "Team slug to review the pull request"
required: false
outputs:
PULL_REQUEST_URL:
description: "URL for either the generated pull request or the currently open one"
PULL_REQUEST_NUMBER:
description: "Pull request number from generated pull request or the currently open one"
runs:
using: "node12"
using: "node24"
main: "dist/index.js"
21 changes: 14 additions & 7 deletions create-branch.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
async function createBranch(octokit, context, branch) {
async function createOrUpdateBranch(octokit, repo, sha, branch) {
try {
await octokit.repos.getBranch({
...context.repo,
await octokit.rest.repos.getBranch({
...repo,
branch,
});
// If branch already exists, update ref
await octokit.rest.git.updateRef({
ref: `heads/${branch}`,
sha: sha,
force: true,
...repo,
});
} catch (error) {
if (error.name === "HttpError" && error.status === 404) {
await octokit.git.createRef({
await octokit.rest.git.createRef({
ref: `refs/heads/${branch}`,
sha: context.sha,
...context.repo,
sha: sha,
...repo,
});
} else {
console.log("Error while creating new branch");
Expand All @@ -18,4 +25,4 @@ async function createBranch(octokit, context, branch) {
}
}

module.exports = createBranch;
module.exports = createOrUpdateBranch;
Loading
Loading