Unciv/.github/workflows/uncivbot.yml

53 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:16:46 +07:00
if (commitMessage.match(/^\d+\.\d+\.\d+$/)){ // match EXACT version, like 3.4.55 ^ is for start-of-line, $ for end-of-line
2021-01-21 04:05:16 +07:00
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)
2021-01-21 04:11:21 +07:00
if (author != context.repo.owner){
2021-01-21 04:12:41 +07:00
if (ownerToCommits[author]==undefined) ownerToCommits[author]=[]
ownerToCommits[author].push(commitMessage)
2021-01-21 04:06:54 +07:00
}
else commitSummary += "\n\n" + commitMessage
});
2021-01-21 04:16:46 +07:00
ownerToCommits.forEach((commits,author)=>{
if (commits.length==1) commitSummary += "\n\n" + commitMessage+" By "+author
else {
commitSummary += "\n\nBy "+author+":"
commits.forEach(commitMessage => {commitSummary+="\n- "+commitMessage})
}
})
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
})