Skip to content

Commit

Permalink
Merge pull request #1606 from intuit/after-changelog
Browse files Browse the repository at this point in the history
rename afterAddToChangelog hook to afterChangelog
  • Loading branch information
hipstersmoothie committed Oct 26, 2020
2 parents c9aa70d + 4f84e44 commit c9149a8
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 69 deletions.
2 changes: 1 addition & 1 deletion docs/pages/docs/plugins/release-lifecycle-hooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ These hooks is where the publishing of your package actually happens.
- [prCheck](#prCheck)
- [beforeShipIt](#beforeshipit)
- [beforeCommitChangelog](#beforecommitchangelog)
- [afterAddToChangelog](#afteraddtochangelog)
- [afterChangelog](#afterchangelog)
- [version](#version)
- [afterVersion](#afterversion)
- [publish](#publish)
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/__tests__/auto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1442,12 +1442,12 @@ describe("Auto", () => {
jest.spyOn(auto.release!, "addToChangelog").mockImplementation();
const beforeCommitChangelog = jest.fn();
auto.hooks.beforeCommitChangelog.tap("test", beforeCommitChangelog);
const afterAddToChangelog = jest.fn();
auto.hooks.afterAddToChangelog.tap("test", afterAddToChangelog);
const afterChangelog = jest.fn();
auto.hooks.afterChangelog.tap("test", afterChangelog);

await auto.shipit({ noChangelog: true });
expect(beforeCommitChangelog).not.toHaveBeenCalled();
expect(afterAddToChangelog).toHaveBeenCalled();
expect(afterChangelog).toHaveBeenCalled();
});

test("should not publish when behind remote", async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export interface IAutoHooks {
/** Ran before the `changelog` command commits the new release notes to `CHANGELOG.md`. */
beforeCommitChangelog: AsyncSeriesHook<[ChangelogLifecycle]>;
/** Ran after the `changelog` command adds the new release notes to `CHANGELOG.md`. */
afterAddToChangelog: AsyncSeriesHook<[ChangelogLifecycle]>;
afterChangelog: AsyncSeriesHook<[ChangelogLifecycle]>;
/** Ran after the `shipit` command has run. */
afterShipIt: AsyncParallelHook<
[
Expand Down Expand Up @@ -1763,7 +1763,7 @@ export default class Auto {
this.logger.verbose.info("Committed new changelog.");
}

await this.hooks.afterAddToChangelog.promise(context);
await this.hooks.afterChangelog.promise(context);
}

/** Make a release over a range of commits */
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/make-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const makeHooks = (): IAutoHooks => ({
modifyConfig: new SyncWaterfallHook(["config"]),
validateConfig: new AsyncSeriesBailHook(["name", "options"]),
beforeShipIt: new AsyncSeriesHook(["context"]),
afterAddToChangelog: new AsyncSeriesHook(["context"]),
afterChangelog: new AsyncSeriesHook(["context"]),
beforeCommitChangelog: new AsyncSeriesHook(["context"]),
afterShipIt: new AsyncParallelHook(["version", "commits", "context"]),
makeRelease: new AsyncSeriesBailHook(["releaseInfo"]),
Expand Down
27 changes: 15 additions & 12 deletions plugins/all-contributors/__tests__/all-contributors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jest.mock("child_process");
jest.mock("all-contributors-cli/dist/contributors");
jest.mock("all-contributors-cli/dist/generate");

// @ts-ignore
// @ts-ignore
generateReadme.mockImplementation(generateMock);
// @ts-ignore
addContributor.mockImplementation(addContributorMock);
Expand All @@ -38,7 +38,10 @@ env.mockImplementation(envMock);
jest.mock("../../../packages/core/dist/utils/exec-promise", () => (...args) =>
gitShow(...args)
);
jest.mock("../../../packages/core/dist/utils/get-lerna-packages", () => (...args: any[]) => getLernaPackages(...args));
jest.mock(
"../../../packages/core/dist/utils/get-lerna-packages",
() => (...args: any[]) => getLernaPackages(...args)
);
jest.spyOn(process, "chdir").mockReturnValue();

const mockRead = (result: string) =>
Expand Down Expand Up @@ -264,7 +267,7 @@ describe("All Contributors Plugin", () => {

releasedLabel.apply({ hooks: autoHooks, logger: dummyLog() } as Auto.Auto);

await autoHooks.afterAddToChangelog.promise({
await autoHooks.afterChangelog.promise({
bump: Auto.SEMVER.patch,
currentVersion: "0.0.0",
lastRelease: "0.0.0",
Expand Down Expand Up @@ -296,7 +299,7 @@ describe("All Contributors Plugin", () => {

releasedLabel.apply({ hooks: autoHooks, logger: dummyLog() } as Auto.Auto);

await autoHooks.afterAddToChangelog.promise({
await autoHooks.afterChangelog.promise({
bump: Auto.SEMVER.patch,
currentVersion: "0.0.0",
lastRelease: "0.0.0",
Expand Down Expand Up @@ -325,7 +328,7 @@ describe("All Contributors Plugin", () => {

releasedLabel.apply({ hooks: autoHooks, logger: dummyLog() } as Auto.Auto);

await autoHooks.afterAddToChangelog.promise({
await autoHooks.afterChangelog.promise({
bump: Auto.SEMVER.patch,
currentVersion: "0.0.0",
lastRelease: "0.0.0",
Expand Down Expand Up @@ -353,7 +356,7 @@ describe("All Contributors Plugin", () => {

releasedLabel.apply({ hooks: autoHooks, logger: dummyLog() } as Auto.Auto);

await autoHooks.afterAddToChangelog.promise({
await autoHooks.afterChangelog.promise({
bump: Auto.SEMVER.patch,
currentVersion: "0.0.0",
lastRelease: "0.0.0",
Expand All @@ -380,7 +383,7 @@ describe("All Contributors Plugin", () => {

releasedLabel.apply({ hooks: autoHooks, logger: dummyLog() } as Auto.Auto);

await autoHooks.afterAddToChangelog.promise({
await autoHooks.afterChangelog.promise({
bump: Auto.SEMVER.patch,
currentVersion: "0.0.0",
lastRelease: "0.0.0",
Expand Down Expand Up @@ -429,7 +432,7 @@ describe("All Contributors Plugin", () => {

releasedLabel.apply({ hooks: autoHooks, logger: dummyLog() } as Auto.Auto);

await autoHooks.afterAddToChangelog.promise({
await autoHooks.afterChangelog.promise({
bump: Auto.SEMVER.patch,
currentVersion: "0.0.0",
lastRelease: "0.0.0",
Expand Down Expand Up @@ -472,7 +475,7 @@ describe("All Contributors Plugin", () => {

releasedLabel.apply({ hooks: autoHooks, logger: dummyLog() } as Auto.Auto);

await autoHooks.afterAddToChangelog.promise({
await autoHooks.afterChangelog.promise({
bump: Auto.SEMVER.patch,
currentVersion: "0.0.0",
lastRelease: "0.0.0",
Expand Down Expand Up @@ -501,7 +504,7 @@ describe("All Contributors Plugin", () => {

releasedLabel.apply({ hooks: autoHooks, logger: dummyLog() } as Auto.Auto);

await autoHooks.afterAddToChangelog.promise({
await autoHooks.afterChangelog.promise({
bump: Auto.SEMVER.patch,
currentVersion: "0.0.0",
lastRelease: "0.0.0",
Expand Down Expand Up @@ -535,7 +538,7 @@ describe("All Contributors Plugin", () => {

releasedLabel.apply({ hooks: autoHooks, logger: dummyLog() } as Auto.Auto);

await autoHooks.afterAddToChangelog.promise({
await autoHooks.afterChangelog.promise({
bump: Auto.SEMVER.patch,
currentVersion: "0.0.0",
lastRelease: "0.0.0",
Expand Down Expand Up @@ -564,7 +567,7 @@ describe("All Contributors Plugin", () => {

releasedLabel.apply({ hooks: autoHooks, logger: dummyLog() } as Auto.Auto);

await autoHooks.afterAddToChangelog.promise({
await autoHooks.afterChangelog.promise({
bump: Auto.SEMVER.patch,
currentVersion: "0.0.0",
lastRelease: "0.0.0",
Expand Down
94 changes: 44 additions & 50 deletions plugins/all-contributors/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,62 +315,56 @@ export default class AllContributorsPlugin implements IPlugin {
});
});

auto.hooks.afterAddToChangelog.tapPromise(
this.name,
async ({ commits }) => {
const rootDir = process.cwd();
// Always do the root package
let packages = [{ path: rootDir, name: "root-package" }];

try {
// Try to get sub-packages
packages = [...packages, ...(await getLernaPackages())];
} catch (error) {}

// Go through each package and update code contributions
await packages.reduce(async (last, { name, path }) => {
// Cannot run git operations in parallel
await last;

auto.logger.verbose.info(`Updating contributors for: ${name}`);

const includedCommits = commits.filter((commit) =>
commit.files.some((file) => inFolder(path, file))
);
auto.hooks.afterChangelog.tapPromise(this.name, async ({ commits }) => {
const rootDir = process.cwd();
// Always do the root package
let packages = [{ path: rootDir, name: "root-package" }];

if (includedCommits.length > 0) {
auto.logger.verbose.success(
`${name} has ${includedCommits.length} new commits.`
);
auto.logger.veryVerbose.info(
`With commits: ${JSON.stringify(includedCommits, null, 2)}`
);
try {
// Try to get sub-packages
packages = [...packages, ...(await getLernaPackages())];
} catch (error) {}

process.chdir(path);
await this.updateContributors(auto, includedCommits);
}
}, Promise.resolve());
// Go through each package and update code contributions
await packages.reduce(async (last, { name, path }) => {
// Cannot run git operations in parallel
await last;

process.chdir(rootDir);
const changedFiles = await execPromise("git", [
"status",
"--porcelain",
]);
auto.logger.verbose.info(`Updating contributors for: ${name}`);

const includedCommits = commits.filter((commit) =>
commit.files.some((file) => inFolder(path, file))
);

if (changedFiles) {
await execPromise("git", ["add", "README.md"]);
await execPromise("git", ["add", ".all-contributorsrc"]);
await on(execPromise("git", ["add", "**/README.md"]));
await on(execPromise("git", ["add", "**/.all-contributorsrc"]));
await execPromise("git", [
"commit",
"--no-verify",
"-m",
'"Update contributors [skip ci]"',
]);
if (includedCommits.length > 0) {
auto.logger.verbose.success(
`${name} has ${includedCommits.length} new commits.`
);
auto.logger.veryVerbose.info(
`With commits: ${JSON.stringify(includedCommits, null, 2)}`
);

process.chdir(path);
await this.updateContributors(auto, includedCommits);
}
}, Promise.resolve());

process.chdir(rootDir);
const changedFiles = await execPromise("git", ["status", "--porcelain"]);

if (changedFiles) {
await execPromise("git", ["add", "README.md"]);
await execPromise("git", ["add", ".all-contributorsrc"]);
await on(execPromise("git", ["add", "**/README.md"]));
await on(execPromise("git", ["add", "**/.all-contributorsrc"]));
await execPromise("git", [
"commit",
"--no-verify",
"-m",
'"Update contributors [skip ci]"',
]);
}
);
});

auto.hooks.onCreateLogParse.tap(this.name, (logParse) => {
logParse.hooks.parseCommit.tapPromise(this.name, async (commit) => {
Expand Down

0 comments on commit c9149a8

Please sign in to comment.