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

Commit c94d8a9

Browse files
authored
ref(config): Add SENTRY_REPOSITORY environment variable
Allow users to override the repository name passed to the cli. This is useful for gitlab users where the repository name is not necessarily the same as the URL (#21)
2 parents d42f0b1 + c2682c1 commit c94d8a9

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

README.md

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ The Sentry Netlify build plugin:
99

1010
Before proceeding, you'll first want to ensure that your Sentry project is set up properly to track commit metadata. The easiest way to do that is to [install a repository integration](https://docs.sentry.io/product/releases/#install-repo-integration).
1111

12+
By default, the linked Sentry repository will be parsed from the Netlify's `REPOSITORY_URL` environment variable. This behaviour can be overridden using the `SENTRY_REPOSITORY` environment variable.
13+
1214
Make sure build plugins are enabled on your site to see the plugin run.
1315

1416
## Installation
@@ -58,26 +60,28 @@ To link errors with releases, you must include a release ID (a.k.a version) wher
5860
#### Environment Variables
5961

6062
You can use [site environment variables](https://docs.netlify.com/configure-builds/environment-variables/) to configure these values:
61-
| name | description | default |
62-
|------|-------------|---------|
63-
| `SENTRY_AUTH_TOKEN` | Authentication token for Sentry. | - |
64-
| `SENTRY_ORG` | The slug of the organization name in Sentry. | - |
65-
| `SENTRY_PROJECT` | The slug of the project name in Sentry. | - |
66-
| `SENTRY_RELEASE` | The release ID (a.k.a version). | [COMMIT_REF](https://docs.netlify.com/configure-builds/environment-variables/#git-metadata) |
67-
| `SENTRY_ENVIRONMENT` | The name of the environment being deployed to. | Netlify [deploy context](https://docs.netlify.com/site-deploys/overview/#deploy-contexts) |
68-
| `SENTRY_RELEASE_PREFIX` | Set this to prefix the release name with the value. | - |
63+
| name | description | default |
64+
| ----------------------- | --------------------------------------------------- | ------------------------------------------------------------------------------------------- |
65+
| `SENTRY_AUTH_TOKEN` | Authentication token for Sentry. | - |
66+
| `SENTRY_ORG` | The slug of the organization name in Sentry. | - |
67+
| `SENTRY_PROJECT` | The slug of the project name in Sentry. | - |
68+
| `SENTRY_RELEASE` | The release ID (a.k.a version). | [COMMIT_REF](https://docs.netlify.com/configure-builds/environment-variables/#git-metadata) |
69+
| `SENTRY_REPOSITORY` | The name of the target Sentry repository. | - |
70+
| `SENTRY_ENVIRONMENT` | The name of the environment being deployed to. | Netlify [deploy context](https://docs.netlify.com/site-deploys/overview/#deploy-contexts) |
71+
| `SENTRY_RELEASE_PREFIX` | Set this to prefix the release name with the value. | - |
6972

7073

7174
#### Plugin Inputs
72-
| name | description | default |
73-
|------|-------------|---------|
74-
| `sentryOrg` | The slug of the organization name in Sentry. | - |
75-
| `sentryProject` | The slug of the project name in Sentry. | - |
76-
| `sentryAuthToken` | Authentication token for Sentry. We recommend this be set as an environment variable (see below). | - |
77-
| `sentryRelease` | The release ID (a.k.a version). | [COMMIT_REF](https://docs.netlify.com/configure-builds/environment-variables/#git-metadata) |
78-
| `sourceMapPath` | Folder in which to scan for source maps to upload. | Netlify publish directory |
79-
| `sourceMapUrlPrefix` | Prefix for the location of source maps. | `"~/"` |
80-
| `skipSetCommits` | Set this to true if you want to disable commit tracking. | `false` |
81-
| `skipSourceMaps` | Set this to true if you want to disable sending source maps to Sentry. | `false` |
82-
| `releasePrefix` | Set this to prefix the release name with the value. | - |
83-
| `deployPreviews` | Set this to false if you want to skip running the build plugin on deploy previews. | `true` |
75+
| name | description | default |
76+
| -------------------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
77+
| `sentryOrg` | The slug of the organization name in Sentry. | - |
78+
| `sentryProject` | The slug of the project name in Sentry. | - |
79+
| `sentryAuthToken` | Authentication token for Sentry. We recommend this be set as an environment variable (see below). | - |
80+
| `sentryRelease` | The release ID (a.k.a version). | [COMMIT_REF](https://docs.netlify.com/configure-builds/environment-variables/#git-metadata) |
81+
| `sentryRepository` | The name of the target Sentry repository. | Derived from [REPOSITORY_URL](https://docs.netlify.com/configure-builds/environment-variables/#git-metadata) |
82+
| `sourceMapPath` | Folder in which to scan for source maps to upload. | Netlify publish directory |
83+
| `sourceMapUrlPrefix` | Prefix for the location of source maps. | `"~/"` |
84+
| `skipSetCommits` | Set this to true if you want to disable commit tracking. | `false` |
85+
| `skipSourceMaps` | Set this to true if you want to disable sending source maps to Sentry. | `false` |
86+
| `releasePrefix` | Set this to prefix the release name with the value. | - |
87+
| `deployPreviews` | Set this to false if you want to skip running the build plugin on deploy previews. | `true` |

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module.exports = {
3434
const sentryRelease = process.env.SENTRY_RELEASE || inputs.sentryRelease || process.env.COMMIT_REF
3535
const releasePrefix = process.env.SENTRY_RELEASE_PREFIX || inputs.releasePrefix || ''
3636
const sentryEnvironment = process.env.SENTRY_ENVIRONMENT || process.env.CONTEXT
37+
const sentryRepository = process.env.SENTRY_REPOSITORY || inputs.sentryRepository
3738
const sourceMapPath = inputs.sourceMapPath || PUBLISH_DIR
3839
const sourceMapUrlPrefix = inputs.sourceMapUrlPrefix || DEFAULT_SOURCE_MAP_URL_PREFIX
3940

@@ -61,6 +62,7 @@ module.exports = {
6162
pluginApi,
6263
release,
6364
sentryEnvironment,
65+
sentryRepository,
6466
sourceMapPath,
6567
sourceMapUrlPrefix
6668
})
@@ -74,7 +76,7 @@ module.exports = {
7476
}
7577
}
7678

77-
async function createSentryRelease({ pluginApi, release, sentryEnvironment, sourceMapPath, sourceMapUrlPrefix }) {
79+
async function createSentryRelease({ pluginApi, release, sentryEnvironment, sentryRepository, sourceMapPath, sourceMapUrlPrefix }) {
7880
// default config file is read from ~/.sentryclirc
7981
const { constants, inputs, utils } = pluginApi
8082
const cli = new SentryCli()
@@ -108,7 +110,7 @@ async function createSentryRelease({ pluginApi, release, sentryEnvironment, sour
108110

109111
// https://docs.sentry.io/cli/releases/#sentry-cli-commit-integration
110112
if (!inputs.skipSetCommits) {
111-
const repository = process.env.REPOSITORY_URL.split(/[:/]/).slice(-2).join('/')
113+
const repository = sentryRepository || process.env.REPOSITORY_URL.split(/[:/]/).slice(-2).join('/')
112114
try {
113115
await cli.releases.setCommits(release, {
114116
repo: repository,

manifest.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ inputs:
88
description: Authentication token for Sentry
99
- name: sentryRelease
1010
description: The release ID (a.k.a version)
11+
- name: sentryRepository
12+
description: The name of the target Sentry repository
1113
- name: sourceMapPath
1214
description: Folder in which to scan for source maps to upload
1315
- name: sourceMapUrlPrefix

0 commit comments

Comments
 (0)