Ma77Ball commented on code in PR #5651:
URL: https://github.com/apache/texera/pull/5651#discussion_r3409507283
##########
.github/workflows/comment-commands.yml:
##########
@@ -38,12 +47,170 @@ name: Comment commands
on:
issue_comment:
types: [created]
+ pull_request:
+ types: [opened, synchronize, reopened]
permissions:
+ contents: read
issues: write
pull-requests: write
jobs:
+ suggest-reviewers:
+ if: github.event_name == 'pull_request'
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v5
+ with:
+ fetch-depth: 0
+ - uses: actions/github-script@v8
+ with:
+ github-token: ${{ secrets.GITHUB_TOKEN }}
+ script: |
+ const { execFileSync } = require('node:child_process');
+ const pull_number = context.payload.pull_request.number;
+ const author = context.payload.pull_request.user.login;
+ const { owner, repo } = context.repo;
+
+ const { data: pull } = await github.rest.pulls.get({ owner, repo,
pull_number });
+
+ try {
+ execFileSync('git', ['fetch', 'origin', pull.base.ref], {
encoding: 'utf8' });
+ } catch (e) {
+ core.warning(`git fetch for base ref ${pull.base.ref} failed:
${e.message}`);
+ }
+
+ const files = await github.paginate(github.rest.pulls.listFiles, {
+ owner, repo, pull_number, per_page: 100,
+ });
+
+ // Parse `git blame -p` output to find the most-recent commit per
file.
+ function latestBlameCommit(blameOutput) {
+ let latest = null;
+ let current = null;
+
+ function finalizeCurrent() {
+ if (!current || current.authorTime == null) return;
+ if (!latest || current.authorTime > latest.authorTime) latest
= current;
+ }
+
+ for (const line of blameOutput.split(/\r?\n/)) {
+ const header = line.match(/^([0-9a-f^]+)\s+\d+\s+\d+\s+\d+$/);
+ if (header) {
+ finalizeCurrent();
+ current = { sha: header[1].replace(/^\^/, ''), authorTime:
null };
+ continue;
+ }
+ const authorTime = line.match(/^author-time\s+(\d+)$/);
+ if (authorTime && current) current.authorTime =
Number(authorTime[1]);
+ }
+
+ finalizeCurrent();
+ return latest;
+ }
+
+ // Count changed files touched per login; track collaborator
status.
+ const committerCounts = new Map(); // collaborators
+ const nonCommitterCounts = new Map(); // non-collaborators with a
GitHub login
+
+ for (const { filename, status } of files) {
+ if (status === 'removed' || status === 'added') continue;
+
+ let blameOutput;
+ try {
+ blameOutput = execFileSync(
+ 'git', ['blame', '-p', pull.base.sha, '--', filename],
Review Comment:
Renamed files don't exist at `base.sha`, so blame throws and they're
dropped. Use `previous_filename`:
```suggestion
for (const { filename, status, previous_filename } of files) {
if (status === 'removed' || status === 'added') continue;
const blamePath = status === 'renamed' ? previous_filename :
filename;
let blameOutput;
try {
blameOutput = execFileSync(
'git', ['blame', '-p', pull.base.sha, '--', blamePath],
```
##########
.github/workflows/comment-commands.yml:
##########
@@ -38,12 +47,170 @@ name: Comment commands
on:
issue_comment:
types: [created]
+ pull_request:
Review Comment:
`pull_request` gives a read-only token for fork PRs, so the comment writes
403. Use `pull_request_target` (as `pr-assignment.yml` does); safe here since
the job only blames `base.sha`. Also change line 60 to `'pull_request_target'`.
```suggestion
pull_request_target:
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]