Skip to content

Commit 8bb2039

Browse files
committed
rename lang to scope
1 parent 94ea151 commit 8bb2039

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

scripts/release/__tests__/create-release-issue.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('create release issue', () => {
2121
it('parses commit', () => {
2222
expect(parseCommit(`b2501882 fix(javascript): fix the thing`)).toEqual({
2323
hash: 'b2501882',
24-
lang: 'javascript',
24+
scope: 'javascript',
2525
message: 'fix the thing',
2626
raw: 'b2501882 fix(javascript): fix the thing',
2727
type: 'fix',
@@ -31,7 +31,7 @@ describe('create release issue', () => {
3131
it('considers `specs` as a lang commit', () => {
3232
expect(parseCommit(`b2501882 fix(specs): fix the thing`)).toEqual({
3333
hash: 'b2501882',
34-
lang: 'specs',
34+
scope: 'specs',
3535
message: 'fix the thing',
3636
raw: 'b2501882 fix(specs): fix the thing',
3737
type: 'fix',
@@ -149,7 +149,7 @@ describe('create release issue', () => {
149149
{
150150
hash: 'b2501882',
151151
type: 'feat',
152-
lang: 'javascript',
152+
scope: 'javascript',
153153
message: 'update the API (BREAKING CHANGE)',
154154
raw: 'b2501882 feat(javascript): update the API (BREAKING CHANGE)',
155155
},
@@ -176,7 +176,7 @@ describe('create release issue', () => {
176176
{
177177
hash: 'b2501882',
178178
type: 'feat',
179-
lang: 'php',
179+
scope: 'php',
180180
message: 'update the API',
181181
raw: 'b2501882 feat(php): update the API',
182182
},
@@ -203,7 +203,7 @@ describe('create release issue', () => {
203203
{
204204
hash: 'b2501882',
205205
type: 'fix',
206-
lang: 'java',
206+
scope: 'java',
207207
message: 'fix some bug',
208208
raw: 'b2501882 fix(java): fix some bug',
209209
},
@@ -230,7 +230,7 @@ describe('create release issue', () => {
230230
{
231231
hash: 'b2501882',
232232
type: 'fix',
233-
lang: 'java',
233+
scope: 'java',
234234
message: 'fix some bug',
235235
raw: 'b2501882 fix(java): fix some bug',
236236
},
@@ -259,7 +259,7 @@ describe('create release issue', () => {
259259
{
260260
hash: 'b2501882',
261261
type: 'fix',
262-
lang: 'specs',
262+
scope: 'specs',
263263
message: 'fix some descriptions',
264264
raw: 'b2501882 fix(specs): fix some descriptions',
265265
},
@@ -291,14 +291,14 @@ describe('create release issue', () => {
291291
{
292292
hash: 'b2501882',
293293
type: 'fix',
294-
lang: 'php',
294+
scope: 'php',
295295
message: 'fix some descriptions',
296296
raw: 'b2501882 feat(php): fix some descriptions',
297297
},
298298
{
299299
hash: 'b2501882',
300300
type: 'feat',
301-
lang: 'specs',
301+
scope: 'specs',
302302
message: 'add some descriptions',
303303
raw: 'b2501882 feat(specs): add some descriptions',
304304
},
@@ -330,7 +330,7 @@ describe('create release issue', () => {
330330
{
331331
hash: 'b2501882',
332332
type: 'chore',
333-
lang: 'javascript',
333+
scope: 'javascript',
334334
message: 'update devDevpendencies',
335335
raw: 'b2501882 chore(javascript): update devDevpendencies',
336336
},

scripts/release/create-release-issue.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
REPO,
1313
} from '../common';
1414
import { getPackageVersionDefault } from '../config';
15-
import type { Language } from '../types';
1615

1716
import { RELEASED_TAG, getOctokit } from './common';
1817
import TEXT from './text';
@@ -21,10 +20,13 @@ import type {
2120
VersionsWithoutReleaseType,
2221
PassedCommit,
2322
Commit,
23+
Scope,
2424
} from './types';
2525

2626
dotenv.config({ path: ROOT_ENV_PATH });
2727

28+
const COMMON_SCOPES = ['specs'];
29+
2830
export function readVersions(): VersionsWithoutReleaseType {
2931
return Object.fromEntries(
3032
LANGUAGES.map((lang) => [lang, { current: getPackageVersionDefault(lang) }])
@@ -101,18 +103,18 @@ export function parseCommit(commit: string): Commit {
101103
}
102104
message = message.slice(message.indexOf(':') + 1).trim();
103105
type = matchResult[1];
104-
const lang = matchResult[2] as Language;
106+
const scope = matchResult[2] as Scope;
105107
// A spec commit should be added to every clients, as it mostly imply a client change.
106-
const allowedLanguages = [...LANGUAGES, 'specs'];
108+
const allowedScopes = [...LANGUAGES, ...COMMON_SCOPES];
107109

108-
if (!allowedLanguages.includes(lang)) {
110+
if (!allowedScopes.includes(scope)) {
109111
return { error: 'unknown-language-scope' };
110112
}
111113

112114
return {
113115
hash,
114116
type, // `fix` | `feat` | `chore` | ...
115-
lang, // `specs` | `javascript` | `php` | `java` | ...
117+
scope, // `specs` | `javascript` | `php` | `java` | ...
116118
message,
117119
raw: commit,
118120
};
@@ -129,7 +131,8 @@ export function decideReleaseStrategy({
129131
return Object.entries(versions).reduce(
130132
(versionsWithReleaseType: Versions, [lang, version]) => {
131133
const commitsPerLang = commits.filter(
132-
(commit) => commit.lang === lang || commit.lang === 'specs'
134+
(commit) =>
135+
commit.scope === lang || COMMON_SCOPES.includes(commit.scope)
133136
);
134137
const currentVersion = versions[lang].current;
135138

@@ -272,7 +275,10 @@ async function createReleaseIssue(): Promise<void> {
272275
return [
273276
`### ${lang}`,
274277
...validCommits
275-
.filter((commit) => commit.lang === lang)
278+
.filter(
279+
(commit) =>
280+
commit.scope === lang || COMMON_SCOPES.includes(commit.scope)
281+
)
276282
.map((commit) => `- ${commit.raw}`),
277283
];
278284
})

scripts/release/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ export type VersionsWithoutReleaseType = {
1717
[lang: string]: Omit<Version, 'releaseType'>;
1818
};
1919

20+
export type Scope = Language | 'specs';
21+
2022
export type PassedCommit = {
2123
hash: string;
2224
type: string;
2325
/**
2426
* A commit can be scoped to a language, or the specs, which impacts all clients.
2527
*/
26-
lang: Language | 'specs';
28+
scope: Scope;
2729
message: string;
2830
raw: string;
2931
};

0 commit comments

Comments
 (0)