Skip to content

Commit

Permalink
Update Sentry endpoint to /organizations/:id/releases (#36)
Browse files Browse the repository at this point in the history
Also allow providing array of projects
  • Loading branch information
schneidmaster authored Sep 4, 2017
1 parent 5225497 commit a41d333
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ $ yarn add webpack-sentry-plugin --dev

- `organization`: **Required**, Sentry organization to upload files to

- `project`: **Required**, Sentry project to upload files to
- `project`: **Required**, Sentry project(s) to upload files to. Can be a string project slug or an array of project slugs if the release should be associated with multiple projects.

- `apiKey`: **Required**, Sentry auth token ([Generate one here](https://sentry.io/api/), ensure that `project:write`, `project:read` and `project:releases` are selected ,under scopes)

Expand Down
34 changes: 29 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
import request from 'request-promise'
import fs from 'fs'

const BASE_SENTRY_URL = 'https://sentry.io/api/0/projects'
const BASE_SENTRY_URL = 'https://sentry.io/api/0'

const DEFAULT_INCLUDE = /\.js$|\.map$/
const DEFAULT_TRANSFORM = filename => `~/${filename}`
const DEFAULT_DELETE_REGEX = /\.map$/
const DEFAULT_BODY_TRANSFORM = version => ({ version })
const DEFAULT_BODY_TRANSFORM = (version, projects) => ({ version, projects })

module.exports = class SentryPlugin {
constructor(options) {
this.baseSentryURL = options.baseSentryURL || BASE_SENTRY_URL
// The baseSentryURL option was previously documented to have
// `/projects` on the end. We now expect the basic API endpoint
// but remove any `/projects` suffix for backwards compatibility.
const projectsRegex = /\/projects$/
if (options.baseSentryURL) {
if (projectsRegex.test(options.baseSentryURL)) {
// eslint-disable-next-line no-console
console.warn("baseSentryURL with '/projects' suffix is deprecated; " +
'see https://github.com/40thieves/webpack-sentry-plugin/issues/38')
this.baseSentryURL = options.baseSentryURL.replace(projectsRegex, '')
}
else {
this.baseSentryURL = options.baseSentryURL
}
}
else {
this.baseSentryURL = BASE_SENTRY_URL
}

this.organizationSlug = options.organization || options.organisation
this.projectSlug = options.project
if (typeof this.projectSlug === 'string') {
this.projectSlug = [this.projectSlug]
}
this.apiKey = options.apiKey

this.releaseBody = options.releaseBody || DEFAULT_BODY_TRANSFORM
Expand Down Expand Up @@ -44,7 +65,10 @@ module.exports = class SentryPlugin {
}

if (typeof this.releaseBody === 'function') {
this.releaseBody = this.releaseBody(this.releaseVersion)
this.releaseBody = this.releaseBody(
this.releaseVersion,
this.projectSlug
)
}

return this.createRelease()
Expand Down Expand Up @@ -144,7 +168,7 @@ module.exports = class SentryPlugin {
}

sentryReleaseUrl() {
return `${this.baseSentryURL}/${this.organizationSlug}/${this.projectSlug}/releases` // eslint-disable-line max-len
return `${this.baseSentryURL}/organizations/${this.organizationSlug}/releases` // eslint-disable-line max-len
}

deleteFiles(stats) {
Expand Down

0 comments on commit a41d333

Please sign in to comment.