Skip to content

Commit 1906a34

Browse files
committed
docs: update pr workflows
1 parent e5d0c63 commit 1906a34

File tree

3 files changed

+166
-66
lines changed

3 files changed

+166
-66
lines changed

.github/workflows/pr-standards.yml

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: PR Standards
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize]
6+
7+
jobs:
8+
check-standards:
9+
if: |
10+
github.event.pull_request.user.login != 'actions-user' &&
11+
github.event.pull_request.user.login != 'opencode' &&
12+
github.event.pull_request.user.login != 'rekram1-node' &&
13+
github.event.pull_request.user.login != 'thdxr' &&
14+
github.event.pull_request.user.login != 'kommander' &&
15+
github.event.pull_request.user.login != 'jayair' &&
16+
github.event.pull_request.user.login != 'fwang' &&
17+
github.event.pull_request.user.login != 'adamdotdevin' &&
18+
github.event.pull_request.user.login != 'iamdavidhill' &&
19+
github.event.pull_request.user.login != 'opencode-agent[bot]'
20+
runs-on: ubuntu-latest
21+
permissions:
22+
pull-requests: write
23+
steps:
24+
- name: Check PR standards
25+
uses: actions/github-script@v7
26+
with:
27+
script: |
28+
const pr = context.payload.pull_request;
29+
const title = pr.title;
30+
31+
async function addLabel(label) {
32+
await github.rest.issues.addLabels({
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
issue_number: pr.number,
36+
labels: [label]
37+
});
38+
}
39+
40+
async function removeLabel(label) {
41+
try {
42+
await github.rest.issues.removeLabel({
43+
owner: context.repo.owner,
44+
repo: context.repo.repo,
45+
issue_number: pr.number,
46+
name: label
47+
});
48+
} catch (e) {
49+
// Label wasn't present, ignore
50+
}
51+
}
52+
53+
async function comment(marker, body) {
54+
const markerText = `<!-- pr-standards:${marker} -->`;
55+
const { data: comments } = await github.rest.issues.listComments({
56+
owner: context.repo.owner,
57+
repo: context.repo.repo,
58+
issue_number: pr.number
59+
});
60+
61+
const existing = comments.find(c => c.body.includes(markerText));
62+
if (existing) return;
63+
64+
await github.rest.issues.createComment({
65+
owner: context.repo.owner,
66+
repo: context.repo.repo,
67+
issue_number: pr.number,
68+
body: markerText + '\n' + body
69+
});
70+
}
71+
72+
// Step 1: Check title format
73+
const validPrefixes = ['feat:', 'fix:', 'docs:', 'chore:', 'refactor:', 'test:'];
74+
const hasValidTitle = validPrefixes.some(prefix => title.startsWith(prefix));
75+
76+
if (!hasValidTitle) {
77+
await addLabel('needs:title');
78+
await comment('title', `Hey! Your PR title \`${title}\` doesn't follow conventional commit format.
79+
80+
Please update it to start with one of:
81+
- \`feat:\` new feature
82+
- \`fix:\` bug fix
83+
- \`docs:\` documentation changes
84+
- \`chore:\` maintenance tasks
85+
- \`refactor:\` code refactoring
86+
- \`test:\` adding or updating tests
87+
88+
See [CONTRIBUTING.md](../blob/dev/CONTRIBUTING.md#pr-titles) for details.`);
89+
return;
90+
}
91+
92+
await removeLabel('needs:title');
93+
94+
// Step 2: Check for linked issue (skip for docs/refactor PRs)
95+
const skipIssueCheck = title.startsWith('docs:') || title.startsWith('refactor:');
96+
if (skipIssueCheck) {
97+
await removeLabel('needs:issue');
98+
console.log('Skipping issue check for docs/refactor PR');
99+
return;
100+
}
101+
const query = `
102+
query($owner: String!, $repo: String!, $number: Int!) {
103+
repository(owner: $owner, name: $repo) {
104+
pullRequest(number: $number) {
105+
closingIssuesReferences(first: 1) {
106+
totalCount
107+
}
108+
}
109+
}
110+
}
111+
`;
112+
113+
const result = await github.graphql(query, {
114+
owner: context.repo.owner,
115+
repo: context.repo.repo,
116+
number: pr.number
117+
});
118+
119+
const linkedIssues = result.repository.pullRequest.closingIssuesReferences.totalCount;
120+
121+
if (linkedIssues === 0) {
122+
await addLabel('needs:issue');
123+
await comment('issue', `Thanks for your contribution!
124+
125+
This PR doesn't have a linked issue. All PRs must reference an existing issue.
126+
127+
Please:
128+
1. Open an issue describing the bug/feature (if one doesn't exist)
129+
2. Add \`Fixes #<number>\` or \`Closes #<number>\` to this PR description
130+
131+
See [CONTRIBUTING.md](../blob/dev/CONTRIBUTING.md#issue-first-policy) for details.`);
132+
return;
133+
}
134+
135+
await removeLabel('needs:issue');
136+
console.log('PR meets all standards');

.github/workflows/pr-title.yml

Lines changed: 0 additions & 62 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,37 @@ With that said, you may want to try these methods, as they might work for you.
149149

150150
## Pull Request Expectations
151151

152-
- Try to keep pull requests small and focused.
153-
- Link relevant issue(s) in the description
152+
### Issue First Policy
153+
154+
**All PRs must reference an existing issue.** Before opening a PR, open an issue describing the bug or feature. This helps maintainers triage and prevents duplicate work. PRs without a linked issue may be closed without review.
155+
156+
- Use `Fixes #123` or `Closes #123` in your PR description to link the issue
157+
- For small fixes, a brief issue is fine - just enough context for maintainers to understand the problem
158+
159+
### General Requirements
160+
161+
- Keep pull requests small and focused
154162
- Explain the issue and why your change fixes it
155-
- Avoid having verbose LLM generated PR descriptions
156-
- Before adding new functions or functionality, ensure that such behavior doesn't already exist elsewhere in the codebase.
163+
- Before adding new functionality, ensure it doesn't already exist elsewhere in the codebase
164+
165+
### UI Changes
166+
167+
If your PR includes UI changes, please include screenshots or videos showing the before and after. This helps maintainers review faster and gives you quicker feedback.
168+
169+
### Logic Changes
170+
171+
For non-UI changes (bug fixes, new features, refactors), explain **how you verified it works**:
172+
173+
- What did you test?
174+
- How can a reviewer reproduce/confirm the fix?
175+
176+
### No AI-Generated Walls of Text
177+
178+
Long, AI-generated PR descriptions and issues are not acceptable and may be ignored. Respect the maintainers' time:
179+
180+
- Write short, focused descriptions
181+
- Explain what changed and why in your own words
182+
- If you can't explain it briefly, your PR might be too large
157183

158184
### PR Titles
159185

0 commit comments

Comments
 (0)