Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .github/workflows/dependabot-label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Label PRs

on:
pull_request_target:
types: [opened]
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to label'
required: true
type: number

jobs:
add-label:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Check and add copilot label
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;

let prNumber, prAuthor;
if (context.eventName === 'workflow_dispatch') {
prNumber = Number(context.payload.inputs.pr_number);
const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number: prNumber });
prAuthor = pr.user?.login;
} else {
prNumber = context.payload.pull_request.number;
prAuthor = context.payload.pull_request.user?.login;
}

// Check if PR is from dependabot
if (prAuthor === 'dependabot[bot]' || prAuthor === 'dependabot') {
await github.rest.issues.addLabels({
owner, repo, issue_number: prNumber,
labels: ['copilot']
});
console.log('Added copilot label: PR authored by dependabot');
return;
}

// Check if >50% of commits are AI-generated.
// Detects:
// - Co-authored-by: Copilot / GitHub Copilot (inline suggestions)
// - Signed-off-by or trailers containing "copilot" (IDE agent via git hook)
// - Commit messages tagged with [copilot] (manual convention)
const commits = await github.paginate(
github.rest.pulls.listCommits,
{ owner, repo, pull_number: prNumber }
);

let copilotCommits = 0;
for (const commit of commits) {
const message = (commit.commit.message || '').toLowerCase();
const authorName = (commit.commit.author?.name || '').toLowerCase();
if (
message.includes('co-authored-by: copilot') ||
message.includes('co-authored-by: github copilot') ||
message.includes('[copilot]') ||
message.includes('generated-by: copilot') ||
authorName.includes('copilot')
) {
copilotCommits++;
}
}

const totalCommits = commits.length;
const percentage = totalCommits > 0 ? (copilotCommits / totalCommits) * 100 : 0;
console.log(`Copilot commits: ${copilotCommits}/${totalCommits} (${percentage.toFixed(1)}%)`);

if (percentage > 50) {
await github.rest.issues.addLabels({
owner, repo, issue_number: prNumber,
labels: ['copilot']
});
console.log('Added copilot label: >50% commits identified as AI-generated');
}
Loading