File tree 3 files changed +30
-7
lines changed
3 files changed +30
-7
lines changed Original file line number Diff line number Diff line change @@ -18,10 +18,9 @@ import type {
18
18
import { apiRequestAuth } from './request' ;
19
19
20
20
import { print } from 'graphql/language/printer' ;
21
- import Constants from '../constants' ;
22
21
import { QUERY_SEARCH_DISCUSSIONS } from './graphql/discussions' ;
23
22
import { formatAsGitHubSearchSyntax } from './graphql/utils' ;
24
- import { getGitHubAPIBaseUrl } from './utils' ;
23
+ import { getGitHubAPIBaseUrl , getGitHubGraphQLUrl } from './utils' ;
25
24
26
25
/**
27
26
* Get Hypermedia links to resources accessible in GitHub's REST API
@@ -247,7 +246,8 @@ export async function searchDiscussions(
247
246
notification : Notification ,
248
247
token : string ,
249
248
) : 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 , {
251
251
query : print ( QUERY_SEARCH_DISCUSSIONS ) ,
252
252
variables : {
253
253
queryStatement : formatAsGitHubSearchSyntax (
Original file line number Diff line number Diff line change 1
- import { getGitHubAPIBaseUrl } from './utils' ;
1
+ import { getGitHubAPIBaseUrl , getGitHubGraphQLUrl } from './utils' ;
2
2
3
3
describe ( 'utils/api/utils.ts' , ( ) => {
4
- describe ( 'generateGitHubAPIUrl ' , ( ) => {
4
+ describe ( 'getGitHubAPIBaseUrl ' , ( ) => {
5
5
it ( 'should generate a GitHub API url - non enterprise' , ( ) => {
6
6
const result = getGitHubAPIBaseUrl ( 'github.com' ) ;
7
7
expect ( result . toString ( ) ) . toBe ( 'https://api.github.com/' ) ;
8
8
} ) ;
9
9
10
10
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' ) ;
13
25
} ) ;
14
26
} ) ;
15
27
} ) ;
Original file line number Diff line number Diff line change @@ -10,3 +10,14 @@ export function getGitHubAPIBaseUrl(hostname: string): URL {
10
10
}
11
11
return url ;
12
12
}
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
+ }
You can’t perform that action at this time.
0 commit comments