Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from 3ShapeInternal/features/missing-ref-warnin…
Browse files Browse the repository at this point in the history
…g-instead-of-error

This implementation gives the user the possibility to decide if the action should fail with an error or continue with a warning. This is done in order to make the action more flexible in the cases where a branch does not exist but the rest of the workflow that the action is used in is not dependent on that condition.
  • Loading branch information
Rasmus-Rosted authored Jan 22, 2021
2 parents b8fda04 + c5da44a commit 28303e9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
An action that deletes multiple branches from repository.
Optionally one can provide a `prefix` or `suffix` strings that would be appended or prepended to every branch name.
If it is needed to specify which owner and repository the branches are located in, then the `owner` and `repository` can be provided as well.
If setting the `soft_fail` flag to `true` a warning will be written to the console, and the action will continue, instead of the action failing. The default is `false`.

## Usage

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ inputs:
suffix:
description: Additional suffix to append to every branch name
required: false
soft_fail:
description: If set to `true` the workflow will continue if a branch reference is not found
required: false
default: false
runs:
using: node12
main: main.js
20 changes: 15 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ async function main() {
const branches = core.getInput("branches")
const prefix = core.getInput("prefix")
const suffix = core.getInput("suffix")
const soft_fail = core.getInput("soft_fail")

const client = github.getOctokit(token)

Expand All @@ -36,11 +37,20 @@ async function main() {

console.log("==> Deleting \"" + ownerOfRepository + "/" + repositoryContainingBranches + "/" + branch + "\" branch")

await client.git.deleteRef({
owner: ownerOfRepository,
repo: repositoryContainingBranches,
ref: "heads/" + branch
})
try {
await client.git.deleteRef({
owner: ownerOfRepository,
repo: repositoryContainingBranches,
ref: "heads/" + branch
})
} catch (error) {
const shouldFailSoftly = (soft_fail === 'true');

if(shouldFailSoftly)
core.warning(error.message)
else
core.setFailed(error.message)
}
}
} catch (error) {
core.setFailed(error.message)
Expand Down

0 comments on commit 28303e9

Please sign in to comment.