Compare commits

..

2 commits

Author SHA1 Message Date
7174d368c2
chore: Build 2024-12-16 03:38:12 +01:00
1b757dbf52
feat: Handle API URLs for Forgejo, Gitea, GitLab and GitHub 2024-12-16 03:37:45 +01:00
2 changed files with 9 additions and 7 deletions

15
dist/index.js vendored
View file

@ -405,7 +405,7 @@ function createPullRequest(inputs) {
core.startGroup('Determining the base and head repositories');
const baseRemote = gitConfigHelper.getGitRemote();
// 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}`);
const ghBranch = new github_helper_1.GitHubHelper(apiUrl, inputs.branchToken);
const ghPull = new github_helper_1.GitHubHelper(apiUrl, inputs.token);
@ -1289,7 +1289,7 @@ class GitHubHelper {
options.throttle = octokit_client_1.throttleOptions;
this.octokit = new octokit_client_1.Octokit(options);
}
static determineApiPath(hostname) {
static determineApiUrl(hostname) {
return __awaiter(this, void 0, void 0, function* () {
if (hostname === 'github.com') {
return "https://api.github.com";
@ -1299,11 +1299,14 @@ class GitHubHelper {
for (const path of possiblePaths) {
try {
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') || '';
if ((response.ok || [401, 403].includes(response.status)) && // Check for valid API status codes
contentType.includes('application/json') // Ensure it's returning JSON
) {
if ((response.ok || [401, 403].includes(response.status)) && // We might get 401, 403
// as we're unauthorised
contentType.includes('application/json')) {
return path.includes('/version') ? url.replace('/version', '') : url;
}
}

View file

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