-
Notifications
You must be signed in to change notification settings - Fork 235
feat: add workflow to review PRs labeled with GFI and Beginner #1828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /** | ||
| * This script automatically requests triage reviews on PRs labeled as "Good First Issue" or "Beginner". | ||
| * It runs on when a pr added with label "Good First Issue" or "Beginner" and posts a comment mentioing triage reviewers. | ||
| * | ||
| * safty measures: | ||
| * - Only runs on PRs (not issues). | ||
| * - Only run for once per pr. | ||
| * - it does not run on new commit push but can run on pr label update | ||
| */ | ||
|
|
||
|
|
||
| const fs = require("fs"); | ||
| const https = require("https"); | ||
|
|
||
| function fail(message) { | ||
| console.error(`${message}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| function info(message) { | ||
| console.log(`${message}`); | ||
| } | ||
|
|
||
|
|
||
| const eventPath = process.env.GITHUB_EVENT_PATH; | ||
| const repository = process.env.GITHUB_REPOSITORY; | ||
| const token = process.env.GITHUB_TOKEN; | ||
|
|
||
| if (!eventPath) fail("GITHUB_EVENT_PATH is not set."); | ||
| if (!repository) fail("GITHUB_REPOSITORY is not set."); | ||
| if (!token) fail("GITHUB_TOKEN is not set."); | ||
|
|
||
|
|
||
| let event; | ||
|
|
||
| try { | ||
| const payload = fs.readFileSync(eventPath, "utf8"); | ||
| event = JSON.parse(payload); | ||
| } catch (err) { | ||
| fail(`Failed to read GitHub event payload: ${err.message}`); | ||
| } | ||
|
|
||
| const prNumber = event?.pull_request?.number; | ||
|
|
||
| if (!prNumber) { | ||
| info("No pull request found in event payload. Exiting."); | ||
| process.exit(0); | ||
| } | ||
|
|
||
|
|
||
| const [owner, repo] = repository.split("/"); | ||
|
|
||
| if (!owner || !repo) { | ||
| fail("Invalid GITHUB_REPOSITORY format. Expected owner/repo."); | ||
| } | ||
|
|
||
|
|
||
| const commentBody = | ||
| "Requesting triage review from: @hiero-ledger/hiero-sdk-python-triage"; | ||
|
|
||
| info(`Preparing to comment on PR #${prNumber} in ${owner}/${repo}`); | ||
|
|
||
|
|
||
| const data = JSON.stringify({ body: commentBody }); | ||
|
|
||
| const options = { | ||
| hostname: "api.github.com", | ||
| path: `/repos/${owner}/${repo}/issues/${prNumber}/comments`, | ||
| method: "POST", | ||
| headers: { | ||
| "User-Agent": "triage-review-bot", | ||
| "Authorization": `Bearer ${token}`, | ||
| "Accept": "application/vnd.github+json", | ||
| "Content-Type": "application/json", | ||
| "Content-Length": Buffer.byteLength(data), | ||
| }, | ||
| }; | ||
|
|
||
| const req = https.request(options, (res) => { | ||
| let body = ""; | ||
|
|
||
| res.on("data", (chunk) => { | ||
| body += chunk; | ||
| }); | ||
|
|
||
| res.on("end", () => { | ||
| if (res.statusCode >= 200 && res.statusCode < 300) { | ||
| info("Comment posted successfully."); | ||
| } else { | ||
| console.error(`Error: GitHub API error (${res.statusCode})`); | ||
| console.error(body); | ||
| process.exit(1); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| req.on("error", (err) => { | ||
| fail(`Request failed: ${err.message}`); | ||
| }); | ||
|
|
||
| req.write(data); | ||
| req.end(); | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||||||||
| name: Request triage review on beginner PRs | ||||||||||||||||
|
|
||||||||||||||||
| on: | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can convert this to a cron trigger every 1 hour to request triage review, if needed |
||||||||||||||||
| pull_request: | ||||||||||||||||
| types: [labeled] | ||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
|
|
||||||||||||||||
| permissions: | ||||||||||||||||
| contents: read | ||||||||||||||||
| pull-requests: write | ||||||||||||||||
|
Comment on lines
+7
to
+9
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🔒 Proposed correction (for the intended behavior) permissions:
contents: read
+ issues: write
- pull-requests: writeAs per coding guidelines: "Requested permissions MUST exactly match behavior" and "Explicitly validate common cases: 📝 Committable suggestion
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| jobs: | ||||||||||||||||
| request-triage: | ||||||||||||||||
| if: ${{ github.event.label.name == 'Good First Issue' || github.event.label.name == 'Beginner'}} | ||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
|
|
||||||||||||||||
| steps: | ||||||||||||||||
| - name: Checkout | ||||||||||||||||
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | ||||||||||||||||
|
|
||||||||||||||||
| - name: Request triage by comment | ||||||||||||||||
| run: node .github/scripts/bot-pr-gfi-review-triage.js | ||||||||||||||||
| env: | ||||||||||||||||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||||||||||||||
|
Comment on lines
+22
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's find and view the workflow file
find . -name "request-triage-review.yml" -type fRepository: hiero-ledger/hiero-sdk-python Length of output: 118 🏁 Script executed: # Get the full context of the workflow file to understand the github-script usage
cat -n ".github/workflows/request-triage-review.yml" 2>/dev/null || echo "File not found"Repository: hiero-ledger/hiero-sdk-python Length of output: 1184 🏁 Script executed: # Search for all github-script usages in workflows to see how other workflows handle authentication
rg -n "uses: actions/github-script" --type yaml -A5Repository: hiero-ledger/hiero-sdk-python Length of output: 55 🏁 Script executed: # Check if the script section references GITHUB_TOKEN env var
rg -n "GITHUB_TOKEN" --type yaml .github/workflows/Repository: hiero-ledger/hiero-sdk-python Length of output: 2684 Remove redundant
Proposed fix await github.rest.pulls.requestReviewers({
owner,
repo,
pull_number: prNumber,
team_reviewers,
});
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you are making manual e.g. https calls
the current script mainly does three things: parse the event, extract the PR number, and post a comment via the API.
All of that is already available through https://github.com/actions/github-script, i think
e.g
context.payload.pull_request.number
https://docs.github.com/en/actions/reference/workflows-and-actions/contexts