Skip to content

Commit 95d931a

Browse files
authored
feat: support discussions for github server (#1118)
* feat: support discussions for github server * update tests
1 parent e96fca2 commit 95d931a

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

src/utils/api/client.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ import type {
1818
import { apiRequestAuth } from './request';
1919

2020
import { print } from 'graphql/language/printer';
21-
import Constants from '../constants';
2221
import { QUERY_SEARCH_DISCUSSIONS } from './graphql/discussions';
2322
import { formatAsGitHubSearchSyntax } from './graphql/utils';
24-
import { getGitHubAPIBaseUrl } from './utils';
23+
import { getGitHubAPIBaseUrl, getGitHubGraphQLUrl } from './utils';
2524

2625
/**
2726
* Get Hypermedia links to resources accessible in GitHub's REST API
@@ -247,7 +246,8 @@ export async function searchDiscussions(
247246
notification: Notification,
248247
token: string,
249248
): AxiosPromise<GraphQLSearch<Discussion>> {
250-
return apiRequestAuth(Constants.GITHUB_API_GRAPHQL_URL, 'POST', token, {
249+
const url = getGitHubGraphQLUrl(notification.hostname);
250+
return apiRequestAuth(url.toString(), 'POST', token, {
251251
query: print(QUERY_SEARCH_DISCUSSIONS),
252252
variables: {
253253
queryStatement: formatAsGitHubSearchSyntax(

src/utils/api/utils.test.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
1-
import { getGitHubAPIBaseUrl } from './utils';
1+
import { getGitHubAPIBaseUrl, getGitHubGraphQLUrl } from './utils';
22

33
describe('utils/api/utils.ts', () => {
4-
describe('generateGitHubAPIUrl', () => {
4+
describe('getGitHubAPIBaseUrl', () => {
55
it('should generate a GitHub API url - non enterprise', () => {
66
const result = getGitHubAPIBaseUrl('github.com');
77
expect(result.toString()).toBe('https://api.github.com/');
88
});
99

1010
it('should generate a GitHub API url - enterprise', () => {
11-
const result = getGitHubAPIBaseUrl('github.manos.im');
12-
expect(result.toString()).toBe('https://github.manos.im/api/v3/');
11+
const result = getGitHubAPIBaseUrl('github.gitify.io');
12+
expect(result.toString()).toBe('https://github.gitify.io/api/v3/');
13+
});
14+
});
15+
16+
describe('getGitHubGraphQLUrl', () => {
17+
it('should generate a GitHub GraphQL url - non enterprise', () => {
18+
const result = getGitHubGraphQLUrl('github.com');
19+
expect(result.toString()).toBe('https://api.github.com/graphql');
20+
});
21+
22+
it('should generate a GitHub GraphQL url - enterprise', () => {
23+
const result = getGitHubGraphQLUrl('github.gitify.io');
24+
expect(result.toString()).toBe('https://github.gitify.io/api/graphql');
1325
});
1426
});
1527
});

src/utils/api/utils.ts

+11
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,14 @@ export function getGitHubAPIBaseUrl(hostname: string): URL {
1010
}
1111
return url;
1212
}
13+
14+
export function getGitHubGraphQLUrl(hostname: string): URL {
15+
const url = new URL(Constants.GITHUB_API_GRAPHQL_URL);
16+
17+
if (isEnterpriseHost(hostname)) {
18+
url.hostname = hostname;
19+
url.pathname = '/api/graphql';
20+
}
21+
22+
return url;
23+
}

0 commit comments

Comments
 (0)