Skip to content

Commit

Permalink
feat: allow force pushes (#555)
Browse files Browse the repository at this point in the history
* feat: allow force option
* chore: add input to actions.yaml
* docs: add parameter
* fix: use getBooleanInput
  • Loading branch information
aiell0 authored Dec 13, 2023
1 parent 8093e03 commit cf2e493
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}} |
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 3 additions & 2 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function run(options: Options, actions: Actions): Promise<void> {

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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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`)
}
Expand Down
4 changes: 3 additions & 1 deletion src/git-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const updateBranch = async (
owner: string,
repo: string,
branch: string,
force: boolean,
commitSha: string,
actions: Actions
): Promise<void> => {
Expand All @@ -130,7 +131,8 @@ export const updateBranch = async (
owner,
repo,
ref: `heads/${branch}`,
sha: commitSha
sha: commitSha,
force: force
})
} catch (error) {
actions.info(`update branch ${branch} failed (${error}), fallback to create branch`)
Expand Down
5 changes: 5 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface Options {
commitChange: boolean
updateFile: boolean
branch: string
force: boolean
masterBranchName: string
message: string
title: string
Expand Down Expand Up @@ -49,6 +50,10 @@ export class GitHubOptions implements Options {
return core.getInput('branch')
}

get force(): boolean {
return core.getBooleanInput('force')
}

get commitChange(): boolean {
return core.getBooleanInput('commitChange')
}
Expand Down

0 comments on commit cf2e493

Please sign in to comment.