Skip to content
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

feat(rn): Add code snippet to send the first Sentry Error #263

Merged
merged 5 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- ref(nextjs): Clean up minor things (#258)
- ref(nextjs): Replace old Next.js wizard (#262)
- feat(rn): Add code snippet to send the first Sentry Error ([#263](https://github.com/getsentry/sentry-wizard/pull/263))

## 3.1.0

Expand Down
42 changes: 41 additions & 1 deletion lib/Steps/Integrations/ReactNative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import {
matchFiles,
patchMatchingFile,
} from '../../Helper/File';
import { dim, green, nl, red } from '../../Helper/Logging';
import { dim, green, l, nl, red } from '../../Helper/Logging';
import { checkPackageVersion } from '../../Helper/Package';
import { getPackageMangerChoice } from '../../Helper/PackageManager';
import { SentryCli } from '../../Helper/SentryCli';
import { MobileProject } from './MobileProject';
import { URL } from 'url';

const xcode = require('xcode');

Expand All @@ -37,11 +38,15 @@ export class ReactNative extends MobileProject {
*/
private static _buildGradleAndroidSectionBeginning = /^android {/m;

private url: string | undefined;

protected _answers: Answers;
protected _sentryCli: SentryCli;


public constructor(protected _argv: Args) {
super(_argv);
this.url = _argv.url;
this._sentryCli = new SentryCli(this._argv);
}

Expand Down Expand Up @@ -135,6 +140,41 @@ export class ReactNative extends MobileProject {

await Promise.all(promises);

let host: string | null = null
try {
host = (new URL(this.url || '')).host;
} catch (_error) {
// ignore
}
const orgSlag = _.get(answers, 'config.organization.slug', null);
krystofwoldrich marked this conversation as resolved.
Show resolved Hide resolved
const projectId = _.get(answers, 'config.project.id', null);
const projectIssuesUrl = host && orgSlag && projectId
? `https://${orgSlag}.${host}/issues/?project=${projectId}`
: null;

l(`
To make sure everything is set up correctly, put the following code snippet into your application.
The snippet will create a button that, when tapped, sends a test event to Sentry.
`);

if (projectIssuesUrl) {
kahest marked this conversation as resolved.
Show resolved Hide resolved
l(`After that check your project issues:`);
l(projectIssuesUrl);
nl();
}

l(`<Button title='Try!' onPress={ () => { Sentry.captureException(new Error('First error')) }}/>`);
nl();

if (!this._argv.quiet) {
await prompt({
message: 'Have you successfully sent a test event?',
name: 'snippet',
default: true,
type: 'confirm',
});
}

return answers;
}

Expand Down
1 change: 1 addition & 0 deletions lib/Steps/SentryProjectSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class SentryProjectSelector extends BaseStep {
),
},
project: {
id: _.get(selectedProject, 'selectedProject.id', null),
slug: _.get(selectedProject, 'selectedProject.slug', null),
},
},
Expand Down