Compare commits

..

No commits in common. "fcb0baa025427b2d717df70bb3c4520e54d07bd9" and "7174d368c2e4450dea17b297819eb28ae93ee645" have entirely different histories.

3 changed files with 17 additions and 24 deletions

View file

@ -24,8 +24,6 @@ jobs:
with: with:
node-version: 20.x node-version: 20.x
cache: npm cache: npm
- name: Install Docker
run: apt install docker.io
- run: npm ci - run: npm ci
- run: npm run build - run: npm run build
- run: npm run format-check - run: npm run format-check

View file

@ -51,8 +51,8 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
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 = await GitHubHelper.determineApiUrl(baseRemote.hostname) const apiUrl = await GitHubHelper.determineApiUrl(baseRemote.hostname);
core.info(`Using API base URL: ${apiUrl}`) core.info(`Using API base URL: ${apiUrl}`);
const ghBranch = new GitHubHelper(apiUrl, inputs.branchToken) const ghBranch = new GitHubHelper(apiUrl, inputs.branchToken)
const ghPull = new GitHubHelper(apiUrl, inputs.token) const ghPull = new GitHubHelper(apiUrl, inputs.token)
// Determine the head repository; the target for the pull request branch // Determine the head repository; the target for the pull request branch

View file

@ -46,47 +46,42 @@ export class GitHubHelper {
if (token) { if (token) {
options.auth = `${token}` options.auth = `${token}`
} }
options.baseUrl = apiUrl options.baseUrl = apiUrl;
options.throttle = throttleOptions options.throttle = throttleOptions
this.octokit = new Octokit(options) this.octokit = new Octokit(options)
} }
static async determineApiUrl(hostname: string): Promise<string> { static async determineApiUrl(hostname: string): Promise<string> {
if (hostname === 'github.com') { if (hostname === 'github.com') {
return 'https://api.github.com' return "https://api.github.com";
} }
const baseUrl = `https://${hostname}` const baseUrl = `https://${hostname}`;
const possiblePaths = [ const possiblePaths = ['/api/v4/version', '/api/forgejo/v1/version', '/api/v1/version'];
'/api/v4/version',
'/api/forgejo/v1/version',
'/api/v1/version'
]
for (const path of possiblePaths) { for (const path of possiblePaths) {
try { try {
const url = `${baseUrl}${path}` const url = `${baseUrl}${path}`;
const response = await fetch(url, {method: 'GET', redirect: 'manual'}) // GitLab redirects const response = await fetch(url, { method: 'GET', redirect: 'manual' }); // GitLab redirects
// invalid API paths // invalid API paths
// to login prompt // to login prompt
// which returns 200 // which returns 200
const contentType = response.headers.get('Content-Type') || '' const contentType = response.headers.get('Content-Type') || '';
if ( if (
(response.ok || [401, 403].includes(response.status)) && // We might get 401, 403 (response.ok || [401, 403].includes(response.status)) && // We might get 401, 403
// as we're unauthorised // as we're unauthorised
contentType.includes('application/json') contentType.includes('application/json')
) { ) {
return path.includes('/version') ? url.replace('/version', '') : url return path.includes('/version') ? url.replace('/version', '') : url;
} }
} catch (error) { } catch (error) {
// Ignore errors and try the next path // Ignore errors and try the next path
} }
} }
throw new Error( throw new Error(`Unable to determine API base URL for hostname: ${hostname}`);
`Unable to determine API base URL for hostname: ${hostname}`
)
} }
private parseRepository(repository: string): Repository { private parseRepository(repository: string): Repository {