Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ linkStyle default opacity:0.5
changesets_changelog(["@metamask/changesets-changelog"]);
changesets_utils(["@metamask/changesets-utils"]);
create_release_branch(["@metamask/create-release-branch"]);
changesets_changelog --> changesets_utils;
```

<!-- end dependency graph -->
Expand Down
1 change: 1 addition & 0 deletions packages/changesets-changelog/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Add local pull request resolution from Git commit subjects ([#84](https://github.com/MetaMask/release-tools/pull/84))
- Add Keep a Changelog categories and repository option validation ([#87](https://github.com/MetaMask/release-tools/pull/87))

[Unreleased]: https://github.com/MetaMask/release-tools/
2 changes: 2 additions & 0 deletions packages/changesets-changelog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
},
"dependencies": {
"@changesets/types": "^7.0.0",
"@metamask/changesets-utils": "^0.0.0",
"@metamask/utils": "^11.12.0",
"execa": "^8.0.1"
},
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions packages/changesets-changelog/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Re-exported as `categories` because the categorized changelog interface in
// `@metamask/apply-release-plan` requires a `categories` export.
export { CATEGORIES as categories } from '@metamask/changesets-utils';
29 changes: 29 additions & 0 deletions packages/changesets-changelog/src/options.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { describe, expect, it } from 'vitest';

import { getGitHubRepository, validateChangelogOptions } from './options.js';

describe('validateChangelogOptions', () => {
it('does not throw for options with a validated repository', () => {
expect(() =>
validateChangelogOptions({ repository: 'MetaMask/core' }),
).not.toThrow();
});

it.each([
null,
{},
{ repository: '' },
{ repository: ' ' },
{ repository: 123 },
])('throws when repository is missing or invalid: %j', (options) => {
expect(() => validateChangelogOptions(options)).toThrow('"repository"');
});
});

describe('getGitHubRepository', () => {
it('returns the validated repository', () => {
expect(getGitHubRepository({ repository: 'MetaMask/core' })).toBe(
'MetaMask/core',
);
});
});
37 changes: 37 additions & 0 deletions packages/changesets-changelog/src/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { hasProperty, isObject } from '@metamask/utils';

export type ChangelogOptions = {
repository: string;
};

/**
* Validates and narrows changelog options.
*
* @param changelogOpts - The changelog options.
* @throws If `repository` is missing or empty.
*/
export function validateChangelogOptions(
changelogOpts: unknown,
): asserts changelogOpts is ChangelogOptions {
if (
!isObject(changelogOpts) ||
!hasProperty(changelogOpts, 'repository') ||
typeof changelogOpts.repository !== 'string' ||
changelogOpts.repository.trim() === ''
) {
throw new Error(
'Please provide a repository to this changelog generator: "repository": "org/repo"',
);
}
}

/**
* Returns the configured GitHub repository.
*
* @param changelogOpts - The changelog options.
* @returns The repository in `owner/repo` form.
*/
export function getGitHubRepository(changelogOpts: unknown): string {
validateChangelogOptions(changelogOpts);
return changelogOpts.repository;
}
6 changes: 3 additions & 3 deletions packages/changesets-changelog/src/resolve-pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ export function extractPullRequestNumber(subject: string): string {
* Resolves the pull request link for a changeset using its local Git commit.
*
* @param changeset - The changeset whose commit should be inspected.
* @param repo - The GitHub repository in `owner/repo` form.
* @param repository - The GitHub repository in `owner/repo` form.
* @returns The Markdown pull request link.
*/
export async function getPullRequestLink(
changeset: NewChangesetWithCommit,
repo: string,
repository: string,
): Promise<string> {
if (!changeset.commit) {
throw new Error(`Changeset ${changeset.id} has no commit`);
Expand Down Expand Up @@ -61,5 +61,5 @@ export async function getPullRequestLink(
}

const pullRequestNumber = extractPullRequestNumber(subject.trim());
return `[#${pullRequestNumber}](https://github.com/${repo}/pull/${pullRequestNumber})`;
return `[#${pullRequestNumber}](https://github.com/${repository}/pull/${pullRequestNumber})`;
}
2 changes: 1 addition & 1 deletion packages/changesets-changelog/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"rootDir": "./src",
"types": ["node"]
},
"references": [],
"references": [{ "path": "../changesets-utils/tsconfig.build.json" }],
"include": ["./src"]
}
2 changes: 1 addition & 1 deletion packages/changesets-changelog/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"compilerOptions": {
"types": ["node"]
},
"references": [],
"references": [{ "path": "../changesets-utils/tsconfig.json" }],
"include": ["./src"]
}
2 changes: 1 addition & 1 deletion packages/changesets-changelog/tsconfig.lint.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"outDir": "./.tsc-lint-cache",
"tsBuildInfoFile": "./.tsc-lint-cache/tsconfig.tsbuildinfo"
},
"references": []
"references": [{ "path": "../changesets-utils/tsconfig.lint.json" }]
}
1 change: 1 addition & 0 deletions packages/changesets-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Returns new changeset and release objects, preserves summaries and metadata, drops changesets with no selected releases, and does not mutate its inputs.
- Add `restoreResidualChangesets` for rewriting Changeset files after a partial release ([#78](https://github.com/MetaMask/release-tools/pull/78))
- Writes back only the releases for packages that were not released, preserves the original summary and bump types, leaves fully consumed Changeset files deleted, and is safe to run more than once.
- Export the supported changeset categories for changelog plugins ([#87](https://github.com/MetaMask/release-tools/pull/87)).

[Unreleased]: https://github.com/MetaMask/release-tools/
16 changes: 16 additions & 0 deletions packages/changesets-utils/src/categories.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, expect, it } from 'vitest';

import { CATEGORIES } from './categories.js';

describe('categories', () => {
it('lists the supported changeset categories', () => {
expect(CATEGORIES).toStrictEqual([
'Added',
'Changed',
'Deprecated',
'Removed',
'Fixed',
'Security',
]);
});
});
13 changes: 13 additions & 0 deletions packages/changesets-utils/src/categories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* The changeset categories supported by the summary parser.
*/
export const CATEGORIES = [
'Added',
'Changed',
'Deprecated',
'Removed',
'Fixed',
'Security',
] as const;

export type ChangesetCategory = (typeof CATEGORIES)[number];
7 changes: 3 additions & 4 deletions packages/changesets-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
export { GrammarError } from './grammar-error.js';
export { CATEGORIES } from './categories.js';
export type { ChangesetCategory } from './categories.js';
export { filterChangesets } from './filter-changesets.js';
export {
restoreResidualChangesets,
type RestoreOptions,
} from './restore-residual-changesets.js';
export { parseChangesetSummary } from './parse-changeset-summary.js';
export type {
ChangesetCategory,
ParsedEntry,
} from './parse-changeset-summary.js';
export type { ParsedEntry } from './parse-changeset-summary.js';
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('parseChangesetSummary', () => {
'The summary must start with a level-two category heading.',
1,
'missing-heading',
'Start with a level-two heading such as `## Added`, `## Changed`, `## Removed`, `## Fixed`, `## Security`, or `## Deprecated`.',
'Start with a level-two heading such as `## Added`, `## Changed`, `## Deprecated`, `## Removed`, `## Fixed`, or `## Security`.',
),
],
[
Expand All @@ -96,7 +96,7 @@ describe('parseChangesetSummary', () => {
'The category heading must name a supported category.',
1,
'unknown-category',
'Use `Added`, `Changed`, `Removed`, `Fixed`, `Security`, or `Deprecated` as the category.',
'Use `Added`, `Changed`, `Deprecated`, `Removed`, `Fixed`, or `Security` as the category.',
),
],
[
Expand All @@ -106,7 +106,7 @@ describe('parseChangesetSummary', () => {
'The category heading must name a supported category.',
1,
'unknown-category',
'Use `Added`, `Changed`, `Removed`, `Fixed`, `Security`, or `Deprecated` as the category.',
'Use `Added`, `Changed`, `Deprecated`, `Removed`, `Fixed`, or `Security` as the category.',
),
],
[
Expand Down
13 changes: 2 additions & 11 deletions packages/changesets-utils/src/parse-changeset-summary.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import { CATEGORIES } from './categories.js';
import type { ChangesetCategory } from './categories.js';
import { GrammarError } from './grammar-error.js';

const CATEGORIES = [
'Added',
'Changed',
'Removed',
'Fixed',
'Security',
'Deprecated',
] as const;

export type ChangesetCategory = (typeof CATEGORIES)[number];

export type ParsedEntry = {
category: ChangesetCategory;
description: string;
Expand Down
4 changes: 3 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,8 @@ __metadata:
dependencies:
"@changesets/types": "npm:^7.0.0"
"@metamask/auto-changelog": "npm:^6.1.0"
"@metamask/changesets-utils": "npm:^0.0.0"
"@metamask/utils": "npm:^11.12.0"
"@types/node": "npm:^22.13.14"
"@typescript/native": "npm:typescript@^7.0.2"
"@vitest/coverage-istanbul": "npm:^5.0.1"
Expand All @@ -1266,7 +1268,7 @@ __metadata:
languageName: unknown
linkType: soft

"@metamask/changesets-utils@workspace:packages/changesets-utils":
"@metamask/changesets-utils@npm:^0.0.0, @metamask/changesets-utils@workspace:packages/changesets-utils":
version: 0.0.0-use.local
resolution: "@metamask/changesets-utils@workspace:packages/changesets-utils"
dependencies:
Expand Down
Loading