Skip to content

Commit 186a0d5

Browse files
Luca Forstnerchargome
andauthored
feat: Default to automatically setting commits on release (#692)
Co-authored-by: Charly Gomez <charly.gomez@sentry.io>
1 parent 1d5a8ca commit 186a0d5

File tree

7 files changed

+42
-7
lines changed

7 files changed

+42
-7
lines changed

packages/bundler-plugin-core/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,9 @@ export function sentryUnpluginFactory({
370370
shouldCreateRelease: options.release.create,
371371
shouldFinalizeRelease: options.release.finalize,
372372
include: options.release.uploadLegacySourcemaps,
373-
setCommitsOption: options.release.setCommits,
373+
// setCommits has a default defined by the options mappings
374+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
375+
setCommitsOption: options.release.setCommits!,
374376
deployOptions: options.release.deploy,
375377
dist: options.release.dist,
376378
handleRecoverableError: handleRecoverableError,

packages/bundler-plugin-core/src/options-mapping.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function normalizeUserOptions(userOptions: UserOptions) {
2626
create: userOptions.release?.create ?? true,
2727
finalize: userOptions.release?.finalize ?? true,
2828
vcsRemote: userOptions.release?.vcsRemote ?? process.env["SENTRY_VSC_REMOTE"] ?? "origin",
29+
setCommits: userOptions.release?.setCommits,
2930
},
3031
bundleSizeOptimizations: userOptions.bundleSizeOptimizations,
3132
reactComponentAnnotation: userOptions.reactComponentAnnotation,
@@ -39,6 +40,14 @@ export function normalizeUserOptions(userOptions: UserOptions) {
3940
_experiments: userOptions._experiments ?? {},
4041
};
4142

43+
if (options.release.setCommits === undefined) {
44+
options.release.setCommits = {
45+
// @ts-expect-error This is fine
46+
auto: true,
47+
isDefault: true,
48+
};
49+
}
50+
4251
return options;
4352
}
4453

packages/bundler-plugin-core/src/plugins/release-management.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface ReleaseManagementPluginOptions {
1313
shouldCreateRelease: boolean;
1414
shouldFinalizeRelease: boolean;
1515
include?: string | IncludeEntry | Array<string | IncludeEntry>;
16-
setCommitsOption?: SentryCliCommitsOptions;
16+
setCommitsOption: SentryCliCommitsOptions | false | { auto: true; isDefault: true };
1717
deployOptions?: SentryCliNewDeployOptions;
1818
dist?: string;
1919
handleRecoverableError: HandleRecoverableErrorFn;
@@ -37,6 +37,7 @@ interface ReleaseManagementPluginOptions {
3737
* Additionally, if legacy upload options are set, it uploads source maps in the legacy (non-debugId) way.
3838
*/
3939
export function releaseManagementPlugin({
40+
logger,
4041
releaseName,
4142
include,
4243
dist,
@@ -86,8 +87,20 @@ export function releaseManagementPlugin({
8687
});
8788
}
8889

89-
if (setCommitsOption) {
90-
await cliInstance.releases.setCommits(releaseName, setCommitsOption);
90+
if (setCommitsOption !== false) {
91+
try {
92+
await cliInstance.releases.setCommits(releaseName, setCommitsOption);
93+
} catch (e) {
94+
// 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
95+
if (!("isDefault" in setCommitsOption)) {
96+
throw e;
97+
} else {
98+
logger.debug(
99+
"An error occurred setting commits on release (this message can be ignored unless your commits on release are desired):",
100+
e
101+
);
102+
}
103+
}
91104
}
92105

93106
if (shouldFinalizeRelease) {

packages/bundler-plugin-core/src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,10 @@ export interface Options {
200200

201201
/**
202202
* Associates the release with its commits in Sentry.
203+
*
204+
* Defaults to `{ auto: true }`. Set to `false` to disable commit association.
203205
*/
204-
setCommits?: SetCommitsOptions;
206+
setCommits?: SetCommitsOptions | false;
205207

206208
/**
207209
* Adds deployment information to the release in Sentry.

packages/bundler-plugin-core/test/option-mappings.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ describe("normalizeUserOptions()", () => {
2323
create: true,
2424
vcsRemote: "origin",
2525
uploadLegacySourcemaps: "./out",
26+
setCommits: {
27+
auto: true,
28+
isDefault: true,
29+
},
2630
},
2731
silent: false,
2832
telemetry: true,
@@ -74,6 +78,10 @@ describe("normalizeUserOptions()", () => {
7478
sourceMapReference: false,
7579
stripCommonPrefix: true,
7680
},
81+
setCommits: {
82+
auto: true,
83+
isDefault: true,
84+
},
7785
},
7886
silent: false,
7987
telemetry: true,

packages/dev-utils/src/generate-documentation-table.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ errorHandler: (err) => {
154154
},
155155
{
156156
name: "setCommits",
157-
fullDescription: "Option to associate the created release with its commits in Sentry.",
157+
fullDescription:
158+
"Option to associate the created release with its commits in Sentry. Defaults to `{ auto: true }`. Set to `false` to disable.",
158159
children: [
159160
{
160161
name: "previousCommit",

packages/integration-tests/fixtures/telemetry/telemetry.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ test("rollup bundle telemetry", async () => {
101101
"upload-legacy-sourcemaps": false,
102102
"module-metadata": false,
103103
"inject-build-information": false,
104-
"set-commits": "undefined",
104+
"set-commits": "auto",
105105
"finalize-release": true,
106106
"deploy-options": false,
107107
"custom-error-handler": false,

0 commit comments

Comments
 (0)