Skip to content
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

rename afterAddToChangelog hook to afterChangelog #1606

Merged
merged 1 commit into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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