-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
✨ feat(integrations): add github domain checker #14011
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 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
754e914
:sparkles: feat: add github domain checker
iamrajjoshi 9ffdf0c
[getsentry/action-github-commit] Auto commit
getsantry[bot] 635ba3f
:wrench: chore: pr feedback
iamrajjoshi f4039c3
[getsentry/action-github-commit] Auto commit
getsantry[bot] 232aa67
:bug: fix: url validation
iamrajjoshi c6aeb22
[getsentry/action-github-commit] Auto commit
getsantry[bot] 187e53e
:wrench: chore: fix margin
iamrajjoshi 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 |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| 'use client'; | ||
|
|
||
| import {useState} from 'react'; | ||
|
|
||
| interface GitHubDomainCheckerProps { | ||
| id?: string; | ||
| } | ||
|
|
||
| export function GitHubDomainChecker({id}: GitHubDomainCheckerProps = {}) { | ||
| const [domain, setDomain] = useState(''); | ||
| const [isValidDomain, setIsValidDomain] = useState(false); | ||
|
|
||
| // Safe function to check if domain is github.com or its subdomain | ||
| const isValidGitHubDomain = (input_domain: string): boolean => { | ||
| try { | ||
| const url = new URL( | ||
| input_domain.startsWith('http') ? input_domain : `https://${input_domain}` | ||
| ); | ||
| const hostname = url.hostname.toLowerCase(); | ||
|
|
||
| // Exact match for github.com or valid subdomain (like gist.github.com) | ||
| return hostname === 'github.com' || hostname.endsWith('.github.com'); | ||
| } catch { | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| // Safe function to check if it's an enterprise GitHub domain | ||
| const isValidEnterpriseDomain = (input_domain: string): boolean => { | ||
| try { | ||
| const url = new URL( | ||
| input_domain.startsWith('http') ? input_domain : `https://${input_domain}` | ||
| ); | ||
| const hostname = url.hostname.toLowerCase(); | ||
|
|
||
| // Must be a valid domain with TLD, but not github.com | ||
| const domainPattern = /^[\w\-\.]+\.[\w]{2,}$/; | ||
| return ( | ||
| domainPattern.test(hostname) && | ||
| !hostname.endsWith('.github.com') && | ||
| hostname !== 'github.com' | ||
| ); | ||
| } catch { | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| const isGitHubCom = (() => { | ||
| const trimmedDomain = domain.toLowerCase().trim(); | ||
| if (!trimmedDomain) return false; | ||
|
|
||
| return isValidGitHubDomain(trimmedDomain); | ||
| })(); | ||
|
|
||
| const hasInput = domain.trim().length > 0; | ||
|
|
||
| // Validate domain format | ||
| const validateDomain = (inputDomain: string) => { | ||
| const trimmedDomain = inputDomain.trim(); | ||
| if (!trimmedDomain) { | ||
| setIsValidDomain(false); | ||
| return; | ||
| } | ||
|
|
||
| // Check if it's a valid GitHub.com domain or subdomain | ||
| if (isValidGitHubDomain(trimmedDomain)) { | ||
| setIsValidDomain(true); | ||
| return; | ||
| } | ||
|
|
||
| // For enterprise, validate as proper domain | ||
| if (isValidEnterpriseDomain(trimmedDomain)) { | ||
| setIsValidDomain(true); | ||
| return; | ||
| } | ||
|
|
||
| setIsValidDomain(false); | ||
| }; | ||
|
|
||
| const handleDomainChange = ev => { | ||
| const newDomain = ev.target.value; | ||
| setDomain(newDomain); | ||
| validateDomain(newDomain); | ||
| }; | ||
|
|
||
| // Improved input styling with dark mode support | ||
| const inputClassName = | ||
| 'form-input w-full rounded-md border-[1.5px] focus:ring-2 focus:ring-accent-purple/20 border-gray-200 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 dark:placeholder-gray-400'; | ||
|
|
||
| // Use provided id or generate a fallback | ||
| const inputId = id || `gh-domain-${Date.now()}`; | ||
|
|
||
| return ( | ||
| <div className="space-y-4 p-6 border border-gray-100 dark:border-gray-700 rounded"> | ||
| <div className="flex w-full"> | ||
| <div className="flex items-center min-w-[16ch] px-4"> | ||
| <label htmlFor={inputId} className="text-nowrap"> | ||
| GitHub Domain | ||
| </label> | ||
| </div> | ||
| <input | ||
| id={inputId} | ||
| value={domain} | ||
| placeholder="https://github.com or https://ghe.example.com" | ||
iamrajjoshi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| className={inputClassName} | ||
| onChange={handleDomainChange} | ||
| /> | ||
| </div> | ||
|
|
||
| {hasInput && ( | ||
| <div className="mt-4 p-4 rounded-md border dark:border-gray-600"> | ||
| {isValidDomain ? ( | ||
| <div> | ||
| <div className="text-sm font-medium mb-2">Recommended Installation:</div> | ||
| {isGitHubCom ? ( | ||
| <div className="text-green-700 bg-green-50 dark:text-green-300 dark:bg-green-900/30 p-3 rounded-md"> | ||
| <div className="mb-2"> | ||
|
||
| <strong>GitHub</strong> - Use the standard GitHub integration for | ||
| github.com | ||
| </div> | ||
| </div> | ||
| ) : ( | ||
| <div className="text-blue-700 bg-blue-50 dark:text-blue-300 dark:bg-blue-900/30 p-3 rounded-md"> | ||
| <div className="mb-2"> | ||
|
||
| <strong>GitHub Enterprise</strong> - Use GitHub Enterprise integration | ||
| for your domain | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ) : ( | ||
| <div className="text-red-700 bg-red-50 dark:text-red-300 dark:bg-red-900/30 p-3 rounded-md"> | ||
| <strong>Invalid Domain</strong> - Please enter a valid GitHub domain or URL | ||
| </div> | ||
| )} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
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
Oops, something went wrong.
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.

Uh oh!
There was an error while loading. Please reload this page.