Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
39 changes: 39 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,44 @@ export function normalizeUserOptions(userOptions: UserOptions) {
_experiments: userOptions._experiments ?? {},
};

if (options.release.setCommits === undefined) {
if (
process.env["VERCEL"] &&
process.env["VERCEL_GIT_COMMIT_SHA"] &&
process.env["VERCEL_GIT_REPO_SLUG"] &&
process.env["VERCEL_GIT_REPO_OWNER"]
) {
options.release.setCommits = {
// @ts-expect-error This is fine
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just update the type interface?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're the angel on my shoulder.

shouldNotThrowOnFailure: true,
commit: process.env["VERCEL_GIT_COMMIT_SHA"],
previousCommit: process.env["VERCEL_GIT_PREVIOUS_SHA"],
repo: `${process.env["VERCEL_GIT_REPO_OWNER"]}/${process.env["VERCEL_GIT_REPO_SLUG"]}`,
ignoreEmpty: true,
ignoreMissing: true,
};
} else {
options.release.setCommits = {
shouldNotThrowOnFailure: true,
// @ts-expect-error This is fine
auto: true,
ignoreEmpty: true,
ignoreMissing: true,
};
}
}

if (
options.release.deploy === undefined &&
process.env["VERCEL"] &&
process.env["VERCEL_TARGET_ENV"]
) {
options.release.deploy = {
env: `vercel-${process.env["VERCEL_TARGET_ENV"]}`,
url: process.env["VERCEL_URL"] ? `https://${process.env["VERCEL_URL"]}` : undefined,
};
}

return options;
}

Expand Down
22 changes: 19 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,23 @@ export function releaseManagementPlugin({
});
}

if (setCommitsOption) {
await cliInstance.releases.setCommits(releaseName, setCommitsOption);
if (setCommitsOption !== false) {
try {
await cliInstance.releases.setCommits(releaseName, setCommitsOption);
} catch (e) {
// shouldNotThrowOnFailure 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 (
"shouldNotThrowOnFailure" in setCommitsOption &&
setCommitsOption.shouldNotThrowOnFailure
) {
logger.debug(
"An error occurred setting commits on release (this message can be ignored unless you commits on release are desired):",
e
);
} else {
throw 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
12 changes: 12 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,12 @@ describe("normalizeUserOptions()", () => {
create: true,
vcsRemote: "origin",
uploadLegacySourcemaps: "./out",
setCommits: {
auto: true,
shouldNotThrowOnFailure: true,
ignoreEmpty: true,
ignoreMissing: true,
},
},
silent: false,
telemetry: true,
Expand Down Expand Up @@ -74,6 +80,12 @@ describe("normalizeUserOptions()", () => {
sourceMapReference: false,
stripCommonPrefix: true,
},
setCommits: {
auto: true,
shouldNotThrowOnFailure: true,
ignoreEmpty: true,
ignoreMissing: 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