Compare commits

..

1 commit

2 changed files with 7 additions and 9 deletions

15
dist/index.js vendored
View file

@ -405,7 +405,7 @@ function createPullRequest(inputs) {
core.startGroup('Determining the base and head repositories'); core.startGroup('Determining the base and head repositories');
const baseRemote = gitConfigHelper.getGitRemote(); const baseRemote = gitConfigHelper.getGitRemote();
// Init the GitHub clients // Init the GitHub clients
const apiUrl = yield github_helper_1.GitHubHelper.determineApiUrl(baseRemote.hostname); const apiUrl = yield github_helper_1.GitHubHelper.determineApiPath(baseRemote.hostname);
core.info(`Using API base URL: ${apiUrl}`); core.info(`Using API base URL: ${apiUrl}`);
const ghBranch = new github_helper_1.GitHubHelper(apiUrl, inputs.branchToken); const ghBranch = new github_helper_1.GitHubHelper(apiUrl, inputs.branchToken);
const ghPull = new github_helper_1.GitHubHelper(apiUrl, inputs.token); const ghPull = new github_helper_1.GitHubHelper(apiUrl, inputs.token);
@ -1289,7 +1289,7 @@ class GitHubHelper {
options.throttle = octokit_client_1.throttleOptions; options.throttle = octokit_client_1.throttleOptions;
this.octokit = new octokit_client_1.Octokit(options); this.octokit = new octokit_client_1.Octokit(options);
} }
static determineApiUrl(hostname) { static determineApiPath(hostname) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
if (hostname === 'github.com') { if (hostname === 'github.com') {
return "https://api.github.com"; return "https://api.github.com";
@ -1299,14 +1299,11 @@ class GitHubHelper {
for (const path of possiblePaths) { for (const path of possiblePaths) {
try { try {
const url = `${baseUrl}${path}`; const url = `${baseUrl}${path}`;
const response = yield fetch(url, { method: 'GET', redirect: 'manual' }); // GitLab redirects const response = yield fetch(url, { method: 'GET', redirect: 'manual' });
// invalid API paths
// to login prompt
// which returns 200
const contentType = response.headers.get('Content-Type') || ''; const contentType = response.headers.get('Content-Type') || '';
if ((response.ok || [401, 403].includes(response.status)) && // We might get 401, 403 if ((response.ok || [401, 403].includes(response.status)) && // Check for valid API status codes
// as we're unauthorised contentType.includes('application/json') // Ensure it's returning JSON
contentType.includes('application/json')) { ) {
return path.includes('/version') ? url.replace('/version', '') : url; return path.includes('/version') ? url.replace('/version', '') : url;
} }
} }

View file

@ -432,3 +432,4 @@ export class GitHubHelper {
}) })
} }
} }