Skip to content

feat: Default to automatically setting commits on release #692

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

Merged
merged 4 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion packages/bundler-plugin-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@ export function sentryUnpluginFactory({
shouldCreateRelease: options.release.create,
shouldFinalizeRelease: options.release.finalize,
include: options.release.uploadLegacySourcemaps,
setCommitsOption: options.release.setCommits,
// setCommits has a default defined by the options mappings
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
setCommitsOption: options.release.setCommits!,
deployOptions: options.release.deploy,
dist: options.release.dist,
handleRecoverableError: handleRecoverableError,
Expand Down
9 changes: 9 additions & 0 deletions packages/bundler-plugin-core/src/options-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function normalizeUserOptions(userOptions: UserOptions) {
create: userOptions.release?.create ?? true,
finalize: userOptions.release?.finalize ?? true,
vcsRemote: userOptions.release?.vcsRemote ?? process.env["SENTRY_VSC_REMOTE"] ?? "origin",
setCommits: userOptions.release?.setCommits,
},
bundleSizeOptimizations: userOptions.bundleSizeOptimizations,
reactComponentAnnotation: userOptions.reactComponentAnnotation,
Expand All @@ -39,6 +40,14 @@ export function normalizeUserOptions(userOptions: UserOptions) {
_experiments: userOptions._experiments ?? {},
};

if (options.release.setCommits === undefined) {
options.release.setCommits = {
// @ts-expect-error This is fine
auto: true,
isDefault: true,
};
}

return options;
}

Expand Down
19 changes: 16 additions & 3 deletions packages/bundler-plugin-core/src/plugins/release-management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface ReleaseManagementPluginOptions {
shouldCreateRelease: boolean;
shouldFinalizeRelease: boolean;
include?: string | IncludeEntry | Array<string | IncludeEntry>;
setCommitsOption?: SentryCliCommitsOptions;
setCommitsOption: SentryCliCommitsOptions | false | { auto: true; isDefault: true };
deployOptions?: SentryCliNewDeployOptions;
dist?: string;
handleRecoverableError: HandleRecoverableErrorFn;
Expand All @@ -37,6 +37,7 @@ interface ReleaseManagementPluginOptions {
* Additionally, if legacy upload options are set, it uploads source maps in the legacy (non-debugId) way.
*/
export function releaseManagementPlugin({
logger,
releaseName,
include,
dist,
Expand Down Expand Up @@ -86,8 +87,20 @@ export function releaseManagementPlugin({
});
}

if (setCommitsOption) {
await cliInstance.releases.setCommits(releaseName, setCommitsOption);
if (setCommitsOption !== false) {
try {
await cliInstance.releases.setCommits(releaseName, setCommitsOption);
} catch (e) {
// isDefault being present means that the plugin defaulted to `{ auto: true }` for the setCommitsOptions, meaning that wee should not throw when CLI throws because there is no repo
if (!("isDefault" in setCommitsOption)) {
throw e;
} else {
logger.debug(
"An error occurred setting commits on release (this message can be ignored unless you commits on release are desired):",
e
);
}
}
}

if (shouldFinalizeRelease) {
Expand Down
4 changes: 3 additions & 1 deletion packages/bundler-plugin-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,10 @@ export interface Options {

/**
* Associates the release with its commits in Sentry.
*
* Defaults to `{ auto: true }`. Set to `false` to disable commit association.
*/
setCommits?: SetCommitsOptions;
setCommits?: SetCommitsOptions | false;

/**
* Adds deployment information to the release in Sentry.
Expand Down
8 changes: 8 additions & 0 deletions packages/bundler-plugin-core/test/option-mappings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ describe("normalizeUserOptions()", () => {
create: true,
vcsRemote: "origin",
uploadLegacySourcemaps: "./out",
setCommits: {
auto: true,
isDefault: true,
},
},
silent: false,
telemetry: true,
Expand Down Expand Up @@ -74,6 +78,10 @@ describe("normalizeUserOptions()", () => {
sourceMapReference: false,
stripCommonPrefix: true,
},
setCommits: {
auto: true,
isDefault: true,
},
},
silent: false,
telemetry: true,
Expand Down
3 changes: 2 additions & 1 deletion packages/dev-utils/src/generate-documentation-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ errorHandler: (err) => {
},
{
name: "setCommits",
fullDescription: "Option to associate the created release with its commits in Sentry.",
fullDescription:
"Option to associate the created release with its commits in Sentry. Defaults to `{ auto: true }`. Set to `false` to disable.",
children: [
{
name: "previousCommit",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ test("rollup bundle telemetry", async () => {
"upload-legacy-sourcemaps": false,
"module-metadata": false,
"inject-build-information": false,
"set-commits": "undefined",
"set-commits": "auto",
"finalize-release": true,
"deploy-options": false,
"custom-error-handler": false,
Expand Down
Loading