Skip to content

Commit f997236

Browse files
authored
Merge pull request #23 from PotLock/chore/add-github-config
feat(github): simplify PR labeler and intake checks workflows
2 parents 623ed52 + 5ee2262 commit f997236

2 files changed

Lines changed: 113 additions & 77 deletions

File tree

Lines changed: 96 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,104 @@
11
name: PR Intake Checks
22

33
on:
4-
pull_request_target:
5-
branches: [dev, main]
6-
types: [opened, reopened, synchronize, edited, ready_for_review]
7-
8-
concurrency:
9-
group: pr-intake-checks-${{ github.event.pull_request.number || github.run_id }}
10-
cancel-in-progress: true
4+
pull_request_target:
5+
types: [opened, synchronize, reopened]
116

127
permissions:
13-
contents: read
14-
pull-requests: write
15-
issues: write
8+
contents: read
9+
pull-requests: write
10+
11+
jobs:
12+
pr-intake:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
sparse-checkout: |
18+
.github
19+
sparse-checkout-cone-mode: false
1620

17-
env:
18-
GIT_CONFIG_COUNT: "1"
19-
GIT_CONFIG_KEY_0: core.hooksPath
20-
GIT_CONFIG_VALUE_0: /dev/null
21+
- name: Check PR and post feedback
22+
uses: actions/github-script@v7
23+
with:
24+
github-token: ${{ secrets.GITHUB_TOKEN }}
25+
script: |
26+
const { data: pr } = await github.rest.pulls.get({
27+
owner: context.repo.owner,
28+
repo: context.repo.repo,
29+
pull_number: context.issue.number
30+
});
2131
32+
const body = pr.body || '';
33+
const title = pr.title || '';
34+
const warnings = [];
35+
const blocking = [];
2236
23-
jobs:
24-
intake:
25-
name: Intake Checks
26-
runs-on: [self-hosted, Linux, X64, aws-india, blacksmith-2vcpu-ubuntu-2404, hetzner]
27-
timeout-minutes: 10
28-
steps:
29-
- name: Checkout repository
30-
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
31-
32-
- name: Run safe PR intake checks
33-
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
34-
with:
35-
script: |
36-
const script = require('./.github/workflows/scripts/pr_intake_checks.js');
37-
await script({ github, context, core });
37+
// Check PR template sections
38+
const requiredSections = [
39+
'Summary',
40+
'Problem statement',
41+
'Proposed solution',
42+
'Acceptance criteria'
43+
];
44+
45+
const missingSections = requiredSections.filter(section =>
46+
!body.includes(section)
47+
);
48+
49+
if (missingSections.length > 0) {
50+
warnings.push(`Missing sections: ${missingSections.join(', ')}`);
51+
}
52+
53+
// Check for issue reference
54+
if (!/#\d+/.test(body) && !/#\d+/.test(title)) {
55+
warnings.push('No issue reference found (recommended for traceability)');
56+
}
57+
58+
// Check for large PR
59+
const { data: files } = await github.rest.pulls.listFiles({
60+
owner: context.repo.owner,
61+
repo: context.repo.repo,
62+
pull_number: context.issue.number
63+
});
64+
65+
const totalChanges = files.reduce((sum, f) => sum + f.additions + f.deletions, 0);
66+
if (totalChanges > 500) {
67+
warnings.push(`Large PR: ${totalChanges} lines changed`);
68+
}
69+
70+
// Check for merge conflicts
71+
for (const file of files) {
72+
if (file.patch && (file.patch.includes('<<<<<<<') || file.patch.includes('=======') || file.patch.includes('>>>>>>>'))) {
73+
blocking.push(`Merge conflicts in ${file.filename}`);
74+
}
75+
}
76+
77+
// Build comment
78+
let commentBody = '';
79+
80+
if (blocking.length > 0) {
81+
commentBody += '## PR Intake Checks - Blocking Issues\n\n';
82+
commentBody += '❌ These issues must be resolved before merging:\n\n';
83+
blocking.forEach(e => commentBody += `- ${e}\n`);
84+
commentBody += '\n---\n\n';
85+
}
86+
87+
if (warnings.length > 0) {
88+
commentBody += '## PR Intake Checks - Warnings (non-blocking)\n\n';
89+
commentBody += 'The following are recommendations:\n\n';
90+
warnings.forEach(w => commentBody += `- ${w}\n`);
91+
}
92+
93+
if (commentBody) {
94+
await github.rest.issues.createComment({
95+
owner: context.repo.owner,
96+
repo: context.repo.repo,
97+
issue_number: context.issue.number,
98+
body: commentBody
99+
});
100+
}
101+
102+
if (blocking.length > 0) {
103+
core.setFailed('Blocking issues found in PR');
104+
}

.github/workflows/pr-labeler.yml

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,25 @@
11
name: PR Labeler
22

33
on:
4-
pull_request_target:
5-
branches: [dev, main]
6-
types: [opened, reopened, synchronize, edited, labeled, unlabeled]
7-
workflow_dispatch:
8-
inputs:
9-
mode:
10-
description: "Run mode for managed-label governance"
11-
required: true
12-
default: "audit"
13-
type: choice
14-
options:
15-
- audit
16-
- repair
17-
18-
concurrency:
19-
group: pr-labeler-${{ github.event.pull_request.number || github.run_id }}
20-
cancel-in-progress: true
4+
pull_request_target:
5+
types: [opened, synchronize, reopened]
216

227
permissions:
23-
contents: read
24-
pull-requests: write
25-
issues: write
26-
27-
env:
28-
GIT_CONFIG_COUNT: "1"
29-
GIT_CONFIG_KEY_0: core.hooksPath
30-
GIT_CONFIG_VALUE_0: /dev/null
31-
LABEL_POLICY_PATH: .github/label-policy.json
8+
contents: read
9+
pull-requests: write
3210

3311
jobs:
34-
label:
35-
runs-on: [self-hosted, Linux, X64, aws-india, blacksmith-2vcpu-ubuntu-2404, hetzner]
36-
steps:
37-
- name: Checkout repository
38-
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
39-
40-
- name: Apply path labels
41-
if: github.event_name == 'pull_request_target'
42-
uses: actions/labeler@634933edcd8ababfe52f92936142cc22ac488b1b # v6.0.1
43-
continue-on-error: true
44-
with:
45-
repo-token: ${{ secrets.GITHUB_TOKEN }}
46-
sync-labels: true
12+
label:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
sparse-checkout: |
18+
.github
19+
sparse-checkout-cone-mode: false
4720

48-
- name: Apply size/risk/module labels
49-
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
50-
continue-on-error: true
51-
env:
52-
LABEL_POLICY_PATH: .github/label-policy.json
53-
with:
54-
script: |
55-
const script = require('./.github/workflows/scripts/pr_labeler.js');
56-
await script({ github, context, core });
21+
- uses: actions/labeler@v5
22+
with:
23+
repo-token: "${{ secrets.GITHUB_TOKEN }}"
24+
configuration-path: .github/labeler.yml
25+
sync-labels: true

0 commit comments

Comments
 (0)