Unciv/.github/workflows/uncivbot.yml

51 lines
2.0 KiB
YAML
Raw Normal View History

2021-01-21 03:28:19 +07:00
name: UncivBot
on: [issue_comment]
jobs:
comment:
2021-01-21 03:42:47 +07:00
if: github.event.comment.body == 'summary'
2021-01-21 03:28:19 +07:00
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
2021-01-21 03:56:45 +07:00
var result = await github.repos.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 50 });
2021-01-21 03:58:45 +07:00
var commitSummary = "";
var ownerToCommits = {}
var reachedPreviousVersion = false
result.data.forEach(commit => {
2021-01-21 04:05:16 +07:00
if (reachedPreviousVersion) return
2021-01-21 04:03:36 +07:00
var author = commit.author.login
2021-01-21 04:05:16 +07:00
if (author=="uncivbot[bot]") return
2021-01-21 04:03:36 +07:00
var commitMessage = commit.commit.message.split("\n")[0];
2021-01-21 04:06:54 +07:00
//commitSummary += "\n\n" + commitMessage
2021-01-21 04:05:16 +07:00
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
}
2021-01-21 04:06:54 +07:00
if(commitMessage.startsWith("Merge ")) return
commitMessage = commitMessage.replace(/\(\#\d+\)/,"") // match PR auto-text, like (#2345)
if (author != owner){
if (ownerToCommits.get(author)==undefined) ownerToCommits.set(author,[])
2021-01-21 04:08:44 +07:00
ownerToCommits.get(author).push(commitMessage)
2021-01-21 04:06:54 +07:00
}
else commitSummary += "\n\n" + commitMessage
});
2021-01-21 03:47:27 +07:00
//ownerToCommits.forEach((commits,author)=>{
// commitSummary += "\n\nBy "+author+":"
// commits.forEach(commitMessage => {commitSummary+="\n- "+commitMessage})
2021-01-21 04:10:05 +07:00
//})
2021-01-21 03:47:27 +07:00
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
2021-01-21 03:58:45 +07:00
body: commitSummary
2021-01-21 03:47:27 +07:00
})