Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d6857d369 | ||
|
|
9153d834b6 |
@@ -210,8 +210,8 @@ describe('create-or-update-branch tests', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it('tests if a branch exists and can be fetched', async () => {
|
it('tests if a branch exists and can be fetched', async () => {
|
||||||
expect(await tryFetch(git, REMOTE_NAME, NOT_BASE_BRANCH)).toBeTruthy()
|
expect(await tryFetch(git, REMOTE_NAME, NOT_BASE_BRANCH, 1)).toBeTruthy()
|
||||||
expect(await tryFetch(git, REMOTE_NAME, NOT_EXIST_BRANCH)).toBeFalsy()
|
expect(await tryFetch(git, REMOTE_NAME, NOT_EXIST_BRANCH, 1)).toBeFalsy()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('tests getWorkingBaseAndType on a checked out ref', async () => {
|
it('tests getWorkingBaseAndType on a checked out ref', async () => {
|
||||||
|
|||||||
27193
dist/index.js
vendored
27193
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
16
package-lock.json
generated
16
package-lock.json
generated
@@ -14,8 +14,8 @@
|
|||||||
"@octokit/core": "^4.2.4",
|
"@octokit/core": "^4.2.4",
|
||||||
"@octokit/plugin-paginate-rest": "^5.0.1",
|
"@octokit/plugin-paginate-rest": "^5.0.1",
|
||||||
"@octokit/plugin-rest-endpoint-methods": "^6.8.1",
|
"@octokit/plugin-rest-endpoint-methods": "^6.8.1",
|
||||||
"https-proxy-agent": "^5.0.1",
|
|
||||||
"proxy-from-env": "^1.1.0",
|
"proxy-from-env": "^1.1.0",
|
||||||
|
"undici": "^6.14.1",
|
||||||
"uuid": "^9.0.1"
|
"uuid": "^9.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -2302,6 +2302,7 @@
|
|||||||
"version": "6.0.2",
|
"version": "6.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz",
|
||||||
"integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==",
|
"integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==",
|
||||||
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"debug": "4"
|
"debug": "4"
|
||||||
},
|
},
|
||||||
@@ -3019,6 +3020,7 @@
|
|||||||
"version": "4.3.4",
|
"version": "4.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
||||||
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ms": "2.1.2"
|
"ms": "2.1.2"
|
||||||
},
|
},
|
||||||
@@ -4912,6 +4914,7 @@
|
|||||||
"version": "5.0.1",
|
"version": "5.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz",
|
||||||
"integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==",
|
"integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==",
|
||||||
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"agent-base": "6",
|
"agent-base": "6",
|
||||||
"debug": "4"
|
"debug": "4"
|
||||||
@@ -6446,7 +6449,8 @@
|
|||||||
"node_modules/ms": {
|
"node_modules/ms": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
|
||||||
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/natural-compare": {
|
"node_modules/natural-compare": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
@@ -7931,6 +7935,14 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/undici": {
|
||||||
|
"version": "6.14.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/undici/-/undici-6.14.1.tgz",
|
||||||
|
"integrity": "sha512-mAel3i4BsYhkeVPXeIPXVGPJKeBzqCieZYoFsbWfUzd68JmHByhc1Plit5WlylxXFaGpgkZB8mExlxnt+Q1p7A==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.17"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/undici-types": {
|
"node_modules/undici-types": {
|
||||||
"version": "5.26.5",
|
"version": "5.26.5",
|
||||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
||||||
|
|||||||
@@ -34,8 +34,8 @@
|
|||||||
"@octokit/core": "^4.2.4",
|
"@octokit/core": "^4.2.4",
|
||||||
"@octokit/plugin-paginate-rest": "^5.0.1",
|
"@octokit/plugin-paginate-rest": "^5.0.1",
|
||||||
"@octokit/plugin-rest-endpoint-methods": "^6.8.1",
|
"@octokit/plugin-rest-endpoint-methods": "^6.8.1",
|
||||||
"https-proxy-agent": "^5.0.1",
|
|
||||||
"proxy-from-env": "^1.1.0",
|
"proxy-from-env": "^1.1.0",
|
||||||
|
"undici": "^6.14.1",
|
||||||
"uuid": "^9.0.1"
|
"uuid": "^9.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ const CHERRYPICK_EMPTY =
|
|||||||
'The previous cherry-pick is now empty, possibly due to conflict resolution.'
|
'The previous cherry-pick is now empty, possibly due to conflict resolution.'
|
||||||
const NOTHING_TO_COMMIT = 'nothing to commit, working tree clean'
|
const NOTHING_TO_COMMIT = 'nothing to commit, working tree clean'
|
||||||
|
|
||||||
|
const FETCH_DEPTH_MARGIN = 10
|
||||||
|
|
||||||
export enum WorkingBaseType {
|
export enum WorkingBaseType {
|
||||||
Branch = 'branch',
|
Branch = 'branch',
|
||||||
Commit = 'commit'
|
Commit = 'commit'
|
||||||
@@ -31,11 +33,13 @@ export async function getWorkingBaseAndType(
|
|||||||
export async function tryFetch(
|
export async function tryFetch(
|
||||||
git: GitCommandManager,
|
git: GitCommandManager,
|
||||||
remote: string,
|
remote: string,
|
||||||
branch: string
|
branch: string,
|
||||||
|
depth: number
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
await git.fetch([`${branch}:refs/remotes/${remote}/${branch}`], remote, [
|
await git.fetch([`${branch}:refs/remotes/${remote}/${branch}`], remote, [
|
||||||
'--force'
|
'--force',
|
||||||
|
`--depth=${depth}`
|
||||||
])
|
])
|
||||||
return true
|
return true
|
||||||
} catch {
|
} catch {
|
||||||
@@ -215,8 +219,15 @@ export async function createOrUpdateBranch(
|
|||||||
await git.fetch([`${base}:${base}`], baseRemote, fetchArgs)
|
await git.fetch([`${base}:${base}`], baseRemote, fetchArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine the fetch depth for the pull request branch (best effort)
|
||||||
|
const tempBranchCommitsAhead = await commitsAhead(git, base, tempBranch)
|
||||||
|
const fetchDepth =
|
||||||
|
tempBranchCommitsAhead > 0
|
||||||
|
? tempBranchCommitsAhead + FETCH_DEPTH_MARGIN
|
||||||
|
: FETCH_DEPTH_MARGIN
|
||||||
|
|
||||||
// Try to fetch the pull request branch
|
// Try to fetch the pull request branch
|
||||||
if (!(await tryFetch(git, branchRemoteName, branch))) {
|
if (!(await tryFetch(git, branchRemoteName, branch, fetchDepth))) {
|
||||||
// The pull request branch does not exist
|
// The pull request branch does not exist
|
||||||
core.info(`Pull request branch '${branch}' does not exist yet.`)
|
core.info(`Pull request branch '${branch}' does not exist yet.`)
|
||||||
// Create the pull request branch
|
// Create the pull request branch
|
||||||
@@ -250,7 +261,6 @@ export async function createOrUpdateBranch(
|
|||||||
// temp branch. This catches a case where the base branch has been force pushed to
|
// temp branch. This catches a case where the base branch has been force pushed to
|
||||||
// a new commit.
|
// a new commit.
|
||||||
// For changes on base this reset is equivalent to a rebase of the pull request branch.
|
// For changes on base this reset is equivalent to a rebase of the pull request branch.
|
||||||
const tempBranchCommitsAhead = await commitsAhead(git, base, tempBranch)
|
|
||||||
const branchCommitsAhead = await commitsAhead(git, base, branch)
|
const branchCommitsAhead = await commitsAhead(git, base, branch)
|
||||||
if (
|
if (
|
||||||
(await git.hasDiff([`${branch}..${tempBranch}`])) ||
|
(await git.hasDiff([`${branch}..${tempBranch}`])) ||
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import {Octokit as Core} from '@octokit/core'
|
import {Octokit as Core} from '@octokit/core'
|
||||||
import {paginateRest} from '@octokit/plugin-paginate-rest'
|
import {paginateRest} from '@octokit/plugin-paginate-rest'
|
||||||
import {restEndpointMethods} from '@octokit/plugin-rest-endpoint-methods'
|
import {restEndpointMethods} from '@octokit/plugin-rest-endpoint-methods'
|
||||||
import {HttpsProxyAgent} from 'https-proxy-agent'
|
|
||||||
import {getProxyForUrl} from 'proxy-from-env'
|
import {getProxyForUrl} from 'proxy-from-env'
|
||||||
|
import {ProxyAgent, fetch as undiciFetch} from 'undici'
|
||||||
export {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods'
|
export {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods'
|
||||||
export {OctokitOptions} from '@octokit/core/dist-types/types'
|
export {OctokitOptions} from '@octokit/core/dist-types/types'
|
||||||
|
|
||||||
@@ -12,12 +12,23 @@ export const Octokit = Core.plugin(
|
|||||||
autoProxyAgent
|
autoProxyAgent
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const proxyFetch =
|
||||||
|
(proxyUrl: string): typeof undiciFetch =>
|
||||||
|
(url, opts) => {
|
||||||
|
return undiciFetch(url, {
|
||||||
|
...opts,
|
||||||
|
dispatcher: new ProxyAgent({
|
||||||
|
uri: proxyUrl
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Octokit plugin to support the standard environment variables http_proxy, https_proxy and no_proxy
|
// Octokit plugin to support the standard environment variables http_proxy, https_proxy and no_proxy
|
||||||
function autoProxyAgent(octokit: Core) {
|
function autoProxyAgent(octokit: Core) {
|
||||||
octokit.hook.before('request', options => {
|
octokit.hook.before('request', options => {
|
||||||
const proxy = getProxyForUrl(options.baseUrl)
|
const proxy = getProxyForUrl(options.baseUrl)
|
||||||
if (proxy) {
|
if (proxy) {
|
||||||
options.request.agent = new HttpsProxyAgent(proxy)
|
options.request.fetch = proxyFetch(proxy)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user