Skip to content

Commit

Permalink
feat(config): add project and org plugin config
Browse files Browse the repository at this point in the history
  • Loading branch information
lgaticaq committed Mar 24, 2020
1 parent 0bf0b15 commit 5eb197d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ The plugin can be configured in the [**semantic-release** configuration file](ht

| Variable | Description |
| --------- | ----------------------------------------------------------------- |
| `project` | Sentry project name. Optional. Required if not present in environment variables |
| `org` | Sentry organization name. Optional. Required if not present in environment variables |
| `repositoryUrl` | A valid url for add link to commits of new release. Optional. Ex: https://github.com/owner/repo |
| `tagsUrl` | A valid url for add link to new release. Optional. Ex: https://github.com/owner/repo/releases/tag/vx.y.z |
| `environment` | Sentry environment. Optional for deploy. Default production |
Expand Down
4 changes: 2 additions & 2 deletions src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Please make sure to create an [sentry token](https://docs.sentry.io/api/auth/#id
message: 'No sentry org specified.',
details: `An [sentry org](${linkify(
'README.md#environment-variables'
)}) must be created and set in the \`SENTRY_ORG\` environment variable on your CI environment.`
)}) must be created and set in the \`SENTRY_ORG\` environment variable on your CI environment or set org in plugin config.`
})
],
[
Expand All @@ -60,7 +60,7 @@ Please make sure to create an [sentry token](https://docs.sentry.io/api/auth/#id
message: 'No sentry project specified.',
details: `An [sentry project](${linkify(
'README.md#environment-variables'
)}) must be created and set in the \`SENTRY_PROJECT\` environment variable on your CI environment.`
)}) must be created and set in the \`SENTRY_PROJECT\` environment variable on your CI environment or set project in plugin config.`
})
],
[
Expand Down
7 changes: 4 additions & 3 deletions src/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ module.exports = async (pluginConfig, ctx) => {
return newCommit
}),
version: ctx.nextRelease.version,
projects: [ctx.env.SENTRY_PROJECT]
projects: [ctx.env.SENTRY_PROJECT || pluginConfig.project]
}
if (url !== '') releaseDate.url = url
const org = ctx.env.SENTRY_ORG || pluginConfig.org
const release = await createRelease(
releaseDate,
ctx.env.SENTRY_AUTH_TOKEN,
ctx.env.SENTRY_ORG
org
)
/** @type {SentryDeployParams} */
const deployData = {
Expand All @@ -68,7 +69,7 @@ module.exports = async (pluginConfig, ctx) => {
const deploy = await createDeploy(
deployData,
ctx.env.SENTRY_AUTH_TOKEN,
ctx.env.SENTRY_ORG,
org,
ctx.nextRelease.version
)
return { release, deploy }
Expand Down
2 changes: 2 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ export interface Config extends SemanticReleaseConfig {
environment?: string
deployName?: string
deployUrl?: string
org?: string
project?: string
}
7 changes: 4 additions & 3 deletions src/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ module.exports = async (pluginConfig, ctx) => {
if (!ctx.env.SENTRY_AUTH_TOKEN) {
errors.push(getError('ENOSENTRYTOKEN', ctx))
}
if (!ctx.env.SENTRY_ORG) {
const org = ctx.env.SENTRY_ORG || pluginConfig.org
if (!org) {
errors.push(getError('ENOSENTRYORG', ctx))
}
if (!ctx.env.SENTRY_PROJECT) {
if (!ctx.env.SENTRY_PROJECT && !pluginConfig.project) {
errors.push(getError('ENOSENTRYPROJECT', ctx))
}
if (pluginConfig.tagsUrl && !/http/.test(pluginConfig.tagsUrl)) {
Expand All @@ -31,7 +32,7 @@ module.exports = async (pluginConfig, ctx) => {
if (errors.length > 0) {
throw new AggregateError(errors)
}
return await verify(ctx.env.SENTRY_AUTH_TOKEN, ctx.env.SENTRY_ORG)
return await verify(ctx.env.SENTRY_AUTH_TOKEN, org)
} catch (err) {
if (err instanceof AggregateError) {
throw err
Expand Down

0 comments on commit 5eb197d

Please sign in to comment.