Skip to content

Commit

Permalink
Added configuration to provide default bump label
Browse files Browse the repository at this point in the history
  • Loading branch information
Thejus-Paul committed Mar 11, 2023
1 parent afbef26 commit 393a847
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ The GitHub action to bump the gem or engine version from the pull request labels

**Optional** The pull request body to use. Default `"New version release"`.

### `default_bump_label`

**Optional** Provide a default bump label for cases when labels does not include a bump type label.

## Example usage

```yaml
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ inputs:
description: 'Provide a body for the PR.'
required: false
default: 'New version release'
default_bump_label:
description: 'Provide a default bump label for cases when labels does not include a bump type label'
required: false
runs:
using: 'node16'
main: 'dist/index.js'
Expand Down
Binary file modified dist/index.js.cache
Binary file not shown.
4 changes: 2 additions & 2 deletions dist/index.js.cache.js

Large diffs are not rendered by default.

29 changes: 20 additions & 9 deletions src/bump.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
const core = require("@actions/core");
const exec = require("@actions/exec");

const containsBumpTypeLabel = (labels) => {
const getLabels = (labels, defaultBumpLabel) => {
const bumpTypes = ["major", "minor", "patch"];
const labelsArray = labels.split(",");

if (labelsArray.length === 0 || labelsArray[0] === "") {
return false;
const isDefaultBumpLabelPresent = bumpTypes.some(
(bumpType) => bumpType === defaultBumpLabel
);
console.log({ isDefaultBumpLabelPresent });
const isBumpTypePresent = bumpTypes.some((bumpType) =>
labelsArray.includes(bumpType)
);
console.log({ isBumpTypePresent });

if (isBumpTypePresent) {
return labels;
} else {
return isDefaultBumpLabelPresent ? defaultBumpLabel : false;
}

return bumpTypes.some((bumpType) => labelsArray.includes(bumpType));
};

const bumpGem = async () => {
const labels = core.getInput("labels");
const defaultBumpLabel = core.getInput("default_bump_label");

const prLabels = getLabels(labels, defaultBumpLabel);

if (!labels || !containsBumpTypeLabel(labels)) {
if (!!prLabels) {
core.error(
"No bump type label (major, minor, or patch) was found in the PR."
"No bump type label (major, minor, or patch) or default bump label was found in the PR."
);
}

Expand All @@ -35,7 +46,7 @@ const bumpGem = async () => {
}

core.debug("Bumping gem version...");
await exec.exec(`bump_gem_version labels ${labels}`);
await exec.exec(`bump_gem_version labels ${prLabels}`);

core.info("Successfully bumped gem version! 🎉");

Expand Down

0 comments on commit 393a847

Please sign in to comment.