Skip to content

Commit 3313ba5

Browse files
committed
feat(release)!: support gitlab releases
1 parent 8619c1d commit 3313ba5

File tree

14 files changed

+1970
-815
lines changed

14 files changed

+1970
-815
lines changed

packages/nx/release/changelog-renderer/index.ts

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
import { major } from 'semver';
2-
import { ChangelogChange } from '../../src/command-line/release/changelog';
3-
import { NxReleaseConfig } from '../../src/command-line/release/config/config';
2+
import type { ChangelogChange } from '../../src/command-line/release/changelog';
3+
import type { NxReleaseConfig } from '../../src/command-line/release/config/config';
44
import { DEFAULT_CONVENTIONAL_COMMITS_CONFIG } from '../../src/command-line/release/config/conventional-commits';
5-
import {
6-
GithubRepoData,
7-
formatReferences,
8-
} from '../../src/command-line/release/utils/github';
9-
10-
// axios types and values don't seem to match
11-
import _axios = require('axios');
12-
const axios = _axios as any as (typeof _axios)['default'];
5+
import type { RemoteReleaseClient } from '../../src/command-line/release/utils/remote-release-clients/remote-release-client';
136

147
/**
158
* The ChangelogRenderOptions are specific to each ChangelogRenderer implementation, and are taken
@@ -42,7 +35,7 @@ export interface DefaultChangelogRenderOptions extends ChangelogRenderOptions {
4235
* using https://ungh.cc (from https://github.com/unjs/ungh) and the email addresses found in the commits.
4336
* Defaults to true.
4437
*/
45-
mapAuthorsToGitHubUsernames?: boolean;
38+
applyUsernameToAuthors?: boolean;
4639
/**
4740
* Whether or not the commit references (such as commit and/or PR links) should be included in the changelog.
4841
* Defaults to true.
@@ -63,13 +56,13 @@ export default class DefaultChangelogRenderer {
6356
protected changelogRenderOptions: DefaultChangelogRenderOptions;
6457
protected isVersionPlans: boolean;
6558
protected dependencyBumps?: DependencyBump[];
66-
protected repoData?: GithubRepoData;
6759
protected conventionalCommitsConfig:
6860
| NxReleaseConfig['conventionalCommits']
6961
| null;
7062
protected relevantChanges: ChangelogChange[];
7163
protected breakingChanges: string[];
7264
protected additionalChangesForAuthorsSection: ChangelogChange[];
65+
protected remoteReleaseClient: RemoteReleaseClient<unknown>;
7366

7467
/**
7568
* A ChangelogRenderer class takes in the determined changes and other relevant metadata
@@ -83,8 +76,8 @@ export default class DefaultChangelogRenderer {
8376
* @param {boolean} config.isVersionPlans Whether or not Nx release version plans are the source of truth for the changelog entry
8477
* @param {ChangelogRenderOptions} config.changelogRenderOptions The options specific to the ChangelogRenderer implementation
8578
* @param {DependencyBump[]} config.dependencyBumps Optional list of additional dependency bumps that occurred as part of the release, outside of the change data
86-
* @param {GithubRepoData} config.repoData Resolved data for the current GitHub repository
8779
* @param {NxReleaseConfig['conventionalCommits'] | null} config.conventionalCommitsConfig The configuration for conventional commits, or null if version plans are being used
80+
* @param {RemoteReleaseClient} config.remoteReleaseClient The remote release client to use for formatting references
8881
*/
8982
constructor(config: {
9083
changes: ChangelogChange[];
@@ -94,8 +87,8 @@ export default class DefaultChangelogRenderer {
9487
isVersionPlans: boolean;
9588
changelogRenderOptions: DefaultChangelogRenderOptions;
9689
dependencyBumps?: DependencyBump[];
97-
repoData?: GithubRepoData;
9890
conventionalCommitsConfig: NxReleaseConfig['conventionalCommits'] | null;
91+
remoteReleaseClient: RemoteReleaseClient<unknown>;
9992
}) {
10093
this.changes = this.filterChanges(config.changes, config.project);
10194
this.changelogEntryVersion = config.changelogEntryVersion;
@@ -104,8 +97,8 @@ export default class DefaultChangelogRenderer {
10497
this.isVersionPlans = config.isVersionPlans;
10598
this.changelogRenderOptions = config.changelogRenderOptions;
10699
this.dependencyBumps = config.dependencyBumps;
107-
this.repoData = config.repoData;
108100
this.conventionalCommitsConfig = config.conventionalCommitsConfig;
101+
this.remoteReleaseClient = config.remoteReleaseClient;
109102

110103
this.relevantChanges = [];
111104
this.breakingChanges = [];
@@ -341,7 +334,10 @@ export default class DefaultChangelogRenderer {
341334

342335
protected async renderAuthors(): Promise<string[]> {
343336
const markdownLines: string[] = [];
344-
const _authors = new Map<string, { email: Set<string>; github?: string }>();
337+
const _authors = new Map<
338+
string,
339+
{ email: Set<string>; username?: string }
340+
>();
345341

346342
for (const change of [
347343
...this.relevantChanges,
@@ -365,34 +361,12 @@ export default class DefaultChangelogRenderer {
365361
}
366362

367363
if (
368-
this.repoData &&
369-
this.changelogRenderOptions.mapAuthorsToGitHubUsernames
364+
this.remoteReleaseClient.getRemoteRepoData() &&
365+
this.changelogRenderOptions.applyUsernameToAuthors &&
366+
// TODO: Explore if it is possible to support GitLab
367+
this.remoteReleaseClient.remoteReleaseProviderName === 'GitHub'
370368
) {
371-
await Promise.all(
372-
[..._authors.keys()].map(async (authorName) => {
373-
const meta = _authors.get(authorName);
374-
for (const email of meta.email) {
375-
if (email.endsWith('@users.noreply.github.com')) {
376-
const match = email.match(
377-
/^(\d+\+)?([^@]+)@users\.noreply\.github\.com$/
378-
);
379-
if (match && match[2]) {
380-
meta.github = match[2];
381-
break;
382-
}
383-
}
384-
const { data } = await axios
385-
.get<any, { data?: { user?: { username: string } } }>(
386-
`https://ungh.cc/users/find/${email}`
387-
)
388-
.catch(() => ({ data: { user: null } }));
389-
if (data?.user) {
390-
meta.github = data.user.username;
391-
break;
392-
}
393-
}
394-
})
395-
);
369+
await this.remoteReleaseClient.applyUsernameToAuthors(_authors);
396370
}
397371

398372
const authors = [..._authors.entries()].map((e) => ({
@@ -408,8 +382,8 @@ export default class DefaultChangelogRenderer {
408382
...authors
409383
.sort((a, b) => a.name.localeCompare(b.name))
410384
.map((i) => {
411-
const github = i.github ? ` @${i.github}` : '';
412-
return `- ${i.name}${github}`;
385+
const username = i.username ? ` @${i.username}` : '';
386+
return `- ${i.name}${username}`;
413387
})
414388
);
415389
}
@@ -437,8 +411,13 @@ export default class DefaultChangelogRenderer {
437411
? `**${change.scope.trim()}:** `
438412
: '') +
439413
description;
440-
if (this.repoData && this.changelogRenderOptions.commitReferences) {
441-
changeLine += formatReferences(change.githubReferences, this.repoData);
414+
if (
415+
this.remoteReleaseClient.getRemoteRepoData() &&
416+
this.changelogRenderOptions.commitReferences
417+
) {
418+
changeLine += this.remoteReleaseClient.formatReferences(
419+
change.githubReferences
420+
);
442421
}
443422
if (extraLinesStr) {
444423
changeLine += '\n\n' + extraLinesStr;

packages/nx/schemas/nx-schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@
853853
"oneOf": [
854854
{
855855
"type": "string",
856-
"enum": ["github"]
856+
"enum": ["github", "gitlab"]
857857
},
858858
{
859859
"type": "boolean",
@@ -899,15 +899,15 @@
899899
"properties": {
900900
"provider": {
901901
"type": "string",
902-
"enum": ["github-enterprise-server"]
902+
"enum": ["github-enterprise-server", "gitlab"]
903903
},
904904
"hostname": {
905905
"type": "string",
906906
"description": "The hostname of the VCS provider instance, e.g. github.example.com"
907907
},
908908
"apiBaseUrl": {
909909
"type": "string",
910-
"description": "The base URL for the relevant VCS provider API. If not set, this will default to `https://${hostname}/api/v3`"
910+
"description": "The base URL for the relevant VCS provider API. If not set, this will default to `https://${hostname}/api/v3` (github) or `https://${hostname}/api/v4` (gitlab)."
911911
}
912912
},
913913
"required": ["provider", "hostname"]

0 commit comments

Comments
 (0)