Skip to content

Commit 6f08f7d

Browse files
✨ Add COMMIT_BODY option (#44)
* Add a COMMIT_BODY option Some GitHub actions can check for specific content in a commit message's body. For example a versionbot that checks for content like `Change-type: patch`. This change allows the calling workflow to specify a string to use as the commit body. This string will be appended to the commit message, separated by two new lines. Change-type: minor Signed-off-by: Graham McCulloch <[email protected]> * Add example of COMMIT_BODY option to README Change-type: patch Signed-off-by: Graham McCulloch <[email protected]>
1 parent ef2904e commit 6f08f7d

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ Here are all the inputs [repo-file-sync-action](https://github.com/BetaHuhn/repo
9696
| `PR_LABELS` | Labels which will be added to the pull request. Set to false to turn off | **No** | sync |
9797
| `ASSIGNEES` | People to assign to the pull request | **No** | N/A |
9898
| `COMMIT_PREFIX` | Prefix for commit message and pull request title | **No** | 🔄 |
99+
| `COMMIT_BODY` | Commit message body. Will be appended to commit message, separated by two line returns. | **No** | '' |
99100
| `COMMIT_EACH_FILE` | Commit each file seperately | **No** | true |
100101
| `GIT_EMAIL` | The e-mail address used to commit the synced files | **No** | the email of the PAT used |
101102
| `GIT_USERNAME` | The username used to commit the synced files | **No** | the username of the PAT used |
@@ -319,6 +320,27 @@ The new branch will then be `custom-branch/SOURCE_BRANCH_NAME`.
319320

320321
> You can use `SOURCE_REPO_NAME` in your custom branch prefix as well and it will be replaced with the actual repo name
321322

323+
### Custom commit body
324+
325+
You can specify a custom commit body. This will be appended to the commit message, separated by two new lines. For example:
326+
327+
**.github/workflows/sync.yml**
328+
329+
```yml
330+
- name: Run GitHub File Sync
331+
uses: BetaHuhn/repo-file-sync-action@v1
332+
with:
333+
GH_PAT: ${{ secrets.GH_PAT }}
334+
COMMIT_BODY: "Change-type: patch"
335+
```
336+
337+
The above example would result in a commit message that looks something like this:
338+
```
339+
🔄 Synced local '<filename>' with remote '<filename>'
340+
341+
Change-type: patch
342+
```
343+
322344
### Advanced sync config
323345

324346
Here's how I keep common files in sync across my repositories. The main repository [`github-files`](https://github.com/BetaHuhn/github-files) contains all the files I want to sync and the [repo-file-sync-action](https://github.com/BetaHuhn/repo-file-sync-action) Action which runs on every push.

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ inputs:
2323
description: |
2424
Prefix for commit message and pull request title. Defaults to 🔄
2525
required: false
26+
COMMIT_BODY:
27+
description: |
28+
Commit message body. Will be appended to commit message, separated by two line returns. Defaults to ''
29+
required: false
2630
COMMIT_EACH_FILE:
2731
description: |
2832
Commit each file seperately. Defaults to true

dist/index.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -32842,6 +32842,10 @@ try {
3284232842
key: 'CONFIG_PATH',
3284332843
default: '.github/sync.yml'
3284432844
}),
32845+
COMMIT_BODY: getInput({
32846+
key: 'COMMIT_BODY',
32847+
default: ''
32848+
}),
3284532849
COMMIT_PREFIX: getInput({
3284632850
key: 'COMMIT_PREFIX',
3284732851
default: '🔄'
@@ -33035,6 +33039,7 @@ const {
3303533039
GIT_USERNAME,
3303633040
GIT_EMAIL,
3303733041
TMP_DIR,
33042+
COMMIT_BODY,
3303833043
COMMIT_PREFIX,
3303933044
GITHUB_REPOSITORY,
3304033045
OVERWRITE_EXISTING_PR,
@@ -33122,8 +33127,10 @@ const init = (repo) => {
3312233127
}
3312333128

3312433129
const commit = async (msg) => {
33125-
const message = msg !== undefined ? msg : `${ COMMIT_PREFIX } Synced file(s) with ${ GITHUB_REPOSITORY }`
33126-
33130+
let message = msg !== undefined ? msg : `${ COMMIT_PREFIX } Synced file(s) with ${ GITHUB_REPOSITORY }`
33131+
if (COMMIT_BODY) {
33132+
message += `\n\n${ COMMIT_BODY }`
33133+
}
3312733134
return execCmd(
3312833135
`git commit -m "${ message }"`,
3312933136
workingDir

src/config.js

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ try {
2323
key: 'CONFIG_PATH',
2424
default: '.github/sync.yml'
2525
}),
26+
COMMIT_BODY: getInput({
27+
key: 'COMMIT_BODY',
28+
default: ''
29+
}),
2630
COMMIT_PREFIX: getInput({
2731
key: 'COMMIT_PREFIX',
2832
default: '🔄'

src/git.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const {
77
GIT_USERNAME,
88
GIT_EMAIL,
99
TMP_DIR,
10+
COMMIT_BODY,
1011
COMMIT_PREFIX,
1112
GITHUB_REPOSITORY,
1213
OVERWRITE_EXISTING_PR,
@@ -94,8 +95,10 @@ const init = (repo) => {
9495
}
9596

9697
const commit = async (msg) => {
97-
const message = msg !== undefined ? msg : `${ COMMIT_PREFIX } Synced file(s) with ${ GITHUB_REPOSITORY }`
98-
98+
let message = msg !== undefined ? msg : `${ COMMIT_PREFIX } Synced file(s) with ${ GITHUB_REPOSITORY }`
99+
if (COMMIT_BODY) {
100+
message += `\n\n${ COMMIT_BODY }`
101+
}
99102
return execCmd(
100103
`git commit -m "${ message }"`,
101104
workingDir

0 commit comments

Comments
 (0)