-
Notifications
You must be signed in to change notification settings - Fork 708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PR authors in the changelog message #349
Comments
I've configured this to do the same, however, you cannot get the github username/link because git only contains the commiter name+email, if you wanted the link to profile, you'd have to look it up seperatly. When running you can provide a custom
But here it now includes extra keys Whatever writer you're using now has access to these keys to use them in their template. |
Thanks @samkelleher , you might be able to use GitHub API to fetch your username. |
I'm running this on repository with long history, and unfortunately process hangs with this custom format setting. As I inspected it's due to fact that for some reason in all cases information for all repository commits is retrieved (not just for range which is target of changelog), and custom |
hey guys, I was actually looking at how to add this to Lerna-Lite (a lighter fork of Lerna with extra features) and after a couple weeks and 2 implementations I think I got it all working with decent code, so I decided to post some piece of it which might help some of you. The 1st implementation was string manipulation before the save, it was working but not exactly ideal especially on the perf side. The 2nd implementation, which you can see in this Lerna-Lite PR extends both the writerOpts The first thing to note is that Lerna-Lite uses https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-core and so the pieces of code shown below are what that lib The first question of this issue of how to add the Git Author Name is actually easy to implement (once I understood the documentation) and we can modify, as suggested here, the import conventionalChangelogCore from 'conventional-changelog-core';
const GIT_COMMIT_WITH_AUTHOR_FORMAT = '%B%n-hash-%n%H%n-gitTags-%n%d%n-committerDate-%n%ci%n-authorName-%n%an%n-authorEmail-%n%ae%n-gpgStatus-%n%G?%n-gpgSigner-%n%GS';
const config = getChangelogConfig(changelogPreset, rootPath); // Lerna-Lite way of reading changelog preset config
setConfigChangelogCommitGitAuthor(config, gitRawCommitsOpts, writerOpts, changelogIncludeCommitsGitAuthor);
const changelogStream = conventionalChangelogCore(options, context, gitRawCommitsOpts, undefined, writerOpts);
export function setConfigChangelogCommitGitAuthor(config, gitRawCommitsOpts, writerOpts, commitCustomFormat) {
gitRawCommitsOpts.format = GIT_COMMIT_WITH_AUTHOR_FORMAT;
const extraCommitMsg = `by {{authorName}} ({{authorEmail}})`; // we can also customize this in different ways, which I did in Lerna-Lite
// read chosen preset's `commitPartial` and append our extra commit message to it
writerOpts.commitPartial =
config.writerOpts.commitPartial!.replace(/\n*$/, '') + ` {{#if @root.linkReferences~}}${extraCommitMsg}{{~/if}}\n`;
} I also wanted to have a way to add remote client login name and that was a bit more challenging and also as suggested we can use the GitHub API (Graphql in my case), for Lerna-Lite implementation I decided to read all commits since the last release which you can see the implementation in this file and this provides me an array of commits which shouldn't be too large since it's against the last release. I also did it that way because the import conventionalChangelogCore from 'conventional-changelog-core';
const GIT_COMMIT_WITH_AUTHOR_FORMAT = '%B%n-hash-%n%H%n-gitTags-%n%d%n-committerDate-%n%ci%n-authorName-%n%an%n-authorEmail-%n%ae%n-gpgStatus-%n%G?%n-gpgSigner-%n%GS';
const config = getChangelogConfig(changelogPreset, rootPath); // Lerna-Lite way of reading changelog preset config
setConfigChangelogCommitClientLogin(config, gitRawCommitsOpts, writerOpts, commitsSinceLastRelease, changelogIncludeCommitsClientLogin);
const changelogStream = conventionalChangelogCore(options, context, gitRawCommitsOpts, undefined, writerOpts);
export function setConfigChangelogCommitClientLogin(config, gitRawCommitsOpts, writerOpts, commitsSinceLastRelease, commitCustomFormat) {
gitRawCommitsOpts.format = GIT_COMMIT_WITH_AUTHOR_FORMAT;
const extraCommitMsg = `by @{{userLogin}}`;
writerOpts.commitPartial =
config.writerOpts.commitPartial!.replace(/\n*$/, '') + ` {{#if @root.linkReferences~}}${extraCommitMsg}{{~/if}}\n`;
// add commits since last release into the transform function
writerOpts.transform = writerOptsTransform.bind(null, config.writerOpts.transform, commitsSinceLastRelease);
}
/**
* Extend the writerOpts transform function from whichever preset config is loaded
* We will execute the original writerOpts transform function, then from it we'll add extra properties to the commit object
*/
export function writerOptsTransform(originalTransform, commitsSinceLastRelease, commit, context) {
// execute original writerOpts transform
const extendedCommit = originalTransform(commit, context);
// then add client remote detail (login) to the commit object and return it
if (extendedCommit) {
// search current commit with the commits since last release array returned from fetching GitHub API
const remoteCommit = commitsSinceLastRelease.find((c) => c.shortHash === commit.shortHash);
if (remoteCommit?.login) {
commit.userLogin = remoteCommit.login;
}
}
return extendedCommit;
} and that's it, I now have 2 different new features to chose from, 1st one is to add author's name/email (from git history) or the second feature is to add the remote client login name (from GitHub API). The reason that I have both is that I only implemented this for the GitHub client and so users of GitLab or other type of client would only be able to use the 1st feature because reading git history works for everyone and isn't limited to GitHub client. If you have any questions or comments, feel free to ask and if you want to see a live demo of this on a real project, then you can take a look at Lerna-Lite Releases which now uses these 2 options, the release v1.8.0 was with 1st implementation (git author name) while v1.9.0 was with the 2nd feature to fetch commits from GitHub API. Also to complete the picture, here's Lerna-Lite docs for these 2 features --changelog-include-commits-git-author and --changelog-include-commits-client-login I must say that the documentation on how and what to change for these things was really hard to understand and piece everything together, I had to search for a lot of issues opened in this project to find how to do what I wanted to do. |
I've been playing around with
standard-changelog
on these projects:Using https://github.com/diegohaz/singel/blob/master/CHANGELOG.md as an example, I was looking for a way to append something like
, thanks to @ts-de
(PR author) to the changelog message, but I can't see if that's possible with the CLI.The text was updated successfully, but these errors were encountered: