Skip to content

Commit 885895a

Browse files
authored
Add a branch suffix in config (#6)
1 parent f3e1bf0 commit 885895a

File tree

6 files changed

+32
-6
lines changed

6 files changed

+32
-6
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,29 @@ This is your custom PR Body
513513
This PR was created automatically by the repo-file-sync-action workflow run xxx.
514514
```
515515

516+
### Use a custom branch name per group
517+
518+
You can specify a custom branch name for each group of files. This is useful if you want to sync different files to
519+
different branches in the same repository.
520+
521+
```yaml
522+
group:
523+
- files:
524+
- source: A.txt
525+
branchSuffix: a
526+
repos: |
527+
https://custom.host/user/repo
528+
529+
- files:
530+
- source: B.txt
531+
branchSuffix: b
532+
repos: |
533+
https://custom.host/user/repo
534+
```
535+
536+
This will create two branches in the target repository: `repo-sync/SOURCE_REPO_NAME/a` and
537+
`repo-sync/SOURCE_REPO_NAME/b`.
538+
516539
### Fork and pull request workflow
517540

518541
If you do not wish to grant this action write access to target repositories, you can specify a bot/user Github acccount that you do have access to with the `FORK` parameter.

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ const parseFiles = (files) => {
197197
deleteOrphaned: item.deleteOrphaned === undefined ? DELETE_ORPHANED_DEFAULT : item.deleteOrphaned,
198198
excludeFilePatterns: item.excludeFilePatterns === undefined ? [] : item.excludeFilePatterns,
199199
includeFilePatterns: item.includeFilePatterns === undefined ? [] : item.includeFilePatterns,
200-
exclude: parseExclude(item.exclude, item.source)
200+
exclude: parseExclude(item.exclude, item.source),
201+
branchSuffix: item.branchSuffix || ''
201202
}
202203
}
203204

src/git.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,14 @@ export default class Git {
127127
)
128128
}
129129

130-
async createPrBranch() {
130+
async createPrBranch(branchSuffix) {
131131
const prefix = BRANCH_PREFIX.replace('SOURCE_REPO_NAME', GITHUB_REPOSITORY.split('/')[1])
132132

133133
let newBranch = path.join(prefix, this.repo.branch).replace(/\\/g, '/').replace(/\/\./g, '/')
134134
this.prBranch = newBranch
135135

136+
newBranch += branchSuffix ? `-${ branchSuffix }` : ''
137+
136138
if (OVERWRITE_EXISTING_PR === false) {
137139
newBranch += `-${ Math.round((new Date()).getTime() / 1000) }`
138140
this.prBranch = newBranch

src/helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export async function copy(src, dest, isDirectory, file) {
174174
}
175175
} else {
176176
core.debug(`Copy ${ src } to ${ dest }`)
177-
await fs.copy(src, dest,{ filter: filterFunc })
177+
await fs.copy(src, dest, { filter: filterFunc })
178178
}
179179

180180

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const {
2020
COMMIT_AS_PR_TITLE,
2121
FORK,
2222
REVIEWERS,
23-
TEAM_REVIEWERS,
23+
TEAM_REVIEWERS
2424
} = config
2525

2626
async function run() {
@@ -45,7 +45,7 @@ async function run() {
4545

4646
let existingPr
4747
if (SKIP_PR === false) {
48-
await git.createPrBranch()
48+
await git.createPrBranch(item.branchSuffix)
4949

5050
// Check for existing PR and add warning message that the PR maybe about to change
5151
existingPr = OVERWRITE_EXISTING_PR ? await git.findExistingPr() : undefined

0 commit comments

Comments
 (0)