-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(integrations): Update developer GitHub integration form #15784
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,37 +5,85 @@ import {Button} from '@radix-ui/themes'; | |
|
|
||
| const MAX_COMPONENTS_ON_PAGE = 100; | ||
|
|
||
| type AccountType = 'personal' | 'organization'; | ||
|
Contributor
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. this looks great. I didn't realize there were two ways of doing this. When would someone prefer personal vs organization?
Author
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. Well in my case I don't have an organisation account so I created the GitHub app on my own personal GitHub account, I didn't have permissions to do this on our main Sentry account.
Contributor
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. Yeah exactly I was thinking a note saying that if you are an individual or testing you should do the personal otherwise use organization.
Author
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. Funnily enough the Sentry bot said the same thing, I think it's self explanatory tbh. |
||
|
|
||
| export function CreateGitHubAppForm({url, defaultOrg, defaultUrlPrefix}) { | ||
| const [accountType, setAccountType] = useState<AccountType>('organization'); | ||
| const [orgSlug, setOrgSlug] = useState(''); | ||
| const [urlPrefix, setUrlPrefix] = useState(''); | ||
| const renderedUrl = url | ||
| .replace(/:org(?=\W)/g, orgSlug) | ||
| .replace(/:url-prefix(?=\W)/g, encodeURIComponent(urlPrefix)); | ||
|
|
||
| const isPersonal = accountType === 'personal'; | ||
|
|
||
| const renderedUrl = (() => { | ||
| let processedUrl = url; | ||
| if (isPersonal) { | ||
| // For personal accounts, remove the organizations/:org/ path segment | ||
| processedUrl = processedUrl | ||
| .replace('organizations/:org/', '') | ||
| .replace(':org-Sentry', 'Sentry'); | ||
| } else { | ||
| processedUrl = processedUrl.replace(/:org(?=\W)/g, orgSlug); | ||
| } | ||
| return processedUrl.replace(/:url-prefix(?=\W)/g, encodeURIComponent(urlPrefix)); | ||
| })(); | ||
|
|
||
| const inputClassName = | ||
| 'form-input w-full rounded-md border-[1.5px] focus:ring-2 focus:ring-accent-purple/20 border-gray-200'; | ||
| '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'; | ||
| // This is to avoid in case multiple instances of this component are used on the page | ||
| const randomCounter = Math.round(Math.random() * MAX_COMPONENTS_ON_PAGE); | ||
|
|
||
| const isValid = isPersonal ? !!urlPrefix : !!orgSlug && !!urlPrefix; | ||
|
|
||
| return ( | ||
| <div className="space-y-4 p-6 border border-gray-100 rounded"> | ||
| <div className="space-y-4 p-6 border border-gray-200 dark:border-gray-700 rounded"> | ||
| <div className="flex w-full"> | ||
| <div className="flex items-center min-w-[16ch] px-4"> | ||
| <label htmlFor={`gh-org-slug-${randomCounter}`} className="text-nowrap"> | ||
| GitHub Org Slug | ||
| <span className="text-nowrap">Account Type</span> | ||
| </div> | ||
| <div className="flex gap-4"> | ||
| <label className="flex items-center gap-2 cursor-pointer"> | ||
| <input | ||
| type="radio" | ||
| name={`account-type-${randomCounter}`} | ||
| value="organization" | ||
| checked={accountType === 'organization'} | ||
| onChange={() => setAccountType('organization')} | ||
| className="accent-accent-purple" | ||
| /> | ||
| Organization | ||
| </label> | ||
| <label className="flex items-center gap-2 cursor-pointer"> | ||
| <input | ||
| type="radio" | ||
| name={`account-type-${randomCounter}`} | ||
| value="personal" | ||
| checked={accountType === 'personal'} | ||
| onChange={() => setAccountType('personal')} | ||
| className="accent-accent-purple" | ||
| /> | ||
| Personal | ||
| </label> | ||
| </div> | ||
| <input | ||
| id={`gh-org-slug-${randomCounter}`} | ||
| value={orgSlug} | ||
| placeholder={defaultOrg} | ||
| className={inputClassName} | ||
| onChange={ev => setOrgSlug(ev.target.value)} | ||
| /> | ||
| </div> | ||
| {!isPersonal && ( | ||
| <div className="flex w-full"> | ||
| <div className="flex items-center min-w-[16ch] px-4"> | ||
| <label htmlFor={`gh-org-slug-${randomCounter}`} className="text-nowrap"> | ||
| GitHub Org Slug | ||
| </label> | ||
| </div> | ||
| <input | ||
| id={`gh-org-slug-${randomCounter}`} | ||
| value={orgSlug} | ||
| placeholder={defaultOrg} | ||
| className={inputClassName} | ||
| onChange={ev => setOrgSlug(ev.target.value)} | ||
| /> | ||
| </div> | ||
| )} | ||
| <div className="flex w-full"> | ||
| <div className="flex items-center min-w-[16ch] px-4"> | ||
| <label htmlFor={`gh-org-slug-${randomCounter}`} className="text-nowrap"> | ||
| <label htmlFor={`sentry-url-prefix-${randomCounter}`} className="text-nowrap"> | ||
| Sentry <code>url-prefix</code> | ||
| </label> | ||
| </div> | ||
|
|
@@ -54,7 +102,7 @@ export function CreateGitHubAppForm({url, defaultOrg, defaultUrlPrefix}) { | |
| type="button" | ||
| size="3" | ||
| onClick={() => window.open(renderedUrl, '_blank', 'noopener')} | ||
| disabled={!orgSlug || !urlPrefix} | ||
| disabled={!isValid} | ||
| className="rounded-md" | ||
| > | ||
| Create GitHub App | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.