DEV Community

Kinga
Kinga

Posted on • Updated on

Rush and changelog generation - update

It's been fun to write the rush changefiles command, but I must admit I'm not using it much; the amount of change files generated during the commits, even if limited to major/minor/patch, is staggering.

Instead, I decided to go for another approach that... may even have a chance to make it into the rush🤞

The idea

  • The general idea of creating change files, and change logs stays the same.
  • When running rush change I can use additional parameter, let's say --show-commits that would show the commits.
  • And if --recommend-changetype parameter is used, the commits are parsed and the change type is suggested based on conventional commits

In the meantime...

Not sure when (if at all) this proposal will become reality, so I extended my generator-rush-conventionalcommits with rush whatchanged command.
It does two things:

  • Display commits history: For each project returned by projectAnalyzer.getChangedProjectsAsync, display commits history included in the revision range used by rush change, in a shortlog format
  • Suggest change type For each project returned by projectAnalyzer.getChangedProjectsAsync, filter commits in the revision range used by rush change, using conventional-commit-types as a reference

The script

rush-whatChanged.js uses projectAnalyzer to obtain the list of changed projects; it also mirrors projectAnalyzer functionality when obtaining the merge base, to make sure that the commits displayed/parsed are exactly the ones that triggered the need for the change file.

Display commit history

To display commit history, the script executes:

git shortlog ${mergeHash}... -- "${project.projectRelativeFolder}"
Enter fullscreen mode Exit fullscreen mode

This may be a lot of commits, so perhaps saving the history to a file might be a better idea.

Recommend change type

Calculating the change type follows conventional commits. The script invokes git rev-list --count --grep with a regular expression to filter and count commit messages.

To detect and count commits that may require major change:

git rev-list --count --extended-regexp --grep "(^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(.*?)?!:.*|^BREAKING CHANGE: )" -- "${projectFolder}"
Enter fullscreen mode Exit fullscreen mode

If no commits causing major change are found, the script searches for minor change commits:

git rev-list --count --extended-regexp --grep "^feat((.*?))?:" -- "${projectFolder}"
Enter fullscreen mode Exit fullscreen mode

And finally, if there are no major or minor changes, it will see if there are any commits causing patch bump:

git rev-list --count --extended-regexp --grep "^fix((.*?))?:" -- "${projectFolder}"
Enter fullscreen mode Exit fullscreen mode

The results will be summarized as following:
rush whatchanged result

You may download the latest version of the generator from npm.
The code is on GitHub

Top comments (0)