Skip to content

Commit dda5f8c

Browse files
authored
feat(integrations): Update developer GitHub integration form (#15784)
1 parent d8628cb commit dda5f8c

File tree

3 files changed

+66
-18
lines changed

3 files changed

+66
-18
lines changed

develop-docs/integrations/github.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ For local development make sure to use your ngrok URL as the prefix.
2020
</Alert>
2121

2222
<CreateGitHubAppForm
23-
url="https://github.com/organizations/:org/settings/apps/new?name=:org-Sentry-Integration&public=false&members=read&emails=read&administration=read&contents=read&issues=write&pull_requests=write&repository_hooks=write&url=:url-prefix&callback_url=:url-prefix%2Fauth%2Fsso%2F&setup_url=:url-prefix%2Fextensions%2Fgithub%2Fsetup%2F&webhook_url=:url-prefix%2Fextensions%2Fgithub%2Fwebhook%2F&events[]=push&events[]=pull_request&webhook_active=true"
23+
url="https://github.com/organizations/:org/settings/apps/new?name=:org-Sentry-Integration&public=false&members=read&emails=read&administration=read&contents=read&checks=write&statuses=write&issues=write&pull_requests=write&repository_hooks=write&url=:url-prefix&callback_urls[]=:url-prefix%2Fauth%2Fsso%2F&callback_urls[]=:url-prefix%2Fextensions%2Fgithub%2Fsetup%2F&setup_url=:url-prefix%2Fextensions%2Fgithub%2Fsetup%2F&webhook_url=:url-prefix%2Fextensions%2Fgithub%2Fwebhook%2F&events[]=push&events[]=pull_request&webhook_active=true"
2424
defaultOrg="your-organization"
2525
defaultUrlPrefix="https://your-sentry-url-prefix.com"
2626
/>

develop-docs/self-hosted/configuration/sso.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ As of [Sentry 10](https://github.com/getsentry/self-hosted/releases/tag/10.0.1),
5151
The GitHub App name must not contain any spaces.
5252
</Alert>
5353
54-
<CreateGitHubAppForm url="https://github.com/organizations/:org/settings/apps/new?name=:org-Sentry-Integration&public=false&members=read&emails=read&administration=read&contents=read&issues=write&pull_requests=write&repository_hooks=write&url=:url-prefix&callback_url=:url-prefix%2Fauth%2Fsso%2F&setup_url=:url-prefix%2Fextensions%2Fgithub%2Fsetup%2F&webhook_url=:url-prefix%2Fextensions%2Fgithub%2Fwebhook%2F&events[]=push&events[]=pull_request&webhook_active=true" defaultOrg="your-organization" defaultUrlPrefix="https://your-sentry-url-prefix.com" />
54+
<CreateGitHubAppForm url="https://github.com/organizations/:org/settings/apps/new?name=:org-Sentry-Integration&public=false&members=read&emails=read&administration=read&contents=read&issues=write&pull_requests=write&repository_hooks=write&url=:url-prefix&callback_urls[]=:url-prefix%2Fauth%2Fsso%2F&callback_urls[]=:url-prefix%2Fextensions%2Fgithub%2Fsetup%2F&setup_url=:url-prefix%2Fextensions%2Fgithub%2Fsetup%2F&webhook_url=:url-prefix%2Fextensions%2Fgithub%2Fwebhook%2F&events[]=push&events[]=pull_request&webhook_active=true" defaultOrg="your-organization" defaultUrlPrefix="https://your-sentry-url-prefix.com" />
5555
5656
5757
If the form above does not work for you, you need the following settings for your GitHub Application:

src/components/createGitHubAppForm.tsx

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,85 @@ import {Button} from '@radix-ui/themes';
55

66
const MAX_COMPONENTS_ON_PAGE = 100;
77

8+
type AccountType = 'personal' | 'organization';
9+
810
export function CreateGitHubAppForm({url, defaultOrg, defaultUrlPrefix}) {
11+
const [accountType, setAccountType] = useState<AccountType>('organization');
912
const [orgSlug, setOrgSlug] = useState('');
1013
const [urlPrefix, setUrlPrefix] = useState('');
11-
const renderedUrl = url
12-
.replace(/:org(?=\W)/g, orgSlug)
13-
.replace(/:url-prefix(?=\W)/g, encodeURIComponent(urlPrefix));
14+
15+
const isPersonal = accountType === 'personal';
16+
17+
const renderedUrl = (() => {
18+
let processedUrl = url;
19+
if (isPersonal) {
20+
// For personal accounts, remove the organizations/:org/ path segment
21+
processedUrl = processedUrl
22+
.replace('organizations/:org/', '')
23+
.replace(':org-Sentry', 'Sentry');
24+
} else {
25+
processedUrl = processedUrl.replace(/:org(?=\W)/g, orgSlug);
26+
}
27+
return processedUrl.replace(/:url-prefix(?=\W)/g, encodeURIComponent(urlPrefix));
28+
})();
1429

1530
const inputClassName =
16-
'form-input w-full rounded-md border-[1.5px] focus:ring-2 focus:ring-accent-purple/20 border-gray-200';
31+
'form-input w-full rounded-md border-[1.5px] focus:ring-2 focus:ring-accent-purple/20 border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 placeholder:text-gray-400 dark:placeholder:text-gray-500';
1732
// This is to avoid in case multiple instances of this component are used on the page
1833
const randomCounter = Math.round(Math.random() * MAX_COMPONENTS_ON_PAGE);
1934

35+
const isValid = isPersonal ? !!urlPrefix : !!orgSlug && !!urlPrefix;
36+
2037
return (
21-
<div className="space-y-4 p-6 border border-gray-100 rounded">
38+
<div className="space-y-4 p-6 border border-gray-200 dark:border-gray-700 rounded">
2239
<div className="flex w-full">
2340
<div className="flex items-center min-w-[16ch] px-4">
24-
<label htmlFor={`gh-org-slug-${randomCounter}`} className="text-nowrap">
25-
GitHub Org Slug
41+
<span className="text-nowrap">Account Type</span>
42+
</div>
43+
<div className="flex gap-4">
44+
<label className="flex items-center gap-2 cursor-pointer">
45+
<input
46+
type="radio"
47+
name={`account-type-${randomCounter}`}
48+
value="organization"
49+
checked={accountType === 'organization'}
50+
onChange={() => setAccountType('organization')}
51+
className="accent-accent-purple"
52+
/>
53+
Organization
54+
</label>
55+
<label className="flex items-center gap-2 cursor-pointer">
56+
<input
57+
type="radio"
58+
name={`account-type-${randomCounter}`}
59+
value="personal"
60+
checked={accountType === 'personal'}
61+
onChange={() => setAccountType('personal')}
62+
className="accent-accent-purple"
63+
/>
64+
Personal
2665
</label>
2766
</div>
28-
<input
29-
id={`gh-org-slug-${randomCounter}`}
30-
value={orgSlug}
31-
placeholder={defaultOrg}
32-
className={inputClassName}
33-
onChange={ev => setOrgSlug(ev.target.value)}
34-
/>
3567
</div>
68+
{!isPersonal && (
69+
<div className="flex w-full">
70+
<div className="flex items-center min-w-[16ch] px-4">
71+
<label htmlFor={`gh-org-slug-${randomCounter}`} className="text-nowrap">
72+
GitHub Org Slug
73+
</label>
74+
</div>
75+
<input
76+
id={`gh-org-slug-${randomCounter}`}
77+
value={orgSlug}
78+
placeholder={defaultOrg}
79+
className={inputClassName}
80+
onChange={ev => setOrgSlug(ev.target.value)}
81+
/>
82+
</div>
83+
)}
3684
<div className="flex w-full">
3785
<div className="flex items-center min-w-[16ch] px-4">
38-
<label htmlFor={`gh-org-slug-${randomCounter}`} className="text-nowrap">
86+
<label htmlFor={`sentry-url-prefix-${randomCounter}`} className="text-nowrap">
3987
Sentry <code>url-prefix</code>
4088
</label>
4189
</div>
@@ -54,7 +102,7 @@ export function CreateGitHubAppForm({url, defaultOrg, defaultUrlPrefix}) {
54102
type="button"
55103
size="3"
56104
onClick={() => window.open(renderedUrl, '_blank', 'noopener')}
57-
disabled={!orgSlug || !urlPrefix}
105+
disabled={!isValid}
58106
className="rounded-md"
59107
>
60108
Create GitHub App

0 commit comments

Comments
 (0)