Skip to content

Commit

Permalink
✨ Add branch prefix option #32
Browse files Browse the repository at this point in the history
  • Loading branch information
BetaHuhn committed Apr 30, 2021
1 parent 000bf45 commit de55684
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ inputs:
description: |
Skips creating a Pull Request and pushes directly to the default branch. Defaults to false
required: false
BRANCH_PREFIX:
description: |
Specify a different prefix for the new branch in the target repo. Defaults to repo-sync/SOURCE_REPO_NAME
required: false

runs:
using: 'node12'
Expand Down
4 changes: 4 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ const context = {
key: 'SKIP_PR',
type: 'boolean',
default: false
}),
BRANCH_PREFIX: getVar({
key: 'BRANCH_PREFIX',
default: 'repo-sync/SOURCE_REPO_NAME'
})
}

Expand Down
7 changes: 5 additions & 2 deletions src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const {
TMP_DIR,
COMMIT_PREFIX,
GITHUB_REPOSITORY,
OVERWRITE_EXISTING_PR
OVERWRITE_EXISTING_PR,
BRANCH_PREFIX
} = require('./config')

const { dedent, execCmd } = require('./helpers')
Expand Down Expand Up @@ -58,7 +59,9 @@ const init = (repo) => {
}

const createPrBranch = async () => {
let newBranch = `repo-sync/${ GITHUB_REPOSITORY.split('/')[1] }/${ repo.branch }`
const prefix = BRANCH_PREFIX.replace('SOURCE_REPO_NAME', GITHUB_REPOSITORY.split('/')[1])

let newBranch = path.join(prefix, repo.branch)

if (OVERWRITE_EXISTING_PR === false) {
newBranch += `-${ Math.round((new Date()).getTime() / 1000) }`
Expand Down

0 comments on commit de55684

Please sign in to comment.