@@ -32,6 +32,14 @@ export default class Request {
3232 if ( url . startsWith ( `https://${ CI_DOMAIN } ` ) ) {
3333 options . headers = options . headers || { } ;
3434 Object . assign ( options . headers , this . getJenkinsHeaders ( ) ) ;
35+ } else if ( ! url . startsWith ( 'https://' ) ) {
36+ url = new URL ( url , 'https://api.github.com/' ) . href ;
37+ options . headers = {
38+ Authorization : `Basic ${ this . credentials . github } ` ,
39+ 'User-Agent' : 'node-core-utils' ,
40+ Accept : 'application/vnd.github+json' ,
41+ ...options . headers
42+ } ;
3543 }
3644 return wrappedFetch ( url , options ) ;
3745 }
@@ -65,14 +73,9 @@ export default class Request {
6573 }
6674
6775 async createIssue ( title , body , { owner, repo } ) {
68- const url = `https://api.github.com /repos/${ owner } /${ repo } /issues` ;
76+ const url = `/repos/${ owner } /${ repo } /issues` ;
6977 const options = {
7078 method : 'POST' ,
71- headers : {
72- Authorization : `Basic ${ this . credentials . github } ` ,
73- 'User-Agent' : 'node-core-utils' ,
74- Accept : 'application/vnd.github+json'
75- } ,
7679 body : JSON . stringify ( {
7780 title,
7881 body
@@ -82,15 +85,9 @@ export default class Request {
8285 }
8386
8487 async commentIssue ( fullUrl , comment ) {
85- const commentUrl = fullUrl . replace ( 'https://github.com/' , 'https://api.github.com/repos/' ) +
86- '/comments' ;
88+ const commentUrl = fullUrl . replace ( 'https://github.com/' , '/repos/' ) + '/comments' ;
8789 const options = {
8890 method : 'POST' ,
89- headers : {
90- Authorization : `Basic ${ this . credentials . github } ` ,
91- 'User-Agent' : 'node-core-utils' ,
92- Accept : 'application/vnd.github+json'
93- } ,
9491 body : JSON . stringify ( {
9592 body : comment ,
9693 } )
@@ -99,27 +96,14 @@ export default class Request {
9996 }
10097
10198 async getPullRequest ( fullUrl ) {
102- const prUrl = fullUrl . replace ( 'https://github.com/' , 'https://api.github.com/repos/' ) . replace ( 'pull' , 'pulls' ) ;
103- const options = {
104- method : 'GET' ,
105- headers : {
106- Authorization : `Basic ${ this . credentials . github } ` ,
107- 'User-Agent' : 'node-core-utils' ,
108- Accept : 'application/vnd.github+json'
109- }
110- } ;
111- return this . json ( prUrl , options ) ;
99+ const prUrl = fullUrl . replace ( 'https://github.com/' , '/repos/' ) . replace ( 'pull' , 'pulls' ) ;
100+ return this . json ( prUrl ) ;
112101 }
113102
114103 async createPullRequest ( title , body , { owner, repo, head, base } ) {
115- const url = `https://api.github.com /repos/${ owner } /${ repo } /pulls` ;
104+ const url = `/repos/${ owner } /${ repo } /pulls` ;
116105 const options = {
117106 method : 'POST' ,
118- headers : {
119- Authorization : `Basic ${ this . credentials . github } ` ,
120- 'User-Agent' : 'node-core-utils' ,
121- Accept : 'application/vnd.github+json'
122- } ,
123107 body : JSON . stringify ( {
124108 title,
125109 body,
@@ -131,13 +115,10 @@ export default class Request {
131115 }
132116
133117 async closePullRequest ( id , { owner, repo } ) {
134- const url = `https://api.github.com /repos/${ owner } /${ repo } /pulls/${ id } ` ;
118+ const url = `/repos/${ owner } /${ repo } /pulls/${ id } ` ;
135119 const options = {
136120 method : 'POST' ,
137121 headers : {
138- Authorization : `Basic ${ this . credentials . github } ` ,
139- 'User-Agent' : 'node-core-utils' ,
140- Accept : 'application/vnd.github+json' ,
141122 'Content-Type' : 'application/json'
142123 } ,
143124 body : JSON . stringify ( {
@@ -299,13 +280,11 @@ export default class Request {
299280 throw new Error ( 'The request has not been ' +
300281 'authenticated with a GitHub token' ) ;
301282 }
302- const url = 'https://api.github.com /graphql' ;
283+ const url = '/graphql' ;
303284 const options = {
304285 agent : this . proxyAgent ,
305286 method : 'POST' ,
306287 headers : {
307- Authorization : `Basic ${ githubCredentials } ` ,
308- 'User-Agent' : 'node-core-utils' ,
309288 Accept : 'application/vnd.github.antiope-preview+json'
310289 } ,
311290 body : JSON . stringify ( {
0 commit comments