Repository navigation
ci: Label PRs from potentially automated accounts with AgentScan #26991
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
Draft
2010YOUY01
wants to merge
1
commit into
apache:main
Choose a base branch
from
2010YOUY01:codex/agentscan-pr-label
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+156
−0
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,123 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you 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. | ||
|
|
||
| # On PR open, reopen, or update, check the author's account with AgentScan. | ||
| # | ||
| # For positive agents-like user: | ||
| # 1. Add the "Prolific Author" label and | ||
| # 2. Post this comment once per PR (with links to the policy and account report): | ||
| # | ||
| # Please see our AI policy. AgentScan flagged this account for possible agent | ||
| # activity. This PR may be closed without notice. | ||
| # | ||
| # How it works | ||
| # A PR signal starts this workflow with permission to label and comment on fork PRs. | ||
| # 1. Install `@unveil/identity` (AgentScan's scoring engine) and `@unveil/vk`. | ||
| # 2. Use `@unveil/vk` to fetch the author's public GitHub activity and score it | ||
| # locally with `@unveil/identity` (e.g. 24/7 activity can suggest automation). | ||
| # 3. Label and notify authors classified as "mixed" or "automation". | ||
| name: AgentScan | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: ["Pull request signal"] | ||
| types: [requested] | ||
|
|
||
| permissions: {} | ||
|
|
||
| concurrency: | ||
| group: agentscan-${{ github.event.workflow_run.head_repository.id }}-${{ github.event.workflow_run.head_branch }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| scan: | ||
| if: >- | ||
| github.repository == 'apache/datafusion' && | ||
| github.event.workflow_run.event == 'pull_request' | ||
| runs-on: ubuntu-slim | ||
| timeout-minutes: 5 | ||
| permissions: | ||
| pull-requests: write | ||
| steps: | ||
| - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 | ||
| with: | ||
| node-version: "24" | ||
| package-manager-cache: false | ||
|
|
||
| - name: Install AgentScan's analyzer | ||
| # Pin both packages so the classification rules do not change between runs. | ||
| run: >- | ||
| npm install --prefix "$RUNNER_TEMP/agentscan" --ignore-scripts --no-audit --no-fund | ||
| @unveil/vk@1.0.0 @unveil/identity@3.0.0 | ||
|
|
||
| - name: Label and notify non-organic authors | ||
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 | ||
| env: | ||
| GITHUB_TOKEN: ${{ github.token }} | ||
| with: | ||
| script: | | ||
| const { createRequire } = require('node:module'); | ||
| const { analyze } = createRequire(`${process.env.RUNNER_TEMP}/agentscan/package.json`)('@unveil/vk'); | ||
| const run = context.payload.workflow_run; | ||
| const label = 'Prolific Author'; | ||
| const marker = '<!-- datafusion-agentscan -->'; | ||
| const policy = 'https://datafusion.apache.org/contributor-guide/ai-policy.html'; | ||
|
|
||
| // step1: Find every open PR for this branch and commit, including forks. | ||
| // The event's pull_requests can be empty; a newer head makes this run stale. | ||
| const prs = await github.paginate(github.rest.pulls.list, { | ||
| ...context.repo, state: 'open', per_page: 100, | ||
| head: `${run.head_repository.owner.login}:${run.head_branch}`, | ||
| }); | ||
| for (const pr of prs.filter(pr => pr.head.sha === run.head_sha)) { | ||
| const username = pr.user.login; | ||
|
|
||
| // step2: Let AgentScan fetch public GitHub activity and classify the author. | ||
| let result; | ||
| try { | ||
| result = await analyze(username, { token: process.env.GITHUB_TOKEN }); | ||
| } catch (error) { | ||
| core.warning(`AgentScan unavailable for ${username}: ${error.message}`); | ||
| continue; | ||
| } | ||
|
|
||
| // step3: For mixed or automation, add the label and one policy reminder. | ||
| if (result.user.id !== pr.user.id || | ||
| !['mixed', 'automation'].includes(result.report.classification)) continue; | ||
|
|
||
| const issue = { ...context.repo, issue_number: pr.number }; | ||
| if (!pr.labels.some(existing => existing.name === label)) { | ||
| await github.rest.issues.addLabels({ ...issue, labels: [label] }); | ||
| } | ||
| const comments = await github.paginate(github.rest.issues.listComments, { | ||
| ...issue, per_page: 100, | ||
| }); | ||
| const alreadyNotified = comments.some(comment => | ||
| comment.user?.login === 'github-actions[bot]' && | ||
| comment.user?.type === 'Bot' && | ||
| comment.body?.includes(marker), | ||
| ); | ||
| if (alreadyNotified) continue; | ||
|
|
||
| await github.rest.issues.createComment({ | ||
| ...issue, | ||
| body: `${marker}\nPlease see our [AI policy](${policy}). ` + | ||
| `[AgentScan](https://agentscan.tools/user/${encodeURIComponent(username)}) ` + | ||
| 'flagged this account for possible agent activity. ' + | ||
| 'This PR may be closed without notice.', | ||
| }); | ||
| } | ||
This file contains hidden or 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,33 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you 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. | ||
|
|
||
| # Shared signal for workflows that need write access on fork PRs. | ||
| name: Pull request signal | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, reopened, synchronize] | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| signal: | ||
| if: github.repository == 'apache/datafusion' | ||
| runs-on: ubuntu-slim | ||
| timeout-minutes: 1 | ||
| steps: | ||
| - run: echo "This run triggers the workflow_run workflows that handle the pull request." |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I worry about the security implications of running this package
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.
It seems like nodejs installs it in a different way:
https://github.com/nodejs/node/blob/95f3cf072e83d94ac90616c86a370b250f44a8d7/.github/workflows/contributor-guidance.yml#L77
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.
I agree with the concern about supply-chain security issue.
It can't get installed like nodejs, because we can only use whitelisted GitHub actions from ASF (not sure if it's possible to add it to the ASF whitelist)