Skip to content
This repository was archived by the owner on Nov 20, 2023. It is now read-only.

Commit 937b360

Browse files
Sølve Tornøekamilogorek
authored andcommitted
ref: Allow for nested setCommits (#142)
* nest setCommits options for clarity * Modify setCommits tests to support nesting * Rename setCommits title & add required for repo++ * Make room for old implementation of setCommits This makes it possible to use both nested and non-nested setOptions * Add table section for setCommits * add `options.` prefix on header * Add new tests for nested and flat setCommits Co-authored-by: Kamil Ogórek <kamil.ogorek@gmail.com> * Fix linter issues
1 parent dec7e21 commit 937b360

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ Also, check the [example](example) directory.
5959

6060
#### Options
6161

62-
Option | Type | Required | Description |
63-
-------|------|----------|-------------
62+
| Option | Type | Required | Description |
63+
---------|------|----------|-------------
6464
release | `string` | optional | unique name of a release, must be a `string`, should uniquely identify your release, defaults to `sentry-cli releases propose-version` command which should always return the correct version (**requires access to `git` CLI and root directory to be a valid repository**).
6565
include | `string`/`array` | required | one or more paths that Sentry CLI should scan recursively for sources. It will upload all `.map` files and match associated `.js` files |
6666
entries | `array`/`RegExp`/`function(key: string): bool` | optional | a filter for entry points that should be processed. By default, the release will be injected into all entry points. |
@@ -79,13 +79,17 @@ entries | `array`/`RegExp`/`function(key: string): bool` | optional | a filter f
7979
| debug | `boolean` | optional | print some useful debug information |
8080
| silent | `boolean` | optional | if `true`, all logs are suppressed (useful for `--json` option) |
8181
| errorHandler | `function(err: Error, invokeErr: function(): void): void` | optional | when Cli error occurs, plugin calls this function. webpack compilation failure can be chosen by calling `invokeErr` callback or not. default `(err, invokeErr) => { invokeErr()}` |
82+
| setCommits | `Object` | optional | Adds commits to sentry - [see own table below](#setCommits) for more details |
8283

8384

84-
set-commits options:
85-
* `commit [optional]` - `string`, the current (last) commit in the release
86-
* `previousCommit [optional]` - `string`, the commit before the beginning of this release (in other words, the last commit of the previous release). If omitted, this will default to the last commit of the previous release in Sentry. If there was no previous release, the last 10 commits will be used
87-
* `repo [optional]` - `string`, the full repo name as defined in Sentry
88-
* `auto [optional]` - `boolean`, automatically choose the associated commit (uses the current commit). Overrides other options
85+
#### <a name="setCommits"></a>options.setCommits:
86+
87+
| Option | Type | Required | Description |
88+
---------|------|----------|-------------
89+
| repo | `string` | required | the full git repo name as defined in Sentry |
90+
| commit | `string` | optional/required | the current (last) commit in the release |
91+
| previousCommit | `string` | optional | the commit before the beginning of this release (in other words, the last commit of the previous release). If omitted, this will default to the last commit of the previous release in Sentry. If there was no previous release, the last 10 commits will be used |
92+
| auto | `boolean` | optional/required | automatically choose the associated commit (uses the current commit). Overrides other options |
8993

9094
You can find more information about these options in our official docs:
9195
https://docs.sentry.io/cli/releases/#sentry-cli-sourcemaps

src/__tests__/index.spec.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,14 @@ describe('afterEmitHook', () => {
228228
});
229229
});
230230

231-
test('test setCommits with commits range', done => {
231+
test('test setCommits with flat options', done => {
232232
const sentryCliPlugin = new SentryCliPlugin({
233233
include: 'src',
234234
release: '42',
235235
commit: '4d8656426ca13eab19581499da93408e30fdd9ef',
236236
previousCommit: 'b6b0e11e74fd55836d3299cef88531b2a34c2514',
237237
repo: 'group / repo',
238-
// auto,
238+
auto: false,
239239
});
240240

241241
sentryCliPlugin.apply(compiler);
@@ -245,26 +245,33 @@ describe('afterEmitHook', () => {
245245
repo: 'group / repo',
246246
commit: '4d8656426ca13eab19581499da93408e30fdd9ef',
247247
previousCommit: 'b6b0e11e74fd55836d3299cef88531b2a34c2514',
248+
auto: false,
248249
});
249250
expect(compilationDoneCallback).toBeCalled();
250251
done();
251252
});
252253
});
253254

254-
test('test setCommits with auto option', done => {
255+
test('test setCommits with grouped options', done => {
255256
const sentryCliPlugin = new SentryCliPlugin({
256257
include: 'src',
257258
release: '42',
258-
repo: 'group / repo',
259-
auto: true,
259+
setCommits: {
260+
commit: '4d8656426ca13eab19581499da93408e30fdd9ef',
261+
previousCommit: 'b6b0e11e74fd55836d3299cef88531b2a34c2514',
262+
repo: 'group / repo',
263+
auto: false,
264+
},
260265
});
261266

262267
sentryCliPlugin.apply(compiler);
263268

264269
setImmediate(() => {
265270
expect(mockCli.releases.setCommits).toBeCalledWith('42', {
266271
repo: 'group / repo',
267-
auto: true,
272+
commit: '4d8656426ca13eab19581499da93408e30fdd9ef',
273+
previousCommit: 'b6b0e11e74fd55836d3299cef88531b2a34c2514',
274+
auto: false,
268275
});
269276
expect(compilationDoneCallback).toBeCalled();
270277
done();

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ class SentryCliPlugin {
322322
})
323323
.then(() => this.cli.releases.uploadSourceMaps(release, this.options))
324324
.then(() => {
325-
const { commit, previousCommit, repo, auto } = this.options;
325+
const { commit, previousCommit, repo, auto } =
326+
this.options.setCommits || this.options;
326327

327328
if (repo && (commit || auto)) {
328329
this.cli.releases.setCommits(release, {

0 commit comments

Comments
 (0)