mirror of
https://forgejo.stefka.eu/jiriks74/create-pull-request.git
synced 2025-01-18 16:01:06 +01:00
feat: retry git push
This commit is contained in:
parent
29708c335a
commit
b8d27464d1
4 changed files with 3011 additions and 2 deletions
2973
dist/index.js
vendored
2973
dist/index.js
vendored
File diff suppressed because one or more lines are too long
|
@ -35,6 +35,7 @@
|
||||||
"@octokit/plugin-paginate-rest": "2.14.0",
|
"@octokit/plugin-paginate-rest": "2.14.0",
|
||||||
"@octokit/plugin-rest-endpoint-methods": "5.5.0",
|
"@octokit/plugin-rest-endpoint-methods": "5.5.0",
|
||||||
"@octokit/plugin-retry": "3.0.7",
|
"@octokit/plugin-retry": "3.0.7",
|
||||||
|
"bottleneck": "2.19.5",
|
||||||
"https-proxy-agent": "5.0.0",
|
"https-proxy-agent": "5.0.0",
|
||||||
"uuid": "8.3.2"
|
"uuid": "8.3.2"
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
import {GitHubHelper} from './github-helper'
|
import {GitHubHelper} from './github-helper'
|
||||||
import {GitCommandManager} from './git-command-manager'
|
import {GitCommandManager} from './git-command-manager'
|
||||||
import {GitAuthHelper} from './git-auth-helper'
|
import {GitAuthHelper} from './git-auth-helper'
|
||||||
|
import {pushWithRetry} from './git-push-retry'
|
||||||
import * as utils from './utils'
|
import * as utils from './utils'
|
||||||
|
|
||||||
export interface Inputs {
|
export interface Inputs {
|
||||||
|
@ -182,7 +183,7 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
|
||||||
core.startGroup(
|
core.startGroup(
|
||||||
`Pushing pull request branch to '${branchRemoteName}/${inputs.branch}'`
|
`Pushing pull request branch to '${branchRemoteName}/${inputs.branch}'`
|
||||||
)
|
)
|
||||||
await git.push([
|
await pushWithRetry(git, [
|
||||||
'--force-with-lease',
|
'--force-with-lease',
|
||||||
branchRemoteName,
|
branchRemoteName,
|
||||||
`HEAD:refs/heads/${inputs.branch}`
|
`HEAD:refs/heads/${inputs.branch}`
|
||||||
|
|
36
src/git-push-retry.ts
Normal file
36
src/git-push-retry.ts
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
import Bottleneck from 'bottleneck'
|
||||||
|
import * as core from '@actions/core'
|
||||||
|
import {GitCommandManager} from './git-command-manager'
|
||||||
|
|
||||||
|
const retryableErrors = [
|
||||||
|
'You have triggered an abuse detection mechanism and have been temporarily blocked from content creation. Please retry your request again later.'
|
||||||
|
]
|
||||||
|
const maxRetries = 3
|
||||||
|
const waitMilliseconds = 60000
|
||||||
|
|
||||||
|
const limiter = new Bottleneck()
|
||||||
|
|
||||||
|
limiter.on('failed', async (error, jobInfo) => {
|
||||||
|
const id = jobInfo.options.id
|
||||||
|
core.info(`Job '${id}' failed: ${error}`)
|
||||||
|
|
||||||
|
if (error.message in retryableErrors && jobInfo.retryCount < maxRetries) {
|
||||||
|
core.info(`Retrying job '${id}' in ${waitMilliseconds}ms`)
|
||||||
|
return waitMilliseconds + randomFromInterval(0, 10000)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
limiter.on('retry', (error, jobInfo) =>
|
||||||
|
core.info(`Now retrying job '${jobInfo.options.id}'`)
|
||||||
|
)
|
||||||
|
|
||||||
|
function randomFromInterval(min, max) {
|
||||||
|
return Math.floor(Math.random() * (max - min + 1) + min)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function pushWithRetry(
|
||||||
|
git: GitCommandManager,
|
||||||
|
options: string[]
|
||||||
|
): Promise<void> {
|
||||||
|
await limiter.schedule({id: 'git push'}, () => git.push(options))
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue