Skip to content

Commit

Permalink
ci: create cyborg for all heavy GitHub integrated actions (#3852)
Browse files Browse the repository at this point in the history
* ci: create cyborg for all heavy GitHub integrated actions

Signed-off-by: tison <wander4096@gmail.com>

* hack trigger for testing

Signed-off-by: tison <wander4096@gmail.com>

* fixup token population

Signed-off-by: tison <wander4096@gmail.com>

* tidy up

Signed-off-by: tison <wander4096@gmail.com>

* use tsx

Signed-off-by: tison <wander4096@gmail.com>

---------

Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun authored May 2, 2024
1 parent 65d47ba commit 2748cec
Show file tree
Hide file tree
Showing 8 changed files with 673 additions and 21 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Schedule Management
on:
schedule:
- cron: '4 2 * * *'
workflow_dispatch:

permissions:
contents: read
issues: write
pull-requests: write

jobs:
maintenance:
name: Periodic Maintenance
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- uses: pnpm/action-setup@v3
with:
package_json_file: 'cyborg/package.json'
run_install: true
- name: Describe the Environment
working-directory: cyborg
run: pnpm tsx -v
- name: Do Maintenance
working-directory: cyborg
run: pnpm tsx bin/schedule.ts
env:
GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
21 changes: 0 additions & 21 deletions .github/workflows/unassign.yml

This file was deleted.

2 changes: 2 additions & 0 deletions cyborg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.env
57 changes: 57 additions & 0 deletions cyborg/bin/schedule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import * as core from '@actions/core'
import {GitHub} from "@actions/github/lib/utils"
import _ from "lodash";
import dayjs from "dayjs";
import {handleError, obtainClient} from "@/.";

async function main() {
const client = obtainClient()
await unassign(client)
}

async function unassign(client: InstanceType<typeof GitHub>) {
const owner = "GreptimeTeam"
const repo = "greptimedb"

const dt = dayjs().subtract(14, 'days');
core.info(`Open issues updated before ${dt.toISOString()} will be considered stale.`)

const members = await client.paginate(client.rest.repos.listCollaborators, {
owner,
repo,
permission: "push",
per_page: 100
}).then((members) => members.map((member) => member.login))
core.info(`Members (${members.length}): ${members}`)

const issues = await client.paginate(client.rest.issues.listForRepo, {
owner,
repo,
state: "open",
sort: "created",
direction: "asc",
per_page: 100
})
for (const issue of issues) {
let assignees = [];
if (issue.assignee) {
assignees.push(issue.assignee.login)
}
for (const assignee of issue.assignees) {
assignees.push(assignee.login)
}
assignees = _.uniq(assignees)
assignees = _.difference(assignees, members)
if (assignees.length > 0 && dayjs(issue.updated_at).isBefore(dt)) {
core.info(`Assignees ${assignees} of issue ${issue.number} will be unassigned.`)
await client.rest.issues.removeAssignees({
owner,
repo,
issue_number: issue.number,
assignees: assignees,
})
}
}
}

main().catch(handleError)
22 changes: 22 additions & 0 deletions cyborg/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "cyborg",
"version": "1.0.0",
"description": "Automator for GreptimeDB Repository Management",
"private": true,
"packageManager": "pnpm@8.15.5",
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"@octokit/webhooks-types": "^7.5.1",
"dayjs": "^1.11.11",
"dotenv": "^16.4.5",
"lodash": "^4.17.21"
},
"devDependencies": {
"@types/lodash": "^4.17.0",
"@types/node": "^20.12.7",
"tsconfig-paths": "^4.2.0",
"tsx": "^4.8.2",
"typescript": "^5.4.5"
}
}
Loading

0 comments on commit 2748cec

Please sign in to comment.