Compare commits
2 commits
2c60f35176
...
7174d368c2
Author | SHA1 | Date | |
---|---|---|---|
7174d368c2 | |||
1b757dbf52 |
2 changed files with 9 additions and 7 deletions
15
dist/index.js
vendored
15
dist/index.js
vendored
|
@ -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.determineApiPath(baseRemote.hostname);
|
const apiUrl = yield github_helper_1.GitHubHelper.determineApiUrl(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 determineApiPath(hostname) {
|
static determineApiUrl(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,11 +1299,14 @@ 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' });
|
const response = yield fetch(url, { method: 'GET', redirect: 'manual' }); // GitLab redirects
|
||||||
|
// 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)) && // Check for valid API status codes
|
if ((response.ok || [401, 403].includes(response.status)) && // We might get 401, 403
|
||||||
contentType.includes('application/json') // Ensure it's returning JSON
|
// as we're unauthorised
|
||||||
) {
|
contentType.includes('application/json')) {
|
||||||
return path.includes('/version') ? url.replace('/version', '') : url;
|
return path.includes('/version') ? url.replace('/version', '') : url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -432,4 +432,3 @@ export class GitHubHelper {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue