mirror of
https://github.com/valitydev/repo-file-sync-action.git
synced 2024-11-06 01:45:19 +00:00
parent
2816ce7d5c
commit
8c50c0d781
@ -52,7 +52,7 @@ jobs:
|
||||
#### Token
|
||||
In order for the Action to access your repositories you have to specify a [Personal Access token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token) as the value for `GH_PAT` (`GITHUB_TOKEN` will **not** work). The PAT needs the full repo scope ([#31](https://github.com/BetaHuhn/repo-file-sync-action/discussions/31#discussioncomment-674804)).
|
||||
|
||||
It is recommneded to set the token as a
|
||||
It is recommended to set the token as a
|
||||
[Repository Secret](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository).
|
||||
|
||||
Alternatively, you can provide the token of a GitHub App Installation via the `GH_INSTALLATION_TOKEN` input. You can obtain such token for example via [this](https://github.com/marketplace/actions/github-app-token) action. Tokens from apps have the advantage that they provide more granular access control.
|
||||
@ -108,7 +108,8 @@ Here are all the inputs [repo-file-sync-action](https://github.com/BetaHuhn/repo
|
||||
| `ASSIGNEES` | People to assign to the pull request | **No** | N/A |
|
||||
| `COMMIT_PREFIX` | Prefix for commit message and pull request title | **No** | 🔄 |
|
||||
| `COMMIT_BODY` | Commit message body. Will be appended to commit message, separated by two line returns. | **No** | '' |
|
||||
| `ORIGINAL_MESSAGE` | Use original commit message instead. Only works if the file(s) where changed and the action was triggered by pushing a single commit. | **No** | false |
|
||||
| `ORIGINAL_MESSAGE` | Use original commit message instead. Only works if the file(s) were changed and the action was triggered by pushing a single commit. | **No** | false |
|
||||
| `COMMIT_AS_PR_TITLE` | Use first line of the commit message as PR title. Only works if `ORIGINAL_MESSAGE` is `true` and working. | **No** | false |
|
||||
| `COMMIT_EACH_FILE` | Commit each file seperately | **No** | true |
|
||||
| `GIT_EMAIL` | The e-mail address used to commit the synced files | **Only when using installation token** | the email of the PAT used |
|
||||
| `GIT_USERNAME` | The username used to commit the synced files | **Only when using installation token** | the username of the PAT used |
|
||||
|
@ -67,6 +67,10 @@ inputs:
|
||||
description: |
|
||||
Re-use the original commit message for commits. Works only if the action is triggered by pushing one commit. Defaults to false
|
||||
required: false
|
||||
COMMIT_AS_PR_TITLE:
|
||||
description: |
|
||||
Re-use the commit message as PR title. Works only if ORIGINAL_MESSAGE is on and PR has one commit. Defaults to false
|
||||
required: false
|
||||
SKIP_PR:
|
||||
description: |
|
||||
Skips creating a Pull Request and pushes directly to the default branch. Defaults to false
|
||||
|
@ -100,6 +100,11 @@ try {
|
||||
type: 'boolean',
|
||||
default: false
|
||||
}),
|
||||
COMMIT_AS_PR_TITLE: getInput({
|
||||
key: 'COMMIT_AS_PR_TITLE',
|
||||
type: 'boolean',
|
||||
default: false
|
||||
}),
|
||||
BRANCH_PREFIX: getInput({
|
||||
key: 'BRANCH_PREFIX',
|
||||
default: 'repo-sync/SOURCE_REPO_NAME'
|
||||
|
@ -249,7 +249,7 @@ class Git {
|
||||
})
|
||||
}
|
||||
|
||||
async createOrUpdatePr(changedFiles) {
|
||||
async createOrUpdatePr(changedFiles, title) {
|
||||
const body = dedent(`
|
||||
Synced local file(s) with [${ GITHUB_REPOSITORY }](https://github.com/${ GITHUB_REPOSITORY }).
|
||||
|
||||
@ -268,6 +268,7 @@ class Git {
|
||||
const { data } = await this.github.pulls.update({
|
||||
owner: this.repo.user,
|
||||
repo: this.repo.name,
|
||||
title: `${ COMMIT_PREFIX } Synced file(s) with ${ GITHUB_REPOSITORY }`,
|
||||
pull_number: this.existingPr.number,
|
||||
body: body
|
||||
})
|
||||
@ -280,7 +281,7 @@ class Git {
|
||||
const { data } = await this.github.pulls.create({
|
||||
owner: this.repo.user,
|
||||
repo: this.repo.name,
|
||||
title: `${ COMMIT_PREFIX } Synced file(s) with ${ GITHUB_REPOSITORY }`,
|
||||
title: title === undefined ? `${ COMMIT_PREFIX } Synced file(s) with ${ GITHUB_REPOSITORY }` : title,
|
||||
body: body,
|
||||
head: this.prBranch,
|
||||
base: this.baseBranch
|
||||
|
17
src/index.js
17
src/index.js
@ -15,7 +15,8 @@ const {
|
||||
SKIP_CLEANUP,
|
||||
OVERWRITE_EXISTING_PR,
|
||||
SKIP_PR,
|
||||
ORIGINAL_MESSAGE
|
||||
ORIGINAL_MESSAGE,
|
||||
COMMIT_AS_PR_TITLE
|
||||
} = require('./config')
|
||||
|
||||
const run = async () => {
|
||||
@ -101,7 +102,9 @@ const run = async () => {
|
||||
modified.push({
|
||||
dest: file.dest,
|
||||
source: file.source,
|
||||
message: message[destExists].pr
|
||||
message: message[destExists].pr,
|
||||
useOriginalMessage: useOriginalCommitMessage,
|
||||
commitMessage: message[destExists].commit
|
||||
})
|
||||
}
|
||||
})
|
||||
@ -137,9 +140,12 @@ const run = async () => {
|
||||
})
|
||||
}
|
||||
|
||||
await git.commit(useOriginalCommitMessage ? git.originalCommitMessage() : undefined)
|
||||
const commitMessage = useOriginalCommitMessage ? git.originalCommitMessage() : undefined
|
||||
await git.commit(commitMessage)
|
||||
modified.push({
|
||||
dest: git.workingDir
|
||||
dest: git.workingDir,
|
||||
useOriginalMessage: useOriginalCommitMessage,
|
||||
commitMessage: commitMessage
|
||||
})
|
||||
}
|
||||
|
||||
@ -157,7 +163,8 @@ const run = async () => {
|
||||
</details>
|
||||
`)
|
||||
|
||||
const pullRequest = await git.createOrUpdatePr(COMMIT_EACH_FILE ? changedFiles : '')
|
||||
const useCommitAsPRTitle = COMMIT_AS_PR_TITLE && modified.length === 1 && modified[0].useOriginalMessage
|
||||
const pullRequest = await git.createOrUpdatePr(COMMIT_EACH_FILE ? changedFiles : '', useCommitAsPRTitle ? modified[0].commitMessage.split('\n', 1)[0].trim() : undefined)
|
||||
|
||||
core.notice(`Pull Request #${ pullRequest.number } created/updated: ${ pullRequest.html_url }`)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user