-
Notifications
You must be signed in to change notification settings - Fork 130
Support for github enterprise server(self hosted github) #646
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
8 commits
Select commit
Hold shift + click to select a range
5273dc3
ui: add optional Custom Domain input in GH integration
thesujai 2dbf898
feat(github): add support for custom GitHub domains in API service
thesujai e960980
feat(github): validate custom domain input with regex and provide use…
thesujai 2076322
feat(github): update GithubApiService to handle optional domain input…
thesujai c69d077
feat(github): refactor GitHub domain handling to use centralized util…
thesujai bafd72f
fix(github): update GITHUB_API_URL to use REST API endpoint and add e…
thesujai cad13c0
cleanup and test config
thesujai fffc1bf
Error Handling
thesujai 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
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
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
Empty file.
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,40 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
from mhq.exapi.github import GithubApiService, PAGE_SIZE | ||
|
||
|
||
class DummyGithub: | ||
def __init__(self, token, base_url=None, per_page=None): | ||
self.token = token | ||
self.base_url = base_url | ||
self.per_page = per_page | ||
|
||
|
||
class TestGithubApiService(unittest.TestCase): | ||
|
||
@patch("mhq.exapi.github.Github", new=DummyGithub) | ||
def test_default_domain_sets_standard_api_url(self): | ||
token = "deadpool" | ||
service = GithubApiService(access_token=token, domain=None) | ||
self.assertEqual(service.base_url, "https://api.github.com") | ||
self.assertIsInstance(service._g, DummyGithub) | ||
self.assertEqual(service._g.token, token) | ||
self.assertEqual(service._g.base_url, "https://api.github.com") | ||
self.assertEqual(service._g.per_page, PAGE_SIZE) | ||
|
||
@patch("mhq.exapi.github.Github", new=DummyGithub) | ||
def test_empty_string_domain_uses_default_url(self): | ||
token = "deadpool" | ||
service = GithubApiService(access_token=token, domain="") | ||
self.assertEqual(service.base_url, "https://api.github.com") | ||
self.assertEqual(service._g.base_url, "https://api.github.com") | ||
|
||
@patch("mhq.exapi.github.Github", new=DummyGithub) | ||
def test_custom_domain_appends_api_v3(self): | ||
token = "deadpool" | ||
custom_domain = "https://github.sujai.com" | ||
service = GithubApiService(access_token=token, domain=custom_domain) | ||
expected = f"{custom_domain}/api/v3" | ||
self.assertEqual(service.base_url, expected) | ||
self.assertEqual(service._g.base_url, expected) |
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,3 @@ | ||
const { TextEncoder, TextDecoder } = require('util'); | ||
global.TextEncoder = TextEncoder; | ||
global.TextDecoder = TextDecoder; |
84 changes: 84 additions & 0 deletions
84
web-server/pages/api/internal/[org_id]/__tests__/github.test.ts
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,84 @@ | ||
jest.mock('@/utils/db', () => ({ | ||
db: jest.fn(), | ||
})); | ||
|
||
import { db } from '@/utils/db'; | ||
import * as githubUtils from '../utils'; | ||
import { DEFAULT_GH_URL } from '@/constants/urls'; | ||
|
||
describe('GitHub URL utilities', () => { | ||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('getGitHubCustomDomain', () => { | ||
it('returns custom_domain when present', async () => { | ||
const mockMeta = [{ custom_domain: 'custom.sujai.com' }]; | ||
(db as jest.Mock).mockReturnValue({ | ||
where: jest.fn().mockReturnThis(), | ||
then: jest.fn().mockResolvedValue(mockMeta) | ||
}); | ||
|
||
const domain = await githubUtils.getGitHubCustomDomain(); | ||
expect(domain).toBe('custom.sujai.com'); | ||
}); | ||
|
||
it('returns null when no provider_meta found', async () => { | ||
(db as jest.Mock).mockReturnValue({ | ||
where: jest.fn().mockReturnThis(), | ||
then: jest.fn().mockResolvedValue([]) | ||
}); | ||
|
||
const domain = await githubUtils.getGitHubCustomDomain(); | ||
expect(domain).toBeNull(); | ||
}); | ||
|
||
it('returns null on db error and logs error', async () => { | ||
const consoleSpy = jest.spyOn(console, 'error').mockImplementation(); | ||
(db as jest.Mock).mockImplementation(() => { | ||
throw new Error('DB failure'); | ||
}); | ||
|
||
const domain = await githubUtils.getGitHubCustomDomain(); | ||
expect(domain).toBeNull(); | ||
expect(consoleSpy).toHaveBeenCalledWith( | ||
'Error occured while getting custom domain from database:', | ||
expect.any(Error) | ||
); | ||
}); | ||
}); | ||
|
||
describe('getGitHubRestApiUrl', () => { | ||
it('uses default URL when no custom domain', async () => { | ||
jest.spyOn(githubUtils, 'getGitHubCustomDomain').mockResolvedValue(null); | ||
const url = await githubUtils.getGitHubRestApiUrl('path/to/repo'); | ||
expect(url).toBe(`${DEFAULT_GH_URL}/path/to/repo`); | ||
}); | ||
|
||
it('uses custom domain when provided', async () => { | ||
jest.spyOn(githubUtils, 'getGitHubCustomDomain').mockResolvedValue('git.sujai.com'); | ||
const url = await githubUtils.getGitHubRestApiUrl('repos/owner/repo'); | ||
expect(url).toBe('https://git.sujai.com/api/v3/repos/owner/repo'); | ||
}); | ||
|
||
it('normalizes multiple slashes in URL', async () => { | ||
jest.spyOn(githubUtils, 'getGitHubCustomDomain').mockResolvedValue('git.sujai.com/'); | ||
const url = await githubUtils.getGitHubRestApiUrl('/repos//owner//repo'); | ||
expect(url).toBe('https://git.sujai.com/api/v3/repos/owner/repo'); | ||
}); | ||
}); | ||
|
||
describe('getGitHubGraphQLUrl', () => { | ||
it('uses default GraphQL endpoint when no custom domain', async () => { | ||
jest.spyOn(githubUtils, 'getGitHubCustomDomain').mockResolvedValue(null); | ||
const url = await githubUtils.getGitHubGraphQLUrl(); | ||
expect(url).toBe(`${DEFAULT_GH_URL}/graphql`); | ||
}); | ||
|
||
it('uses custom domain for GraphQL endpoint', async () => { | ||
jest.spyOn(githubUtils, 'getGitHubCustomDomain').mockResolvedValue('api.github.local'); | ||
const url = await githubUtils.getGitHubGraphQLUrl(); | ||
expect(url).toBe('https://api.github.local/api/graphql'); | ||
}); | ||
}); | ||
}); |
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 @@ | ||
export const DEFAULT_GH_URL = 'https://api.github.com'; |
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.
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.
Critical issue with DEFAULT_GH_URL constant
There appears to be a typo in the imported constant from
@/constants/urls.ts
. The constant is defined as'https://api.githb.com'
(missing an 'u'), which will cause all tests and production code to use an incorrect GitHub API URL.