From 4480c8e4dcbfba18f091eaa87a39ce418c930c87 Mon Sep 17 00:00:00 2001 From: vibhansa Date: Tue, 24 Mar 2026 22:21:51 -0700 Subject: [PATCH 1/6] Add GitHub Action to label dependabot and copilot PRs --- .github/workflows/dependabot-label.yml | 67 ++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/dependabot-label.yml diff --git a/.github/workflows/dependabot-label.yml b/.github/workflows/dependabot-label.yml new file mode 100644 index 000000000..fea4fc21a --- /dev/null +++ b/.github/workflows/dependabot-label.yml @@ -0,0 +1,67 @@ +name: Label PRs + +on: + pull_request: + types: [opened] + +jobs: + add-label: + runs-on: ubuntu-latest + permissions: + 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; + const prNumber = context.payload.pull_request.number; + const actor = context.actor; + + // Check if PR is from dependabot + if (actor === 'dependabot[bot]' || actor === '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'); + } From 06c70d942e6a9b42e19c06eae879640f39863f7e Mon Sep 17 00:00:00 2001 From: Vikas Bhansali <64532198+vibhansa-msft@users.noreply.github.com> Date: Wed, 25 Mar 2026 10:56:08 +0530 Subject: [PATCH 2/6] Update .github/workflows/dependabot-label.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/dependabot-label.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dependabot-label.yml b/.github/workflows/dependabot-label.yml index fea4fc21a..5c07c8a76 100644 --- a/.github/workflows/dependabot-label.yml +++ b/.github/workflows/dependabot-label.yml @@ -2,7 +2,7 @@ name: Label PRs on: pull_request: - types: [opened] + types: [opened, synchronize, reopened] jobs: add-label: From 08156cd92de420446430b7145eca976a7b69a7c5 Mon Sep 17 00:00:00 2001 From: Vikas Bhansali <64532198+vibhansa-msft@users.noreply.github.com> Date: Wed, 25 Mar 2026 10:56:39 +0530 Subject: [PATCH 3/6] Update .github/workflows/dependabot-label.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/dependabot-label.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dependabot-label.yml b/.github/workflows/dependabot-label.yml index 5c07c8a76..fd360513c 100644 --- a/.github/workflows/dependabot-label.yml +++ b/.github/workflows/dependabot-label.yml @@ -17,10 +17,10 @@ jobs: const owner = context.repo.owner; const repo = context.repo.repo; const prNumber = context.payload.pull_request.number; - const actor = context.actor; + const prAuthor = context.payload.pull_request.user?.login; // Check if PR is from dependabot - if (actor === 'dependabot[bot]' || actor === 'dependabot') { + if (prAuthor === 'dependabot[bot]' || prAuthor === 'dependabot') { await github.rest.issues.addLabels({ owner, repo, issue_number: prNumber, labels: ['copilot'] From 55e0f33c5e1ec29277f7134459eba775f27169fc Mon Sep 17 00:00:00 2001 From: Vikas Bhansali <64532198+vibhansa-msft@users.noreply.github.com> Date: Wed, 25 Mar 2026 10:58:07 +0530 Subject: [PATCH 4/6] Update .github/workflows/dependabot-label.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/dependabot-label.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dependabot-label.yml b/.github/workflows/dependabot-label.yml index fd360513c..1fe410339 100644 --- a/.github/workflows/dependabot-label.yml +++ b/.github/workflows/dependabot-label.yml @@ -8,7 +8,8 @@ jobs: add-label: runs-on: ubuntu-latest permissions: - pull-requests: write + issues: write + pull-requests: read steps: - name: Check and add copilot label uses: actions/github-script@v7 From 627e4dfdcd45c0a14f307698592075ab433004d7 Mon Sep 17 00:00:00 2001 From: vibhansa Date: Tue, 24 Mar 2026 22:55:37 -0700 Subject: [PATCH 5/6] Fix: use pull_request_target and add issues write permission --- .github/workflows/dependabot-label.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dependabot-label.yml b/.github/workflows/dependabot-label.yml index 1fe410339..b4638d441 100644 --- a/.github/workflows/dependabot-label.yml +++ b/.github/workflows/dependabot-label.yml @@ -1,15 +1,15 @@ name: Label PRs on: - pull_request: - types: [opened, synchronize, reopened] + pull_request_target: + types: [opened] jobs: add-label: runs-on: ubuntu-latest permissions: issues: write - pull-requests: read + pull-requests: write steps: - name: Check and add copilot label uses: actions/github-script@v7 From a0571161be1b3217d481c6fa9ff84a2a13b974d7 Mon Sep 17 00:00:00 2001 From: vibhansa Date: Tue, 24 Mar 2026 22:59:06 -0700 Subject: [PATCH 6/6] Add workflow_dispatch trigger for manual testing --- .github/workflows/dependabot-label.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dependabot-label.yml b/.github/workflows/dependabot-label.yml index b4638d441..bbd5a77da 100644 --- a/.github/workflows/dependabot-label.yml +++ b/.github/workflows/dependabot-label.yml @@ -3,6 +3,12 @@ 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: @@ -17,8 +23,16 @@ jobs: script: | const owner = context.repo.owner; const repo = context.repo.repo; - const prNumber = context.payload.pull_request.number; - const prAuthor = context.payload.pull_request.user?.login; + + 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') {