Skip to content

Commit acd23a9

Browse files
feat(ci): add contributor reputation check workflow
Add automated screening for coordinated inauthentic contributions on PR/issue open events using AGT contributor reputation tools. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 63d08d5 commit acd23a9

1 file changed

Lines changed: 146 additions & 0 deletions

File tree

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
name: Contributor Reputation Check
2+
3+
on:
4+
pull_request_target:
5+
types: [opened]
6+
issues:
7+
types: [opened]
8+
9+
permissions:
10+
contents: read
11+
issues: write
12+
pull-requests: write
13+
14+
jobs:
15+
check:
16+
runs-on: ubuntu-latest
17+
if: >-
18+
github.actor != 'dependabot[bot]' &&
19+
github.actor != 'github-actions[bot]' &&
20+
github.actor != 'copilot-swe-agent[bot]'
21+
steps:
22+
- name: Checkout AGT scripts
23+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
24+
with:
25+
repository: microsoft/agent-governance-toolkit
26+
sparse-checkout: scripts
27+
path: agt
28+
29+
- name: Setup Python
30+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
31+
with:
32+
python-version: "3.12"
33+
34+
- name: Determine author
35+
id: author
36+
run: |
37+
if [ "${{ github.event_name }}" = "pull_request_target" ]; then
38+
echo "username=${{ github.event.pull_request.user.login }}" >> "$GITHUB_OUTPUT"
39+
echo "number=${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT"
40+
echo "type=pr" >> "$GITHUB_OUTPUT"
41+
else
42+
echo "username=${{ github.event.issue.user.login }}" >> "$GITHUB_OUTPUT"
43+
echo "number=${{ github.event.issue.number }}" >> "$GITHUB_OUTPUT"
44+
echo "type=issue" >> "$GITHUB_OUTPUT"
45+
fi
46+
47+
- name: Run profile check
48+
id: profile
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
run: |
52+
set +e
53+
python agt/scripts/contributor_check.py \
54+
--username "${{ steps.author.outputs.username }}" \
55+
--json > /tmp/profile.json 2>/tmp/profile.log
56+
set -e
57+
risk=$(python -c "import json; print(json.load(open('/tmp/profile.json'))['risk'])" 2>/dev/null || echo "UNKNOWN")
58+
echo "risk=$risk" >> "$GITHUB_OUTPUT"
59+
60+
- name: Run credential audit
61+
id: credential
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
run: |
65+
set +e
66+
python agt/scripts/credential_audit.py \
67+
--username "${{ steps.author.outputs.username }}" \
68+
--repo "${{ github.repository }}" \
69+
--json > /tmp/cred.json 2>/tmp/cred.log
70+
set -e
71+
risk=$(python -c "import json; print(json.load(open('/tmp/cred.json'))['risk'])" 2>/dev/null || echo "UNKNOWN")
72+
echo "risk=$risk" >> "$GITHUB_OUTPUT"
73+
74+
- name: Compute overall risk
75+
id: overall
76+
run: |
77+
risk_to_num() {
78+
case "$1" in HIGH) echo 3 ;; MEDIUM) echo 2 ;; LOW) echo 1 ;; *) echo 0 ;; esac
79+
}
80+
p=$(risk_to_num "${{ steps.profile.outputs.risk }}")
81+
c=$(risk_to_num "${{ steps.credential.outputs.risk }}")
82+
max=$p; [ "$c" -gt "$max" ] && max=$c
83+
case "$max" in 3) r="HIGH" ;; 2) r="MEDIUM" ;; *) r="LOW" ;; esac
84+
echo "risk=$r" >> "$GITHUB_OUTPUT"
85+
86+
- name: Comment on MEDIUM or HIGH risk
87+
if: steps.overall.outputs.risk == 'MEDIUM' || steps.overall.outputs.risk == 'HIGH'
88+
env:
89+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90+
run: |
91+
username="${{ steps.author.outputs.username }}"
92+
number="${{ steps.author.outputs.number }}"
93+
type="${{ steps.author.outputs.type }}"
94+
risk="${{ steps.overall.outputs.risk }}"
95+
profile="${{ steps.profile.outputs.risk }}"
96+
cred="${{ steps.credential.outputs.risk }}"
97+
98+
if [ "$risk" = "HIGH" ]; then icon="🔴"; else icon="🟡"; fi
99+
100+
body="<!-- agt-contributor-check -->
101+
$icon **Contributor Reputation Check: $risk risk**
102+
103+
| Check | Risk |
104+
|-------|------|
105+
| Profile | $profile |
106+
| Credential audit | $cred |
107+
108+
Maintainers: please review this contributor before merging.
109+
*Automated check powered by [AGT](https://github.com/microsoft/agent-governance-toolkit).*"
110+
111+
if [ "$type" = "pr" ]; then
112+
gh pr comment "$number" --body "$body"
113+
else
114+
gh issue comment "$number" --body "$body"
115+
fi
116+
117+
- name: Add risk label
118+
if: steps.overall.outputs.risk == 'MEDIUM' || steps.overall.outputs.risk == 'HIGH'
119+
env:
120+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
121+
run: |
122+
number="${{ steps.author.outputs.number }}"
123+
type="${{ steps.author.outputs.type }}"
124+
risk="${{ steps.overall.outputs.risk }}"
125+
126+
gh label create "needs-review:$risk" \
127+
--description "Contributor reputation check flagged $risk risk" \
128+
--color "FFA500" --force 2>/dev/null || true
129+
130+
if [ "$type" = "pr" ]; then
131+
gh pr edit "$number" --add-label "needs-review:$risk"
132+
else
133+
gh issue edit "$number" --add-label "needs-review:$risk"
134+
fi
135+
136+
- name: Job summary
137+
if: always()
138+
run: |
139+
{
140+
echo "## Contributor Check: \`${{ steps.author.outputs.username }}\`"
141+
echo "| Check | Risk |"
142+
echo "|-------|------|"
143+
echo "| Profile | ${{ steps.profile.outputs.risk }} |"
144+
echo "| Credential | ${{ steps.credential.outputs.risk }} |"
145+
echo "| **Overall** | **${{ steps.overall.outputs.risk }}** |"
146+
} >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)