Skip to content

Commit 3d4ffab

Browse files
committed
chore: Support changeset type shorthands via shared source of truth
1 parent 1a8e934 commit 3d4ffab

9 files changed

Lines changed: 126 additions & 62 deletions

File tree

.github/actions/check-pr/index.js

Lines changed: 44 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/merge-and-write-changelogs/index.js

Lines changed: 14 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build-packages/changeset-types.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* eslint-disable jsdoc/require-jsdoc */
2+
export const messageTypes = [
3+
{
4+
name: 'compat',
5+
title: 'Compatibility Notes',
6+
alternatives: ['compatibility', 'compatibility note', 'compat']
7+
},
8+
{
9+
name: 'feat',
10+
title: 'New Features',
11+
alternatives: ['new', 'new functionality', 'feat']
12+
},
13+
{
14+
name: 'fix',
15+
title: 'Fixed Issues',
16+
alternatives: ['bug', 'bug fix', 'fixed issue', 'fix', 'fix issue']
17+
},
18+
{
19+
name: 'known-issue',
20+
title: 'Known Issues',
21+
alternatives: ['known issue']
22+
},
23+
{
24+
name: 'impr',
25+
title: 'Improvements',
26+
alternatives: ['improvement', 'improv']
27+
},
28+
{
29+
name: 'dep',
30+
title: 'Updated Dependencies',
31+
alternatives: ['dependency', 'dependency update']
32+
}
33+
];
34+
35+
export type MessageType = (typeof messageTypes)[number];

build-packages/check-pr/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"type": "module",
88
"scripts": {
99
"compile": "tsc -p tsconfig.json",
10-
"postcompile": "ncc build lib/index.js --out ../../.github/actions/check-pr/",
10+
"postcompile": "ncc build lib/check-pr/index.js --out ../../.github/actions/check-pr/",
1111
"test": "pnpm run test:unit",
1212
"test:unit": "NODE_OPTIONS=--experimental-vm-modules pnpm exec jest",
1313
"lint": "eslint --ignore-pattern '!index.ts' && prettier --check **/*.ts",

build-packages/check-pr/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"strict": true,
88
"skipLibCheck": true,
99
"isolatedModules": true,
10+
"rootDir": "..",
1011
"outDir": "./lib",
1112
"tsBuildInfoFile": "./lib/.tsbuildinfo"
1213
},

build-packages/check-pr/validators.spec.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,32 @@ describe('check-pr', () => {
124124
it('should fail if change type is wrong', async () => {
125125
const fileContents = [
126126
"'@sap-cloud-sdk/generator': major",
127-
'[Fix] Something is fixed.'
127+
'[Something] Something is fixed.'
128128
];
129129
validateChangesets('chore!', '', true, fileContents);
130130
expect(setFailed).toHaveBeenCalledWith(
131-
"All change types must match one of the allowed change types '[Known Issue]' or '[Compatibility Note]' or '[New Functionality]' or '[Improvement]' or '[Fixed Issue]'."
131+
"All change types must be one of: 'compat', 'feat', 'fix', 'known-issue', 'impr', 'dep' (or their aliases)."
132132
);
133133
});
134134

135+
it('should pass if shorthand change type is provided', async () => {
136+
const fileContents = [
137+
"'@sap-cloud-sdk/generator': major",
138+
'[fix] Something is fixed.'
139+
];
140+
validateChangesets('chore!', '', true, fileContents);
141+
expect(setFailed).not.toHaveBeenCalled();
142+
});
143+
144+
it('should pass if compat shorthand change type is provided', async () => {
145+
const fileContents = [
146+
"'@sap-cloud-sdk/generator': major",
147+
'[compat] Something changed.'
148+
];
149+
validateChangesets('chore!', '', true, fileContents);
150+
expect(setFailed).not.toHaveBeenCalled();
151+
});
152+
135153
it('should pass if correct change type is provided', async () => {
136154
const fileContents = [
137155
"'@sap-cloud-sdk/generator': major",

build-packages/check-pr/validators.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { readFile } from 'node:fs/promises';
33
import { resolve } from 'node:path';
44
import { getInput, setFailed, info } from '@actions/core';
5+
import { messageTypes } from '../changeset-types.js';
56

67
const validCommitTypes = ['feat', 'fix', 'chore'];
78

@@ -115,13 +116,10 @@ export function validateChangesets(
115116
fileContents: string[]
116117
): void {
117118
const allowedBumps = getAllowedBumps(commitType, isBreaking);
118-
const allowedChangeTypes = [
119-
'Known Issue',
120-
'Compatibility Note',
121-
'New Functionality',
122-
'Improvement',
123-
'Fixed Issue'
124-
];
119+
const allAllowedTypes = messageTypes.flatMap(({ name, alternatives }) => [
120+
name,
121+
...alternatives
122+
]);
125123

126124
if (!hasMatchingChangeset(allowedBumps, fileContents)) {
127125
return setFailed(
@@ -141,14 +139,12 @@ export function validateChangesets(
141139
}
142140

143141
const allChangeTypesMatch = changeTypes.every(type =>
144-
allowedChangeTypes.includes(type)
142+
allAllowedTypes.includes(type.toLowerCase())
145143
);
146144

147145
if (!allChangeTypesMatch) {
148146
return setFailed(
149-
`All change types must match one of the allowed change types ${allowedChangeTypes
150-
.map(type => `'[${type}]'`)
151-
.join(' or ')}.`
147+
`All change types must be one of: ${messageTypes.map(({ name }) => `'${name}'`).join(', ')} (or their aliases).`
152148
);
153149
}
154150

build-packages/merge-and-write-changelogs/index.ts

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,7 @@ import { readFile, writeFile } from 'node:fs/promises';
33
import { resolve } from 'node:path';
44
import { setFailed, info } from '@actions/core';
55
import { getPackages } from '@manypkg/get-packages';
6-
7-
const messageTypes = [
8-
{
9-
name: 'compat',
10-
title: 'Compatibility Notes',
11-
alternatives: ['compatibility', 'compatibility note', 'compat']
12-
},
13-
{
14-
name: 'feat',
15-
title: 'New Features',
16-
alternatives: ['new', 'new functionality', 'feat']
17-
},
18-
{
19-
name: 'fix',
20-
title: 'Fixed Issues',
21-
alternatives: ['bug', 'bug fix', 'fixed issue', 'fix', 'fix issue']
22-
},
23-
{
24-
name: 'impr',
25-
title: 'Improvements',
26-
alternatives: ['improvement', 'improv']
27-
},
28-
{
29-
name: 'dep',
30-
title: 'Updated Dependencies',
31-
alternatives: ['dependency', 'dependency update']
32-
}
33-
];
34-
35-
type MessageType = (typeof messageTypes)[number];
6+
import { messageTypes, type MessageType } from '../changeset-types.js';
367

378
interface Change {
389
packageNames: string[];

build-packages/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}

0 commit comments

Comments
 (0)