Skip to content

Commit

Permalink
Merge pull request #42 from ariatemplates/merge-pr
Browse files Browse the repository at this point in the history
Merge pull requests
  • Loading branch information
piuccio authored Mar 2, 2018
2 parents a13610a + e42d579 commit 3486aaa
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
node_modules
node_modules
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ More advanced options are
* `p` or `path` Git project path, defaults to the current working path
* `b` or `branch` Git branch, defaults to `master`
* `t` or `title` Regular expression to parse the commit title (see next chapter)
* `i` or `ignore-case` Ignore case flag for title's regular expression. `/.*/` becomes `/.*/i`
* `m` or `meaning` Meaning of capturing block in title's regular expression
* `f` or `file` JSON Configuration file, better option when you don't want to pass all parameters to the command line, for an example see [options.json](https://github.com/ariatemplates/git-release-notes/blob/master/options.json)
* `s` or `script` External script for post-processing commits
* `c` or `merge-commits` List only merge commits, `git log` command is executed with the `--merges` flag instead of `--no-merges`
* `o` or `gitlog-option` to add some additional git log options **and** ignores the `merge-commits` option, this is direct given to `git log` by adding a `--` to each longname option from the array (e.g. `-o first-parent`).

#### Title Parsing

Expand Down
17 changes: 14 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ var argv = require("optimist").usage("git-release-notes [<options>] <since>..<un
"alias": "title",
"default": "(.*)"
})
.boolean("i")
.alias("i", "ignore-case")
.options("m", {
"alias": "meaning",
"default": ['type']
Expand All @@ -22,16 +24,22 @@ var argv = require("optimist").usage("git-release-notes [<options>] <since>..<un
.options("s", {
"alias": "script"
})
.options("o", {
"alias": "gitlog-option",
"default" : []
})
.boolean("c")
.alias("c", "merge-commits")
.describe({
"f": "Configuration file",
"p": "Git project path",
"t": "Commit title regular expression",
"i": "Ignore case of title's regular expression",
"m": "Meaning of capturing block in title's regular expression",
"b": "Git branch, defaults to master",
"s": "External script to rewrite the commit history",
"c": "Only use merge commits"
"c": "Only use merge commits",
"o": "Additional git log options AND ignore 'c' option"
})
.boolean("version")
.check(function (argv) {
Expand Down Expand Up @@ -84,10 +92,11 @@ fs.readFile(template, function (err, templateContent) {
git.log({
branch: options.b,
range: argv._[0],
title: new RegExp(options.t),
title: options.i ? new RegExp(options.t, 'i') : new RegExp(options.t),
meaning: Array.isArray(options.m) ? options.m: [options.m],
cwd: options.p,
mergeCommits: options.c
mergeCommits: options.c,
additionalOptions: Array.isArray(options.o) ? options.o : [options.o]
}, function (commits) {
postProcess(templateContent, commits);
});
Expand All @@ -108,7 +117,9 @@ function getOptions (callback) {
options = {
b: stored.b || stored.branch || argv.b,
t: stored.t || stored.title || argv.t,
i: stored.i || stored.ignoreCase || argv.i,
m: stored.m || stored.meaning || argv.m,
o: stored.o || stored.gitlogOption || argv.o,
p: stored.p || stored.path || argv.p,
c: stored.c || stored.mergeCommits || argv.c
};
Expand Down
15 changes: 13 additions & 2 deletions lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@ var parser = require("debug")("release-notes:parser");

exports.log = function (options, callback) {
var spawn = require("child_process").spawn;
var commits = options.mergeCommits ? "--merges" : "--no-merges";
var gitArgs = ["log", "--no-color", commits, "--branches=" + options.branch, "--format=" + formatOptions, options.range];
var gitArgs = ["log", "--no-color"]
if (options.additionalOptions.length > 0) {
options.additionalOptions.forEach(function(o) {
gitArgs.push("--" + o);
});
} else {
gitArgs.push(options.mergeCommits ? "--merges" : "--no-merges");
}
gitArgs.push(
"--branches=" + options.branch,
"--format=" + formatOptions,
options.range
);
debug("Spawning git with args %o", gitArgs);
var gitLog = spawn("git", gitArgs, {
cwd : options.cwd,
Expand Down
50 changes: 50 additions & 0 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
},
"version": "2.1.0",
"dependencies": {
"date-fns": "^1.28.4",
"debug": "^2.6.0",
"date-fns": "^1.29.0",
"debug": "^3.1.0",
"ejs": "^2.5.7",
"optimist": "^0.6.1"
},
Expand All @@ -39,7 +39,7 @@
"homepage": "https://github.com/ariatemplates/git-release-notes",
"preferGlobal": true,
"devDependencies": {
"cross-env": "^5.0.5",
"eslint": "^4.5.0"
"cross-env": "^5.1.3",
"eslint": "^4.18.1"
}
}

0 comments on commit 3486aaa

Please sign in to comment.