feature/rebase-upstream #1
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -24,6 +24,8 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version: 20.x
|
node-version: 20.x
|
||||||
cache: npm
|
cache: npm
|
||||||
|
- name: Install Docker
|
||||||
|
run: apt update && apt install docker.io -y
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
- run: npm run format-check
|
- run: npm run format-check
|
||||||
|
18
.github/workflows/upstream_sync.yml
vendored
Normal file
18
.github/workflows/upstream_sync.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# .github/workflows/sync.yml
|
||||||
|
name: Rebase Upstream
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: "0 0 * * 0" # run once a week
|
||||||
|
workflow_dispatch: # run manually
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
sync:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@master
|
||||||
|
with:
|
||||||
|
fetch-depth: 10 # greater than the number of commits you made
|
||||||
|
- uses: imba-tjd/rebase-upstream-action@master
|
||||||
|
with: # all args are optional
|
||||||
|
upstream: peter-evans/create-pull-request
|
||||||
|
branch: main
|
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
set -xv
|
||||||
|
|
||||||
IMAGE="cpr-integration-tests:latest"
|
IMAGE="cpr-integration-tests:latest"
|
||||||
ARG1=${1:-}
|
ARG1=${1:-}
|
||||||
|
49
dist/index.js
vendored
49
dist/index.js
vendored
@ -405,8 +405,10 @@ 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 ghBranch = new github_helper_1.GitHubHelper(baseRemote.hostname, inputs.branchToken);
|
const apiUrl = yield github_helper_1.GitHubHelper.determineApiUrl(baseRemote.hostname);
|
||||||
const ghPull = new github_helper_1.GitHubHelper(baseRemote.hostname, inputs.token);
|
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);
|
||||||
// Determine the head repository; the target for the pull request branch
|
// Determine the head repository; the target for the pull request branch
|
||||||
const branchRemoteName = inputs.pushToFork ? 'fork' : 'origin';
|
const branchRemoteName = inputs.pushToFork ? 'fork' : 'origin';
|
||||||
const branchRepository = inputs.pushToFork
|
const branchRepository = inputs.pushToFork
|
||||||
@ -1275,25 +1277,52 @@ const core = __importStar(__nccwpck_require__(7484));
|
|||||||
const octokit_client_1 = __nccwpck_require__(3489);
|
const octokit_client_1 = __nccwpck_require__(3489);
|
||||||
const p_limit_1 = __importDefault(__nccwpck_require__(7989));
|
const p_limit_1 = __importDefault(__nccwpck_require__(7989));
|
||||||
const utils = __importStar(__nccwpck_require__(9277));
|
const utils = __importStar(__nccwpck_require__(9277));
|
||||||
const ERROR_PR_ALREADY_EXISTS = 'A pull request already exists for';
|
const ERROR_PR_ALREADY_EXISTS = 'pull request already exists for';
|
||||||
const ERROR_PR_REVIEW_TOKEN_SCOPE = 'Validation Failed: "Could not resolve to a node with the global id of';
|
const ERROR_PR_REVIEW_TOKEN_SCOPE = 'Validation Failed: "Could not resolve to a node with the global id of';
|
||||||
const ERROR_PR_FORK_COLLAB = `Fork collab can't be granted by someone without permission`;
|
const ERROR_PR_FORK_COLLAB = `Fork collab can't be granted by someone without permission`;
|
||||||
const blobCreationLimit = (0, p_limit_1.default)(8);
|
const blobCreationLimit = (0, p_limit_1.default)(8);
|
||||||
class GitHubHelper {
|
class GitHubHelper {
|
||||||
constructor(githubServerHostname, token) {
|
constructor(apiUrl, token) {
|
||||||
const options = {};
|
const options = {};
|
||||||
if (token) {
|
if (token) {
|
||||||
options.auth = `${token}`;
|
options.auth = `${token}`;
|
||||||
}
|
}
|
||||||
if (githubServerHostname !== 'github.com') {
|
options.baseUrl = apiUrl;
|
||||||
options.baseUrl = `https://${githubServerHostname}/api/v3`;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
options.baseUrl = 'https://api.github.com';
|
|
||||||
}
|
|
||||||
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) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (hostname === 'github.com') {
|
||||||
|
return 'https://api.github.com';
|
||||||
|
}
|
||||||
|
const baseUrl = `https://${hostname}`;
|
||||||
|
const possiblePaths = [
|
||||||
|
'/api/v4/version',
|
||||||
|
'/api/forgejo/v1/version',
|
||||||
|
'/api/v1/version'
|
||||||
|
];
|
||||||
|
for (const path of possiblePaths) {
|
||||||
|
try {
|
||||||
|
const url = `${baseUrl}${path}`;
|
||||||
|
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)) && // We might get 401, 403
|
||||||
|
// as we're unauthorised
|
||||||
|
contentType.includes('application/json')) {
|
||||||
|
return path.includes('/version') ? url.replace('/version', '') : url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
// Ignore errors and try the next path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error(`Unable to determine API base URL for hostname: ${hostname}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
parseRepository(repository) {
|
parseRepository(repository) {
|
||||||
const [owner, repo] = repository.split('/');
|
const [owner, repo] = repository.split('/');
|
||||||
return {
|
return {
|
||||||
|
@ -51,8 +51,10 @@ 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 ghBranch = new GitHubHelper(baseRemote.hostname, inputs.branchToken)
|
const apiUrl = await GitHubHelper.determineApiUrl(baseRemote.hostname)
|
||||||
const ghPull = new GitHubHelper(baseRemote.hostname, inputs.token)
|
core.info(`Using API base URL: ${apiUrl}`)
|
||||||
|
const ghBranch = new GitHubHelper(apiUrl, inputs.branchToken)
|
||||||
|
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
|
||||||
const branchRemoteName = inputs.pushToFork ? 'fork' : 'origin'
|
const branchRemoteName = inputs.pushToFork ? 'fork' : 'origin'
|
||||||
const branchRepository = inputs.pushToFork
|
const branchRepository = inputs.pushToFork
|
||||||
|
@ -5,7 +5,7 @@ import {Octokit, OctokitOptions, throttleOptions} from './octokit-client'
|
|||||||
import pLimit from 'p-limit'
|
import pLimit from 'p-limit'
|
||||||
import * as utils from './utils'
|
import * as utils from './utils'
|
||||||
|
|
||||||
const ERROR_PR_ALREADY_EXISTS = 'A pull request already exists for'
|
const ERROR_PR_ALREADY_EXISTS = 'pull request already exists for'
|
||||||
const ERROR_PR_REVIEW_TOKEN_SCOPE =
|
const ERROR_PR_REVIEW_TOKEN_SCOPE =
|
||||||
'Validation Failed: "Could not resolve to a node with the global id of'
|
'Validation Failed: "Could not resolve to a node with the global id of'
|
||||||
const ERROR_PR_FORK_COLLAB = `Fork collab can't be granted by someone without permission`
|
const ERROR_PR_FORK_COLLAB = `Fork collab can't be granted by someone without permission`
|
||||||
@ -41,20 +41,54 @@ type TreeObject = {
|
|||||||
export class GitHubHelper {
|
export class GitHubHelper {
|
||||||
private octokit: InstanceType<typeof Octokit>
|
private octokit: InstanceType<typeof Octokit>
|
||||||
|
|
||||||
constructor(githubServerHostname: string, token: string) {
|
constructor(apiUrl: string, token: string) {
|
||||||
const options: OctokitOptions = {}
|
const options: OctokitOptions = {}
|
||||||
if (token) {
|
if (token) {
|
||||||
options.auth = `${token}`
|
options.auth = `${token}`
|
||||||
}
|
}
|
||||||
if (githubServerHostname !== 'github.com') {
|
options.baseUrl = apiUrl
|
||||||
options.baseUrl = `https://${githubServerHostname}/api/v3`
|
|
||||||
} else {
|
|
||||||
options.baseUrl = 'https://api.github.com'
|
|
||||||
}
|
|
||||||
options.throttle = throttleOptions
|
options.throttle = throttleOptions
|
||||||
this.octokit = new Octokit(options)
|
this.octokit = new Octokit(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async determineApiUrl(hostname: string): Promise<string> {
|
||||||
|
if (hostname === 'github.com') {
|
||||||
|
return 'https://api.github.com'
|
||||||
|
}
|
||||||
|
|
||||||
|
const baseUrl = `https://${hostname}`
|
||||||
|
const possiblePaths = [
|
||||||
|
'/api/v4/version',
|
||||||
|
'/api/forgejo/v1/version',
|
||||||
|
'/api/v1/version'
|
||||||
|
]
|
||||||
|
|
||||||
|
for (const path of possiblePaths) {
|
||||||
|
try {
|
||||||
|
const url = `${baseUrl}${path}`
|
||||||
|
const response = await 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)) && // We might get 401, 403
|
||||||
|
// as we're unauthorised
|
||||||
|
contentType.includes('application/json')
|
||||||
|
) {
|
||||||
|
return path.includes('/version') ? url.replace('/version', '') : url
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// Ignore errors and try the next path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`Unable to determine API base URL for hostname: ${hostname}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private parseRepository(repository: string): Repository {
|
private parseRepository(repository: string): Repository {
|
||||||
const [owner, repo] = repository.split('/')
|
const [owner, repo] = repository.split('/')
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user