-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-action-with-pr-comment.yml
More file actions
84 lines (71 loc) · 2.44 KB
/
Copy pathgithub-action-with-pr-comment.yml
File metadata and controls
84 lines (71 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Agent Scope
on:
pull_request:
permissions:
contents: read
pull-requests: write
jobs:
scope:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install agent-scope
run: npm install -g @floomhq/agent-scope
- name: Check scope
id: scope_check
run: |
agent-scope check --base origin/${{ github.base_ref }} --with-diff > scope-output.txt 2>&1
echo "exit_code=$?" >> "$GITHUB_OUTPUT"
{
echo 'result<<SCOPE_EOF'
cat scope-output.txt
echo ''
echo 'SCOPE_EOF'
} >> "$GITHUB_OUTPUT"
continue-on-error: true
- name: Comment PR
if: always()
uses: actions/github-script@v7
with:
script: |
const exitCode = parseInt('${{ steps.scope_check.outputs.exit_code }}', 10);
const output = `\`\`\`\n${{ steps.scope_check.outputs.result }}\n\`\`\``;
const header = exitCode === 0
? '✅ Agent Scope Check Passed'
: '❌ Agent Scope Check Failed';
const body = `## ${header}\n\n${output}\n\n---\n*Powered by [agent-scope](https://github.com/floomhq/agent-scope)*`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(c =>
c.user.type === 'Bot' && c.body.includes('Agent Scope Check')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
- name: Fail on violation
if: steps.scope_check.outputs.exit_code != '0'
run: |
cat scope-output.txt
echo "Scope violations detected. See PR comment for details."
exit 1