Skip to content

Commit

Permalink
added history commit message include and exclude filters
Browse files Browse the repository at this point in the history
  • Loading branch information
stbaer committed Jan 8, 2017
1 parent ccf704b commit dc354aa
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,21 @@ This is the default configuration:
productionBranchName: "master",
developBranchName: "develop",
upstream: "origin",
commitMessagesExclude: ['Merge tag'],
commitMessagesInclude: [],
buildCommand: null,
historyFile: null
}
```
- `versionFiles`: json files that contain a version field which should be bumped when releasing
- `productionBranchName` / `developBranchName`: self explanatory
- `upstream` can be changed in case there's an alias set for `origin`
- `commitMessagesExclude`: Array of strings, commit messages containing one of the strings won't be included in the History
- `commitMessagesInclude`: Array of strings, only include commit messages in the History that contain one of the strings
- if `commitMessagesInclude` contains one or more strings, the exclude array will be ignored
- `buildCommand`: this command will be run before finishing the release, e.g `npm run build`
- `historyFile`: if set it will prepend the history between the last release and this one to the file, e.g 'History.md'
- `productionBranchName` / `productionBranchName` - self explanatory
- `upstream` can be changed in case theres an alias set for `origin`


It can be overwritten by adding a `releaseConfig` field to the `package.json`.

Expand Down
4 changes: 3 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const configDefault = {
productionBranchName: 'master',
developBranchName: 'develop',
buildCommand: false,
historyFile: false
historyFile: false,
commitMessagesExclude: ['Merge tag'],
commitMessagesInclude: []
};
const config = Object.assign({}, configDefault, pkgConfig);

Expand Down
34 changes: 33 additions & 1 deletion lib/history.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,47 @@
const util = require('util');
const dateFormat = require('dateformat');
const shellEx = require('./ex').shellEx;
const handleError = require('./handle-error');
const config = require('./config').config;

const getCommitLogMessageFilter = () => {
const excludes = config.commitMessagesExclude;
const includes = config.commitMessagesInclude;
let filterStrings = [];
let invertGrep = false;

if (util.isArray(includes) && includes.length) {
filterStrings = includes;
} else if (util.isArray(excludes) && excludes.length) {
filterStrings = excludes;
invertGrep = true;
}

let filterExpr = '';

if (filterStrings.length) {
filterExpr += invertGrep ? '--invert-grep' : '--grep';
filterStrings.forEach((str) => {
filterExpr += ` --grep="${str}" `
});
}

return filterExpr;

};

const getHistoryString = (currentVersion, newVersion) => {
const logCommand = shellEx(`git log ${currentVersion}..HEAD --pretty=format:" * %s"`);

const filterExpr = getCommitLogMessageFilter();
const logCommand = shellEx(`git log ${filterExpr} ${currentVersion}..HEAD --pretty=format:" * %s"`);
const date = dateFormat(new Date(), 'longDate');

if (logCommand.code !== 0) {
handleError(logCommand.stderr);
}

console.log('______________', logCommand);

return `###${newVersion} — *${date}*\n\n${logCommand.stdout}\n`;
};

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gf-release",
"version": "1.2.1",
"version": "1.2.2",
"description": "git flow release node script",
"main": "index.js",
"bin": {
Expand Down Expand Up @@ -34,6 +34,7 @@
"chalk": "^1.1.3",
"dateformat": "^2.0.0",
"exec-sh": "^0.2.0",
"git-raw-commits": "^1.1.2",
"inquirer": "^2.0.0",
"loud-rejection": "^1.6.0",
"ora": "^0.4.0",
Expand Down

0 comments on commit dc354aa

Please sign in to comment.