-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: create cyborg for all heavy GitHub integrated actions (#3852)
* ci: create cyborg for all heavy GitHub integrated actions Signed-off-by: tison <[email protected]> * hack trigger for testing Signed-off-by: tison <[email protected]> * fixup token population Signed-off-by: tison <[email protected]> * tidy up Signed-off-by: tison <[email protected]> * use tsx Signed-off-by: tison <[email protected]> --------- Signed-off-by: tison <[email protected]>
- Loading branch information
Showing
8 changed files
with
673 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "[email protected]", | ||
"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" | ||
} | ||
} |
Oops, something went wrong.