Skip to content

Commit

Permalink
first iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandru Mihai authored and Alexandru Mihai committed Apr 27, 2021
0 parents commit 86ee2c2
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
package-lock.json
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Branch name normalizer

Simple action that normalizez the current branch name into a string with only lowercase alphanumerical values, separated by hiphens.
Example: For the branch name: Alex/A-Simple-pr. Output: `alex-a-simple-pr`

Inputs:

- **branch_name**:
- default: `$GITHUB_HEAD_REF`
- required: `false`
- **max_length**:
- default: `40`
- required: `false`

Output:

- **normalized**
18 changes: 18 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "Normalize branch name"
description: "Normalizes the branch into an "
inputs:
branch:
description: "Branch name to normalize. Defaults to $GITHUB_HEAD_REF"
required: false
max_length:
description: "Max length of the branch name. If exceeds, string will be striped down to first max_length chars. Defaults to 40 chars"
required: false
outputs:
normalized:
description: "Normalized branch name"
runs:
using: "node12"
main: "index.js"
branding:
icon: 'terminal'
color: 'green'
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const core = require("@actions/core");
const defaultMaxLength = 40
try {
const input = core.getInput("branch") ? core.getInput("branch") : process.env.GITHUB_HEAD_REF;
const maxBranchLength = core.getInput("max_length") ? core.getInput("max_length") : defaultMaxLength;
let output = input
.trim()
.toLowerCase()
.replace(/([^0-9a-zA-Z-]+)/g, "-");
if (output.length > maxBranchLength) {
output = output.substring(0, maxBranchLength);
}
core.setOutput("normalized", output);
if (output.charAt(output.length - 1) == '-') {
output = output.substring(0, output.length - 1);
}
} catch (err) {
core.setFailed(err);
}
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "branch-name-normalizer",
"version": "1.0.0",
"description": "Simple action that normalizez the current branch name into a string with only lowercase alphanumerical values, separated by hiphens. Example: For the branch name: Alex/A-Simple-pr. Output: `alex-a-simple-pr`",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@actions/core": "^1.2.7"
}
}

0 comments on commit 86ee2c2

Please sign in to comment.