-
Notifications
You must be signed in to change notification settings - Fork 7
94 lines (83 loc) · 3.14 KB
/
TODO.yml
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
85
86
87
88
89
90
91
92
93
94
name: TODOs
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
find-todos:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Find TODOs
id: find_todos
run: |
TODO_LIST=$(grep -r -n -A 3 -E "TODO|@show " --include="*.jl" --include="*.ipynb" || true)
echo "todo_list<<EOF" >> $GITHUB_OUTPUT
echo "$TODO_LIST" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
if [ -n "$TODO_LIST" ]; then
echo "has_todos=true" >> $GITHUB_OUTPUT
else
echo "has_todos=false" >> $GITHUB_OUTPUT
fi
- name: Update or Create Comment
if: steps.find_todos.outputs.has_todos == 'true'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const todoList = process.env.TODO_LIST;
const body = `## TODOs and @show instances found in this PR:\n\n\`\`\`\n${todoList}\n\`\`\``;
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' && comment.body.includes('instances found in this PR'));
if (botComment) {
await github.rest.issues.updateComment({
comment_id: botComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
} else {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
}
env:
TODO_LIST: ${{ steps.find_todos.outputs.todo_list }}
- name: Remove Comment if No TODOs
if: steps.find_todos.outputs.has_todos == 'false'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' && comment.body.includes('instances found in this PR'));
if (botComment) {
await github.rest.issues.deleteComment({
comment_id: botComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
});
}
- name: TODO Check
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const hasTodos = '${{ steps.find_todos.outputs.has_todos }}' === 'true';
if (hasTodos) {
core.setFailed('TODOs found in this PR');
}