Clean branch reference after merging

This commit is contained in:
lowlighter
2021-03-09 12:42:21 +01:00
parent 163146cd25
commit b77474e6a5

View File

@@ -29,6 +29,11 @@
} }
info.break = () => console.log("─".repeat(88)) info.break = () => console.log("─".repeat(88))
//Waiter
async function wait(seconds) {
await new Promise(solve => setTimeout(solve, seconds*1000)) //eslint-disable-line no-promise-executor-return
}
//Runner //Runner
;(async function() { ;(async function() {
try { try {
@@ -243,7 +248,7 @@
error = _error error = _error
console.debug("::endgroup::") console.debug("::endgroup::")
console.debug(`::warning::rendering failed (${error.message})`) console.debug(`::warning::rendering failed (${error.message})`)
await new Promise(solve => setTimeout(solve, retries_delay*1000)) //eslint-disable-line no-promise-executor-return await wait(retries_delay)
} }
} }
if (!rendered) if (!rendered)
@@ -298,13 +303,13 @@
//Merge pull request //Merge pull request
if (committer.merge) { if (committer.merge) {
info("Merge method", committer.merge) info("Merge method", committer.merge)
let attempts = 720 let attempts = 240
do { do {
//Check pull request mergeability (https://octokit.github.io/rest.js/v18#pulls-get) //Check pull request mergeability (https://octokit.github.io/rest.js/v18#pulls-get)
const {data:{mergeable, mergeable_state:state}} = await committer.rest.pulls.get({...github.context.repo, pull_number:number}) const {data:{mergeable, mergeable_state:state}} = await committer.rest.pulls.get({...github.context.repo, pull_number:number})
console.debug(`Pull request #${number} mergeable state is "${state}"`) console.debug(`Pull request #${number} mergeable state is "${state}"`)
if (mergeable === null) { if (mergeable === null) {
await new Promise(solve => setTimeout(solve, 5000)) //eslint-disable-line no-promise-executor-return await wait(15)
continue continue
} }
if (!mergeable) if (!mergeable)
@@ -312,6 +317,17 @@
//Merge pull request //Merge pull request
await committer.rest.pulls.merge({...github.context.repo, pull_number:number, merge_method:committer.merge}) await committer.rest.pulls.merge({...github.context.repo, pull_number:number, merge_method:committer.merge})
info(`Merge #${number} to ${committer.branch}`, "ok") info(`Merge #${number} to ${committer.branch}`, "ok")
//Delete head branch
try {
await wait(15)
await committer.rest.git.deleteRef({...github.context.repo, ref:`heads/${committer.head}`})
}
catch (error) {
console.debug(error)
if (!/reference does not exist/i.test(`${error}`))
throw error
}
info(`Branch ${committer.head}`, "(deleted)")
break break
} while (--attempts) } while (--attempts)
} }