From 5ca86d641489ef922361d60350ad203f1b877a07 Mon Sep 17 00:00:00 2001 From: aiell0 Date: Wed, 13 Dec 2023 11:09:58 -0500 Subject: [PATCH 1/4] feat: allow force option --- src/action.ts | 5 +++-- src/git-commands.ts | 4 +++- src/options.ts | 5 +++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/action.ts b/src/action.ts index 6388d44..ddae03f 100644 --- a/src/action.ts +++ b/src/action.ts @@ -36,7 +36,7 @@ export async function run(options: Options, actions: Actions): Promise { const octokit = new Octokit({auth: options.token, baseUrl: options.githubAPI}) - await gitProcessing(options.repository, options.branch, options.masterBranchName, files, options.message, octokit, actions, options.committer) + await gitProcessing(options.repository, options.branch, options.force, options.masterBranchName, files, options.message, octokit, actions, options.committer) if (options.createPR) { await createPullRequest( @@ -116,6 +116,7 @@ export function writeTo(content: string, filePath: string, actions: Actions): vo export async function gitProcessing( repository: string, branch: string, + force: boolean, masterBranchName: string, files: ChangedFile[], commitMessage: string, @@ -145,7 +146,7 @@ export async function gitProcessing( actions.debug(JSON.stringify({createdCommit: newCommitSha})) actions.setOutput('commit', newCommitSha) - await updateBranch(octokit, owner, repo, branch, newCommitSha, actions) + await updateBranch(octokit, owner, repo, branch, force, newCommitSha, actions) actions.debug(`Complete`) } diff --git a/src/git-commands.ts b/src/git-commands.ts index 71d9ffc..ceef1c1 100644 --- a/src/git-commands.ts +++ b/src/git-commands.ts @@ -122,6 +122,7 @@ export const updateBranch = async ( owner: string, repo: string, branch: string, + force: boolean, commitSha: string, actions: Actions ): Promise => { @@ -130,7 +131,8 @@ export const updateBranch = async ( owner, repo, ref: `heads/${branch}`, - sha: commitSha + sha: commitSha, + force: force || false }) } catch (error) { actions.info(`update branch ${branch} failed (${error}), fallback to create branch`) diff --git a/src/options.ts b/src/options.ts index 8730118..5b470aa 100644 --- a/src/options.ts +++ b/src/options.ts @@ -11,6 +11,7 @@ export interface Options { commitChange: boolean updateFile: boolean branch: string + force: boolean masterBranchName: string message: string title: string @@ -49,6 +50,10 @@ export class GitHubOptions implements Options { return core.getInput('branch') } + get force(): boolean { + return core.getInput('force') + } + get commitChange(): boolean { return core.getBooleanInput('commitChange') } From efb0be32155741b02cd7f250b8dbd26593231a93 Mon Sep 17 00:00:00 2001 From: aiell0 Date: Wed, 13 Dec 2023 12:11:20 -0500 Subject: [PATCH 2/4] chore: add input to actions.yaml --- action.yml | 4 ++++ src/git-commands.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 0c06d37..1299d72 100644 --- a/action.yml +++ b/action.yml @@ -32,6 +32,10 @@ inputs: required: false description: 'Branch to commit the change, will be created if not exist' default: 'master' + force: + required: false + description: 'Branch to commit the change, will be created if not exist' + default: 'false' masterBranchName: required: false description: 'Branch name of your master' diff --git a/src/git-commands.ts b/src/git-commands.ts index ceef1c1..d4ebbce 100644 --- a/src/git-commands.ts +++ b/src/git-commands.ts @@ -132,7 +132,7 @@ export const updateBranch = async ( repo, ref: `heads/${branch}`, sha: commitSha, - force: force || false + force: force }) } catch (error) { actions.info(`update branch ${branch} failed (${error}), fallback to create branch`) From 312b7085c733fdd756d1a56dd8681d7a9dbde66d Mon Sep 17 00:00:00 2001 From: aiell0 Date: Wed, 13 Dec 2023 13:03:44 -0500 Subject: [PATCH 3/4] docs: add parameter --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4460fc6..0dcc663 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,8 @@ Determine the behavior for none existing properties or array elements. | targetBranch | Opens a PR from __branch__ to __targetBranch__ if createPR is set to 'true' | `master` | | repository | The Repository where the YAML file is located and should be updated. You have to checkout this repository too and set the working-directory for this action to the same as the repository. See the example below | ${{github.repository}} | | branch | The updated YAML file will be committed to this branch, branch will be created if not exists | `master` | +| force | Allows force pushes | `false` | +| masterBranchName | Branch name of your master branch | `master` | | masterBranchName | Branch name of your master branch | `master` | | githubAPI | BaseURL for all GitHub REST API requests | https://api.github.com | | token | GitHub API Token which is used to create the PR, have to have right permissions for the selected repository | ${{github.token}} | From 4c8a07e4c1779b9802e23c75b4d888125bc80d62 Mon Sep 17 00:00:00 2001 From: aiell0 Date: Wed, 13 Dec 2023 14:09:32 -0500 Subject: [PATCH 4/4] fix: use getBooleanInput --- src/options.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/options.ts b/src/options.ts index 5b470aa..0d90cdb 100644 --- a/src/options.ts +++ b/src/options.ts @@ -51,7 +51,7 @@ export class GitHubOptions implements Options { } get force(): boolean { - return core.getInput('force') + return core.getBooleanInput('force') } get commitChange(): boolean {