Skip to content

Commit b529c0c

Browse files
jembachlgaticaq
authored andcommitted
feat: add releasePrefix to sentry release
fixes that sentry releases are associated with an organization instead a project. For more information about this topic read: getsentry/sentry-cli#482
1 parent 1bf964c commit b529c0c

File tree

4 files changed

+63
-5
lines changed

4 files changed

+63
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
6666
| `sourcemaps` | Directory with sourcemaps. Example `dist`. Optional for upload sourcemaps |
6767
| `urlPrefix` | URL prefix for sourcemaps. Example `~/dist`. Optional for upload sourcemaps |
6868
| `rewrite` | Boolean to indicate rewrite sourcemaps. Default `false`. Optional for upload sourcemaps |
69+
| `releasePrefix`| String that is passed as prefix to the sentry release. <br/> Optional to fix the problem that releases are associated with the organization instead of the project ([Read More](https://github.com/getsentry/sentry-cli/issues/482)). <br/> Ex: `releasePrefix:"web1"` would resolve __only__ the sentry release to `web1-1.0.0`. <br/>__Important Notice:__ when you use this feature you also have to change the release name in your sentry client app. |
6970

7071
### Examples
7172

src/publish.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,21 @@ module.exports = async (pluginConfig, ctx) => {
5353
ctx.logger.log('Retrieving commits data')
5454
const commits = await parseCommits(pluginConfig, ctx)
5555
ctx.logger.log('Commit data retrieved')
56+
const sentryReleaseVersion = pluginConfig.releasePrefix
57+
? `${pluginConfig.releasePrefix}-${ctx.nextRelease.version}`
58+
: ctx.nextRelease.version
5659
/** @type {SentryReleaseParams} */
5760
const releaseDate = {
5861
commits,
59-
version: ctx.nextRelease.version,
62+
version: sentryReleaseVersion,
6063
projects: [project]
6164
}
6265
if (tagsUrl !== '') {
6366
releaseDate.url = `${tagsUrl}/v${ctx.nextRelease.version}`
6467
}
6568
const org = ctx.env.SENTRY_ORG || pluginConfig.org
6669
const url = ctx.env.SENTRY_URL || pluginConfig.url || 'https://sentry.io/'
67-
ctx.logger.log('Creating release %s', ctx.nextRelease.version)
70+
ctx.logger.log('Creating release %s', sentryReleaseVersion)
6871
const release = await createRelease(
6972
releaseDate,
7073
ctx.env.SENTRY_AUTH_TOKEN,
@@ -79,21 +82,21 @@ module.exports = async (pluginConfig, ctx) => {
7982
if (pluginConfig.sourcemaps && pluginConfig.urlPrefix) {
8083
const sourcemaps = path.resolve(ctx.cwd, pluginConfig.sourcemaps)
8184
ctx.logger.log('Uploading sourcemaps from %s', sourcemaps)
82-
await cli.releases.uploadSourceMaps(ctx.nextRelease.version, {
85+
await cli.releases.uploadSourceMaps(sentryReleaseVersion, {
8386
include: [sourcemaps],
8487
urlPrefix: pluginConfig.urlPrefix,
8588
rewrite: pluginConfig.rewrite || false
8689
})
8790
ctx.logger.log('Sourcemaps uploaded')
8891
}
8992
const deployData = getDeployData(pluginConfig, ctx)
90-
ctx.logger.log('Creating deploy for release %s', ctx.nextRelease.version)
93+
ctx.logger.log('Creating deploy for release %s', sentryReleaseVersion)
9194
const deploy = await createDeploy(
9295
deployData,
9396
ctx.env.SENTRY_AUTH_TOKEN,
9497
org,
9598
url,
96-
ctx.nextRelease.version
99+
sentryReleaseVersion
97100
)
98101
ctx.logger.log('Deploy created')
99102
return { release, deploy }

src/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface Config {
2424
sourcemaps?: string
2525
urlPrefix?: string
2626
rewrite?: boolean
27+
releasePrefix?: string
2728
}
2829

2930
export enum PATCH_SET_TYPES {

test/publish.test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,42 @@ describe('Publish', () => {
120120
dateFinished: '2020-02-05T10:30:43Z',
121121
id: '5044917'
122122
})
123+
124+
nock(SENTRY_HOST, NOCK_OPTIONS)
125+
.post(PATH_RELEASE)
126+
.reply(201, {
127+
authors: [],
128+
commitCount: 0,
129+
data: {},
130+
dateCreated: new Date().toISOString(),
131+
dateReleased: null,
132+
deployCount: 0,
133+
firstEvent: null,
134+
lastCommit: null,
135+
lastDeploy: null,
136+
lastEvent: null,
137+
newGroups: 0,
138+
owner: null,
139+
projects: [
140+
{
141+
name: 'project',
142+
slug: 'project'
143+
}
144+
],
145+
ref: '6ba09a7c53235ee8a8fa5ee4c1ca8ca886e7fdbb',
146+
shortVersion: 'web1-1.0.0',
147+
url: null,
148+
version: 'web1-1.0.0'
149+
})
150+
.post('/api/0/organizations/valid/releases/web1-1.0.0/deploys/')
151+
.reply(201, {
152+
name: 'amazon',
153+
url: 'https://api.example.com/',
154+
environment: 'production',
155+
dateStarted: '2020-02-05T10:29:59Z',
156+
dateFinished: '2020-02-05T10:30:43Z',
157+
id: '5044917'
158+
})
123159
})
124160

125161
it(SERVER_ERROR_TITLE, async () => {
@@ -164,4 +200,21 @@ describe('Publish', () => {
164200
const result = await publish({ tagsUrl, sourcemaps, urlPrefix }, ctx)
165201
expect(result.release.version).to.equal('1.0.0')
166202
})
203+
204+
it('Deploy app with releasePrefix', async () => {
205+
ctx.env.SENTRY_PROJECT = 'project'
206+
const filePath = tempWrite.sync('sourcemaps', 'dist/app.js.map')
207+
const sourcemaps = path.dirname(filePath)
208+
ctx.cwd = path.dirname(sourcemaps)
209+
const urlPrefix = '~/dist'
210+
const releasePrefix = 'web1'
211+
// @ts-ignore
212+
const result = await publish(
213+
{ tagsUrl, sourcemaps, urlPrefix, releasePrefix },
214+
ctx
215+
)
216+
expect(result.release.version).to.equal(
217+
`${releasePrefix}-${ctx.nextRelease.version}`
218+
)
219+
})
167220
})

0 commit comments

Comments
 (0)