name: UncivBot on: [issue_comment] jobs: summary: if: github.event.comment.body == 'summary' runs-on: ubuntu-latest steps: - uses: actions/github-script@v3 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | var result = await github.repos.listCommits({ owner: context.repo.owner, repo: context.repo.repo, per_page: 50 }); var commitSummary = ""; var ownerToCommits = {} var reachedPreviousVersion = false result.data.forEach(commit => { if (reachedPreviousVersion) return var author = commit.author.login if (author=="uncivbot[bot]") return var commitMessage = commit.commit.message.split("\n")[0]; if (commitMessage.match(/^\d+\.\d+\.\d+$/)){ // match EXACT version, like 3.4.55 ^ is for start-of-line, $ for end-of-line reachedPreviousVersion=true console.log(commitMessage) return } if (commitMessage.startsWith("Merge ") || commitMessage.startsWith("Update ")) return commitMessage = commitMessage.replace(/\(\#\d+\)/,"") // match PR auto-text, like (#2345) if (author != context.repo.owner){ if (ownerToCommits[author] == undefined) ownerToCommits[author]=[] ownerToCommits[author].push(commitMessage) } else commitSummary += "\n\n" + commitMessage }); Object.entries(ownerToCommits).forEach(entry => { const [author, commits] = entry; if (commits.length==1) commitSummary += "\n\n" + commits[0] + " - By "+author else { commitSummary += "\n\nBy "+author+":" commits.forEach(commitMessage => { commitSummary += "\n- "+commitMessage }) } }) github.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: commitSummary }) merge_translations: if: github.event.comment.body == 'merge translations' runs-on: ubuntu-latest steps: - uses: actions/github-script@v3 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | async function branchExists(branchName) { try { await github.git.getRef({ owner: context.repo.owner, repo: context.repo.repo, ref: 'heads/' + branchName }) return true } catch (err) { return false } } async function getDefaultBranch() { var repo = await github.repos.get({owner: context.repo.owner, repo: context.repo.repo}) return repo.data.default_branch } var translations = "translations" async function createTranslationBranchIfNeeded() { if (await branchExists(translations)) return var defaultBranch = await getDefaultBranch() var currentHead = await context.github.git.getRef({ owner: context.repo.owner, repo: context.repo.repo, ref: 'heads/' + defaultBranch }) var currentSha = currentHead.data.object.sha app.log("Current sha: " + currentSha) await context.github.git.createRef({ owner: context.repo.owner, repo: context.repo.repo, ref: `refs/heads/`+translations, sha: currentSha }) await context.github.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: 'Translations branch created' }) } await createTranslationBranchIfNeeded() //async function createTranslationPrIfNeeded(context: Context, // owner: string, translations: string) { // var translationPulls = await context.github.pulls.list(context.repo({ state: "open", head: owner + ":" + translations })); // if (translationPulls.data.length == 0) { // var defaultBranch = await getDefaultBranch(context); // await context.github.pulls.create(context.repo({ title: "Translations update", head: translations, base: defaultBranch })); // await context.github.issues.createComment(context.issue({ body: 'Translations PR created' })); // } //}