Skip to content

Commit d6ac2cc

Browse files
committed
TST: setup workflow for issue comments
1 parent e2f75c7 commit d6ac2cc

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

.github/workflows/style-guide.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: QuantEcon Style Guide Check
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
7+
jobs:
8+
style-check:
9+
if: contains(github.event.comment.body, '@qe-style-check')
10+
runs-on: ubuntu-latest
11+
name: Process style guide check request
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
ref: ${{ github.event.issue.pull_request && github.event.pull_request.head.ref || github.sha }}
19+
20+
- name: Check if user has permissions
21+
id: check-permissions
22+
uses: actions/github-script@v7
23+
with:
24+
script: |
25+
const { data: permissions } = await github.rest.repos.getCollaboratorPermissionLevel({
26+
owner: context.repo.owner,
27+
repo: context.repo.repo,
28+
username: context.payload.comment.user.login
29+
});
30+
31+
const hasPermissions = ['write', 'admin', 'maintain'].includes(permissions.permission);
32+
33+
if (!hasPermissions) {
34+
await github.rest.issues.createComment({
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
issue_number: context.issue.number,
38+
body: '⚠️ Sorry, only collaborators with write access can trigger style guide checks.'
39+
});
40+
core.setFailed('User does not have sufficient permissions');
41+
return;
42+
}
43+
44+
core.setOutput('has-permissions', 'true');
45+
46+
- name: React to comment
47+
if: steps.check-permissions.outputs.has-permissions == 'true'
48+
uses: actions/github-script@v7
49+
with:
50+
script: |
51+
await github.rest.reactions.createForIssueComment({
52+
owner: context.repo.owner,
53+
repo: context.repo.repo,
54+
comment_id: context.payload.comment.id,
55+
content: 'eyes'
56+
});
57+
58+
- name: Run style guide check
59+
if: steps.check-permissions.outputs.has-permissions == 'true'
60+
id: style-check
61+
uses: QuantEcon/meta/.github/actions/qe-style-guide@main
62+
with:
63+
github-token: ${{ secrets.GITHUB_TOKEN }}
64+
style-guide: '.github/copilot-qe-style-guide.md'
65+
docs: 'lectures/' # Adjust this to your content directory
66+
extensions: 'md' # Adjust file extensions as needed
67+
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
68+
model: 'gpt-4'
69+
max-suggestions: '20'
70+
confidence-threshold: '0.8'

0 commit comments

Comments
 (0)