Skip to content

Commit

Permalink
refactor: use object literal to transform commit type
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-koval committed Nov 3, 2019
1 parent 6c8d0cb commit 3b7ff9a
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 94 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -19,3 +19,6 @@ node_modules

# NPM files
.npmrc

# local configuration
.releaerc.yaml
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 48 additions & 54 deletions plugins.json
@@ -1,54 +1,48 @@
{
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"releaseRules": [
{
"type": "build",
"release": "patch"
},
{
"type": "ci",
"release": "patch"
},
{
"type": "chore",
"release": "patch"
},
{
"type": "docs",
"release": "patch"
},
{
"type": "refactor",
"release": "patch"
},
{
"type": "style",
"release": "patch"
},
{
"type": "test",
"release": "patch"
}
]
}
],
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
[
"@semantic-release/git",
{
"assets": [
"package.json",
"package-lock.json",
"CHANGELOG.md"
],
"message": "release(version): Release ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
],
"@semantic-release/github"
]
}
[
[
"@semantic-release/commit-analyzer",
{
"releaseRules": [
{
"type": "build",
"release": "patch"
},
{
"type": "ci",
"release": "patch"
},
{
"type": "chore",
"release": "patch"
},
{
"type": "docs",
"release": "patch"
},
{
"type": "refactor",
"release": "patch"
},
{
"type": "style",
"release": "patch"
},
{
"type": "test",
"release": "patch"
}
]
}
],
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
[
"@semantic-release/git",
{
"assets": ["package.json", "package-lock.json", "CHANGELOG.md"],
"message": "release(version): Release ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
],
"@semantic-release/github"
]
66 changes: 29 additions & 37 deletions release.config.js
@@ -1,47 +1,36 @@
const plugins = require("./plugins.json");
const plugins = require("./plugins");

parserOpts = {
mergePattern: /^Merge pull request #(\d+) from (.*)$/,
mergeCorrespondence: ["id", "source"]
const transformCommitType = type => {
const commitTypeMapping = {
feat: "Features",
fix: "Bug Fixes",
perf: "Performance Improvements",
revert: "Reverts",
docs: "Documentation",
style: "Styles",
refactor: "Code Refactoring",
test: "Tests",
build: "Build System",
ci: "Continuous Integration",
chore: "Chores",
default: () => {
return;
}
};
return commitTypeMapping[type] || commitTypeMapping["default"];
};

releaseRules = [{ type: "refactor", release: "patch" }];

customTransform = (commit, context) => {
const customTransform = (commit, context) => {
const issues = [];

commit.notes.forEach(note => {
note.title = `BREAKING CHANGES`;
});

if (commit.type === `feat`) {
commit.type = `Features`;
} else if (commit.type === `fix`) {
commit.type = `Bug Fixes`;
} else if (commit.type === `perf`) {
commit.type = `Performance Improvements`;
} else if (commit.type === `revert`) {
commit.type = `Reverts`;
} else if (commit.type === `docs`) {
commit.type = `Documentation`;
} else if (commit.type === `style`) {
commit.type = `Styles`;
} else if (commit.type === `refactor`) {
commit.type = `Code Refactoring`;
} else if (commit.type === `test`) {
commit.type = `Tests`;
} else if (commit.type === `build`) {
commit.type = `Build System`;
} else if (commit.type === `ci`) {
commit.type = `Continuous Integration`;
} else if (commit.type === `chore`) {
commit.type = `Chores`;
} else {
return;
}
commit.type = transformCommitType(commit.type);

if (commit.scope === `*`) {
commit.scope = ``;
if (commit.scope === "*") {
commit.scope = "";
}

if (typeof commit.hash === `string`) {
Expand Down Expand Up @@ -88,8 +77,11 @@ customTransform = (commit, context) => {
};

module.exports = {
releaseRules,
parserOpts,
releaseRules: plugins[0][1].releaseRules,
parserOpts: {
mergePattern: /^Merge pull request #(\d+) from (.*)$/,
mergeCorrespondence: ["id", "source"]
},
writerOpts: { transform: customTransform },
...plugins
plugins
};

0 comments on commit 3b7ff9a

Please sign in to comment.