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

feat(release): support github enterprise server #26482

Merged
merged 9 commits into from
Sep 20, 2024
19 changes: 12 additions & 7 deletions packages/nx/release/changelog-renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { NxReleaseConfig } from '../../src/command-line/release/config/config';
import { DEFAULT_CONVENTIONAL_COMMITS_CONFIG } from '../../src/command-line/release/config/conventional-commits';
import { GitCommit } from '../../src/command-line/release/utils/git';
import {
GithubRepoData,
RepoSlug,
formatReferences,
} from '../../src/command-line/release/utils/github';
Expand Down Expand Up @@ -42,6 +43,7 @@ export type DependencyBump = {
* @param {string | false} config.entryWhenNoChanges The (already interpolated) string to use as the changelog entry when there are no changes, or `false` if no entry should be generated
* @param {ChangelogRenderOptions} config.changelogRenderOptions The options specific to the ChangelogRenderer implementation
* @param {DependencyBump[]} config.dependencyBumps Optional list of additional dependency bumps that occurred as part of the release, outside of the commit data
* @param {GithubRepoData} config.repoData Resolved data for the current GitHub repository
*/
export type ChangelogRenderer = (config: {
projectGraph: ProjectGraph;
Expand All @@ -53,7 +55,9 @@ export type ChangelogRenderer = (config: {
entryWhenNoChanges: string | false;
changelogRenderOptions: DefaultChangelogRenderOptions;
dependencyBumps?: DependencyBump[];
// TODO(v20): remove repoSlug in favour of repoData
repoSlug?: RepoSlug;
repoData?: GithubRepoData;
// TODO(v20): Evaluate if there is a cleaner way to configure this when breaking changes are allowed
// null if version plans are being used to generate the changelog
conventionalCommitsConfig: NxReleaseConfig['conventionalCommits'] | null;
Expand Down Expand Up @@ -101,6 +105,7 @@ const defaultChangelogRenderer: ChangelogRenderer = async ({
dependencyBumps,
repoSlug,
conventionalCommitsConfig,
repoData,
}): Promise<string> => {
const markdownLines: string[] = [];

Expand Down Expand Up @@ -148,7 +153,7 @@ const defaultChangelogRenderer: ChangelogRenderer = async ({
change,
changelogRenderOptions,
isVersionPlans,
repoSlug
repoData
);
breakingChanges.push(line);
relevantChanges.splice(i, 1);
Expand Down Expand Up @@ -222,7 +227,7 @@ const defaultChangelogRenderer: ChangelogRenderer = async ({
change,
changelogRenderOptions,
isVersionPlans,
repoSlug
repoData
);
markdownLines.push(line);
if (change.isBreaking) {
Expand Down Expand Up @@ -295,7 +300,7 @@ const defaultChangelogRenderer: ChangelogRenderer = async ({
change,
changelogRenderOptions,
isVersionPlans,
repoSlug
repoData
);
markdownLines.push(line + '\n');
if (change.isBreaking) {
Expand Down Expand Up @@ -350,7 +355,7 @@ const defaultChangelogRenderer: ChangelogRenderer = async ({
}

// Try to map authors to github usernames
if (repoSlug && changelogRenderOptions.mapAuthorsToGitHubUsernames) {
if (repoData && changelogRenderOptions.mapAuthorsToGitHubUsernames) {
await Promise.all(
[..._authors.keys()].map(async (authorName) => {
const meta = _authors.get(authorName);
Expand Down Expand Up @@ -455,7 +460,7 @@ function formatChange(
change: ChangelogChange,
changelogRenderOptions: DefaultChangelogRenderOptions,
isVersionPlans: boolean,
repoSlug?: RepoSlug
repoData?: GithubRepoData
): string {
let description = change.description;
let extraLines = [];
Expand All @@ -480,8 +485,8 @@ function formatChange(
(!isVersionPlans && change.isBreaking ? '⚠️ ' : '') +
(!isVersionPlans && change.scope ? `**${change.scope.trim()}:** ` : '') +
description;
if (repoSlug && changelogRenderOptions.commitReferences) {
changeLine += formatReferences(change.githubReferences, repoSlug);
if (repoData && changelogRenderOptions.commitReferences) {
changeLine += formatReferences(change.githubReferences, repoData);
}
if (extraLinesStr) {
changeLine += '\n\n' + extraLinesStr;
Expand Down
21 changes: 21 additions & 0 deletions packages/nx/schemas/nx-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,9 @@
{
"type": "boolean",
"enum": [false]
},
{
"$ref": "#/definitions/CreateReleaseProviderConfiguration"
}
]
},
Expand Down Expand Up @@ -724,6 +727,24 @@
}
}
},
"CreateReleaseProviderConfiguration": {
"type": "object",
"properties": {
"provider": {
"type": "string",
"enum": ["github-enterprise-server"]
},
"hostname": {
"type": "string",
"description": "The hostname of the VCS provider instance, e.g. github.example.com"
},
"apiBaseUrl": {
"type": "string",
"description": "The base URL for the relevant VCS provider API. If not set, this will default to `https://${hostname}/api/v3`"
}
},
"required": ["provider", "hostname"]
},
"NxReleaseVersionPlansConfiguration": {
"type": "object",
"properties": {
Expand Down
27 changes: 18 additions & 9 deletions packages/nx/src/command-line/release/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { ChangelogOptions } from './command-object';
import {
NxReleaseConfig,
createNxReleaseConfig,
defaultCreateReleaseProvider,
handleNxReleaseConfigError,
} from './config/config';
import { deepMergeJson } from './config/deep-merge-json';
Expand All @@ -58,7 +59,7 @@ import {
parseCommits,
parseGitCommit,
} from './utils/git';
import { createOrUpdateGithubRelease, getGitHubRepoSlug } from './utils/github';
import { createOrUpdateGithubRelease, getGitHubRepoData } from './utils/github';
import { launchEditor } from './utils/launch-editor';
import { parseChangelogMarkdown } from './utils/markdown';
import { printAndFlushChanges } from './utils/print-changes';
Expand Down Expand Up @@ -411,6 +412,9 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) {
output.logSingleLine(`Creating GitHub Release`);

await createOrUpdateGithubRelease(
nxReleaseConfig.changelog.workspaceChangelog
? nxReleaseConfig.changelog.workspaceChangelog.createRelease
: defaultCreateReleaseProvider,
workspaceChangelog.releaseVersion,
workspaceChangelog.contents,
latestCommit,
Expand Down Expand Up @@ -644,6 +648,9 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) {
output.logSingleLine(`Creating GitHub Release`);

await createOrUpdateGithubRelease(
releaseGroup.changelog
? releaseGroup.changelog.createRelease
: defaultCreateReleaseProvider,
projectChangelog.releaseVersion,
projectChangelog.contents,
latestCommit,
Expand Down Expand Up @@ -797,6 +804,9 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) {
output.logSingleLine(`Creating GitHub Release`);

await createOrUpdateGithubRelease(
releaseGroup.changelog
? releaseGroup.changelog.createRelease
: defaultCreateReleaseProvider,
projectChangelog.releaseVersion,
projectChangelog.contents,
latestCommit,
Expand Down Expand Up @@ -1110,15 +1120,16 @@ async function generateChangelogForWorkspace({
});
}

const githubRepoSlug = getGitHubRepoSlug(gitRemote);
const githubRepoData = getGitHubRepoData(gitRemote, config.createRelease);

let contents = await changelogRenderer({
projectGraph,
changes,
commits,
releaseVersion: releaseVersion.rawVersion,
project: null,
repoSlug: githubRepoSlug,
repoSlug: githubRepoData?.slug,
repoData: githubRepoData,
entryWhenNoChanges: config.entryWhenNoChanges,
changelogRenderOptions: config.renderOptions,
conventionalCommitsConfig: nxReleaseConfig.conventionalCommits,
Expand Down Expand Up @@ -1250,18 +1261,16 @@ async function generateChangelogForProjects({
});
}

const githubRepoSlug =
config.createRelease === 'github'
? getGitHubRepoSlug(gitRemote)
: undefined;
const githubRepoData = getGitHubRepoData(gitRemote, config.createRelease);

let contents = await changelogRenderer({
projectGraph,
changes,
commits,
releaseVersion: releaseVersion.rawVersion,
project: project.name,
repoSlug: githubRepoSlug,
repoSlug: githubRepoData?.slug,
repoData: githubRepoData,
entryWhenNoChanges:
typeof config.entryWhenNoChanges === 'string'
? interpolate(config.entryWhenNoChanges, {
Expand Down Expand Up @@ -1409,7 +1418,7 @@ export function shouldCreateGitHubRelease(
return createReleaseArg === 'github';
}

return (changelogConfig || {}).createRelease === 'github';
return (changelogConfig || {}).createRelease !== false;
}

async function promptForGitHubRelease(): Promise<boolean> {
Expand Down
Loading