-
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: implement docbot in cyborg (#3937)
* ci: implement docbot in cyborg Signed-off-by: tison <[email protected]> * allow remove non-existing label Signed-off-by: tison <[email protected]> * fixup Signed-off-by: tison <[email protected]> * fixup org name Signed-off-by: tison <[email protected]> * fixup step name Signed-off-by: tison <[email protected]> * remove unused file Signed-off-by: tison <[email protected]> --------- Signed-off-by: tison <[email protected]>
- Loading branch information
Showing
12 changed files
with
162 additions
and
103 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,16 @@ | ||
name: Setup cyborg environment | ||
description: Setup cyborg environment | ||
runs: | ||
using: composite | ||
steps: | ||
- 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 | ||
shell: bash | ||
run: pnpm tsx -v |
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
This file was deleted.
Oops, something went wrong.
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,22 @@ | ||
name: Follow Up Docs | ||
on: | ||
pull_request_target: | ||
types: [opened, edited] | ||
|
||
permissions: | ||
pull-requests: write | ||
contents: read | ||
|
||
jobs: | ||
docbot: | ||
runs-on: ubuntu-20.04 | ||
timeout-minutes: 10 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ./.github/actions/setup-cyborg | ||
- name: Maybe Follow Up Docs Issue | ||
working-directory: cyborg | ||
run: pnpm tsx bin/follow-up-docs-issue.ts | ||
env: | ||
DOCS_REPO_TOKEN: ${{ secrets.DOCS_REPO_TOKEN }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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
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
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,106 @@ | ||
/* | ||
* Copyright 2023 Greptime Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as core from '@actions/core' | ||
import {handleError, obtainClient} from "@/common"; | ||
import {context} from "@actions/github"; | ||
import {PullRequestEditedEvent, PullRequestEvent, PullRequestOpenedEvent} from "@octokit/webhooks-types"; | ||
// @ts-expect-error moduleResolution:nodenext issue 54523 | ||
import {RequestError} from "@octokit/request-error"; | ||
|
||
const needFollowUpDocs = "[x] This PR requires documentation updates." | ||
const labelDocsNotRequired = "docs-not-required" | ||
const labelDocsRequired = "docs-required" | ||
|
||
async function main() { | ||
if (!context.payload.pull_request) { | ||
throw new Error(`Only pull request event supported. ${context.eventName} is unsupported.`) | ||
} | ||
|
||
const client = obtainClient("GITHUB_TOKEN") | ||
const docsClient = obtainClient("DOCS_REPO_TOKEN") | ||
const payload = context.payload as PullRequestEvent | ||
const { owner, repo, number, actor, title, html_url } = { | ||
owner: payload.pull_request.base.user.login, | ||
repo: payload.pull_request.base.repo.name, | ||
number: payload.pull_request.number, | ||
title: payload.pull_request.title, | ||
html_url: payload.pull_request.html_url, | ||
actor: payload.pull_request.user.login, | ||
} | ||
const followUpDocs = checkPullRequestEvent(payload) | ||
if (followUpDocs) { | ||
core.info("Follow up docs.") | ||
await client.rest.issues.removeLabel({ | ||
owner, repo, issue_number: number, name: labelDocsNotRequired, | ||
}).catch((e: RequestError) => { | ||
if (e.status != 404) { | ||
throw e; | ||
} | ||
core.debug(`Label ${labelDocsNotRequired} not exist.`) | ||
}) | ||
await client.rest.issues.addLabels({ | ||
owner, repo, issue_number: number, labels: [labelDocsRequired], | ||
}) | ||
await docsClient.rest.issues.create({ | ||
owner: 'GreptimeTeam', | ||
repo: 'docs', | ||
title: `Update docs for ${title}`, | ||
body: `A document change request is generated from ${html_url}`, | ||
assignee: actor, | ||
}).then((res) => { | ||
core.info(`Created issue ${res.data}`) | ||
}) | ||
} else { | ||
core.info("No need to follow up docs.") | ||
await client.rest.issues.removeLabel({ | ||
owner, repo, issue_number: number, name: labelDocsRequired | ||
}).catch((e: RequestError) => { | ||
if (e.status != 404) { | ||
throw e; | ||
} | ||
core.debug(`Label ${labelDocsRequired} not exist.`) | ||
}) | ||
await client.rest.issues.addLabels({ | ||
owner, repo, issue_number: number, labels: [labelDocsNotRequired], | ||
}) | ||
} | ||
} | ||
|
||
function checkPullRequestEvent(payload: PullRequestEvent) { | ||
switch (payload.action) { | ||
case "opened": | ||
return checkPullRequestOpenedEvent(payload as PullRequestOpenedEvent) | ||
case "edited": | ||
return checkPullRequestEditedEvent(payload as PullRequestEditedEvent) | ||
default: | ||
throw new Error(`${payload.action} is unsupported.`) | ||
} | ||
} | ||
|
||
function checkPullRequestOpenedEvent(event: PullRequestOpenedEvent): boolean { | ||
// @ts-ignore | ||
return event.pull_request.body?.includes(needFollowUpDocs) | ||
} | ||
|
||
function checkPullRequestEditedEvent(event: PullRequestEditedEvent): boolean { | ||
const previous = event.changes.body?.from.includes(needFollowUpDocs) | ||
const current = event.pull_request.body?.includes(needFollowUpDocs) | ||
// from docs-not-need to docs-required | ||
return (!previous) && current | ||
} | ||
|
||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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