Update uncivbot.yml

This commit is contained in:
Yair Morgenstern 2021-01-24 19:31:58 +02:00 committed by GitHub
parent 06240ba402
commit 09d6ecb246
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,12 +67,14 @@ jobs:
# and use that instead. # and use that instead.
github-token: ${{ secrets.ACTIONS_ACCESS_TOKEN }} github-token: ${{ secrets.ACTIONS_ACCESS_TOKEN }}
script: | script: |
const repo = {
owner: context.repo.owner,
repo: context.repo.repo }
async function branchExists(branchName) { async function branchExists(branchName) {
try { try {
await github.git.getRef({ await github.git.getRef({...repo, ref: 'heads/' + branchName })
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'heads/' + branchName })
return true return true
} catch (err) { } catch (err) {
return false return false
@ -80,7 +82,7 @@ jobs:
} }
async function getDefaultBranch() { async function getDefaultBranch() {
var repo = await github.repos.get({owner: context.repo.owner, repo: context.repo.repo}) var repo = await github.repos.get(repo)
return repo.data.default_branch return repo.data.default_branch
} }
@ -90,33 +92,22 @@ jobs:
if (await branchExists(translations)) return if (await branchExists(translations)) return
var defaultBranch = await getDefaultBranch() var defaultBranch = await getDefaultBranch()
var currentHead = await github.git.getRef({ var currentHead = await github.git.getRef({...repo, ref: 'heads/' + defaultBranch })
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'heads/' + defaultBranch })
var currentSha = currentHead.data.object.sha var currentSha = currentHead.data.object.sha
console.log("Current sha: " + currentSha) console.log("Current sha: " + currentSha)
await github.git.createRef({ await github.git.createRef({...repo,
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/heads/`+translations, ref: `refs/heads/`+translations,
sha: currentSha }) sha: currentSha })
await github.issues.createComment({ await github.issues.createComment({...repo,
issue_number: context.issue.number, issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Translations branch created' }) body: 'Translations branch created' })
} }
async function mergeExistingTranslationsIntoBranch(){ async function mergeExistingTranslationsIntoBranch(){
var translationPrs = await github.pulls.list({ var translationPrs = await github.pulls.list({ ...repo, state: "open" })
owner: context.repo.owner,
repo: context.repo.repo,
state: "open"
})
// When we used a forEach loop here, only one merge would happen at each run, // When we used a forEach loop here, only one merge would happen at each run,
// because we essentially started multiple async tasks in parallel and they conflicted. // because we essentially started multiple async tasks in parallel and they conflicted.
@ -129,16 +120,12 @@ jobs:
async function tryMergePr(pr){ async function tryMergePr(pr){
if (pr.base.ref != translations) if (pr.base.ref != translations)
await github.pulls.update({ await github.pulls.update({ ...repo,
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number, pull_number: pr.number,
base: translations }) base: translations })
try { try {
await github.pulls.merge({ await github.pulls.merge({...repo,
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number, pull_number: pr.number,
merge_method: "squash" }) merge_method: "squash" })
console.log("Merged #"+pr.number+", "+pr.title) console.log("Merged #"+pr.number+", "+pr.title)
@ -151,14 +138,22 @@ jobs:
await createTranslationBranchIfNeeded() await createTranslationBranchIfNeeded()
await mergeExistingTranslationsIntoBranch() await mergeExistingTranslationsIntoBranch()
//async function createTranslationPrIfNeeded(context: Context<Webhooks.WebhookPayloadIssueComment>, async function createTranslationPrIfNeeded(owner: string) {
// owner: string, translations: string) { var translationPulls = await github.pulls.list({...repo,
// var translationPulls = await context.github.pulls.list(context.repo({ state: "open", head: owner + ":" + translations })); state: "open",
// if (translationPulls.data.length == 0) { head: context.repo.owner + ":" + translations });
// var defaultBranch = await getDefaultBranch(context);
// await context.github.pulls.create(context.repo({ title: "Translations update", head: translations, base: defaultBranch })); if (translationPulls.data.length == 0) {
// await context.github.issues.createComment(context.issue({ body: 'Translations PR created' })); var defaultBranch = await getDefaultBranch(context);
// } await github.pulls.create({...repo,
//} title: "Translations update",
head: translations,
base: defaultBranch });
await github.issues.createComment({...repo,
issue_number: context.issue.number,
body: 'Translations PR created' });
}
}