-
Notifications
You must be signed in to change notification settings - Fork 50
feat(sourcemaps): Replace "clean artifacts" command #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,68 +1,86 @@ | ||||||||||||||
| /* eslint-disable @typescript-eslint/no-empty-function */ | ||||||||||||||
|
|
||||||||||||||
| import axios from "axios"; | ||||||||||||||
| import { AxiosError } from "axios"; | ||||||||||||||
| import { Options } from "../types"; | ||||||||||||||
|
|
||||||||||||||
| const API_PATH = "api/0"; | ||||||||||||||
|
|
||||||||||||||
| type SentryRequestOptions = Pick<Options, "authToken" | "url"> & { | ||||||||||||||
| method: string; | ||||||||||||||
| endpoint: string; | ||||||||||||||
| payload: unknown; | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Generic function to call to make the actual request. | ||||||||||||||
| * Currently takes care of adding headers. | ||||||||||||||
| * Happy to change this to something more sophisticated. | ||||||||||||||
| */ | ||||||||||||||
| async function makeRequest(requestOptions: SentryRequestOptions) { | ||||||||||||||
| const { authToken, url, endpoint, method, payload } = requestOptions; | ||||||||||||||
|
|
||||||||||||||
| if (!authToken || !url || !endpoint) { | ||||||||||||||
| return Promise.reject(); | ||||||||||||||
| } | ||||||||||||||
| // We need to ignore the import because the package.json is not part of the TS project as configured in tsconfig.json | ||||||||||||||
| // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||||||||||||||
| // @ts-ignore | ||||||||||||||
| import { version as unpluginVersion } from "../../package.json"; | ||||||||||||||
|
|
||||||||||||||
| const response = await axios({ | ||||||||||||||
| method, | ||||||||||||||
| url: `${url}/${API_PATH}/${endpoint}`, | ||||||||||||||
| data: payload, | ||||||||||||||
| headers: { Authorization: `Bearer ${authToken}`, "User-Agent": "sentry-unplugin" }, | ||||||||||||||
| }).catch((error: AxiosError) => { | ||||||||||||||
| const msg = `Error: ${error.message}`; | ||||||||||||||
| throw new Error(msg); | ||||||||||||||
| }); | ||||||||||||||
| const API_PATH = "/api/0"; | ||||||||||||||
|
|
||||||||||||||
| return response; | ||||||||||||||
| } | ||||||||||||||
| // eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-member-access | ||||||||||||||
| const USER_AGENT = `sentry-unplugin/${unpluginVersion}`; | ||||||||||||||
| const sentryApiAxiosInstance = axios.create(); | ||||||||||||||
| sentryApiAxiosInstance.interceptors.request.use((config) => { | ||||||||||||||
| return { | ||||||||||||||
| ...config, | ||||||||||||||
| headers: { | ||||||||||||||
| ...config.headers, | ||||||||||||||
| "User-Agent": USER_AGENT, | ||||||||||||||
| }, | ||||||||||||||
| }; | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| /* Just a wrapper to make POST requests */ | ||||||||||||||
| async function makePostRequest(requestOptions: Omit<SentryRequestOptions, "method">) { | ||||||||||||||
| return makeRequest({ ...requestOptions, method: "POST" }); | ||||||||||||||
| } | ||||||||||||||
| export async function createRelease({ | ||||||||||||||
| release, | ||||||||||||||
| project, | ||||||||||||||
| org, | ||||||||||||||
| authToken, | ||||||||||||||
| sentryUrl, | ||||||||||||||
| }: { | ||||||||||||||
| release: string; | ||||||||||||||
| project: string; | ||||||||||||||
| org: string; | ||||||||||||||
| authToken: string; | ||||||||||||||
| sentryUrl: string; | ||||||||||||||
| }): Promise<void> { | ||||||||||||||
| // using the legacy endpoint here because the sentry webpack plugin only associates one project | ||||||||||||||
| // with the release. If we ever wanna support multiple projects in the unplugin, | ||||||||||||||
| // take a look at how sentry/cli calls the new endpoint: | ||||||||||||||
| // https://github.com/getsentry/sentry-cli/blob/4fa813549cd249e77ae6ba974d76e606a19f48de/src/api.rs#L769-L773 | ||||||||||||||
| const requestUrl = `${sentryUrl}${API_PATH}/projects/${org}/${project}/releases/`; | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| export async function makeNewReleaseRequest(release: string, options: Options): Promise<string> { | ||||||||||||||
| const releasePayload = { | ||||||||||||||
| version: release, | ||||||||||||||
| projects: [options.project], | ||||||||||||||
| projects: [project], | ||||||||||||||
| dateStarted: new Date(), | ||||||||||||||
| dateReleased: new Date(), //TODO: figure out if these dates are set correctly | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| const orgSlug = options.org || ""; | ||||||||||||||
| const projectSlug = options.project || ""; | ||||||||||||||
| try { | ||||||||||||||
| await sentryApiAxiosInstance.post(requestUrl, releasePayload, { | ||||||||||||||
| headers: { Authorization: `Bearer ${authToken}` }, | ||||||||||||||
| }); | ||||||||||||||
| } catch (e) { | ||||||||||||||
| // TODO: Maybe do some more sopthisticated error handling here | ||||||||||||||
| throw new Error("Something went wrong while creating a release"); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // using the legacy endpoint here because the sentry webpack plugin only associates one project | ||||||||||||||
| // with the release. If we ever wanna support multiple projects in the unplugin, | ||||||||||||||
| // take a look at how sentry/cli calls the new endpoint: | ||||||||||||||
| // https://github.com/getsentry/sentry-cli/blob/4fa813549cd249e77ae6ba974d76e606a19f48de/src/api.rs#L769-L773 | ||||||||||||||
| const response = await makePostRequest({ | ||||||||||||||
| authToken: options.authToken, | ||||||||||||||
| url: options.url, | ||||||||||||||
| endpoint: `projects/${orgSlug}/${projectSlug}/releases/`, | ||||||||||||||
| payload: releasePayload, | ||||||||||||||
| }); | ||||||||||||||
| export async function deleteAllReleaseArtifacts({ | ||||||||||||||
| org, | ||||||||||||||
| release, | ||||||||||||||
| sentryUrl, | ||||||||||||||
| authToken, | ||||||||||||||
| project, | ||||||||||||||
| }: { | ||||||||||||||
| org: string; | ||||||||||||||
| release: string; | ||||||||||||||
| sentryUrl: string; | ||||||||||||||
| authToken: string; | ||||||||||||||
| project?: string; | ||||||||||||||
| }): Promise<void> { | ||||||||||||||
| const requestUrl = project | ||||||||||||||
| ? `${sentryUrl}${API_PATH}/projects/${org}/${project}/files/source-maps/?name=${release}` // legacy endpoint if users provide project | ||||||||||||||
| : `${sentryUrl}${API_PATH}/organizations/${org}/files/source-maps/?name=${release}`; // new endpoint | ||||||||||||||
|
|
||||||||||||||
| return response.status.toString(); | ||||||||||||||
| try { | ||||||||||||||
| await sentryApiAxiosInstance.delete(requestUrl, { | ||||||||||||||
| headers: { | ||||||||||||||
| Authorization: `Bearer ${authToken}`, | ||||||||||||||
| }, | ||||||||||||||
| }); | ||||||||||||||
| } catch (e) { | ||||||||||||||
| // TODO: Maybe do some more sopthisticated error handling here | ||||||||||||||
| throw new Error("Something went wrong while cleaning previous release artifacts"); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for this!