-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
review_markdown.yml
68 lines (59 loc) · 2.66 KB
/
review_markdown.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
name: Review Markdown
on:
pull_request:
paths:
- '**/*.md'
jobs:
review_markdown:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Download pre-built Rust script from remote repository
run: |
# Fetch the latest release information from the GitHub API
release_info=$(curl -s -H "Accept: application/vnd.github+json" https://api.github.com/repos/hummusonrails/github-action-gpt-language-check/releases/latest)
# Extract the binary's download URL using 'jq'
binary_url=$(echo $release_info | jq -r '.assets[] | select(.name == "github-action-gpt-language-check") | .browser_download_url')
# Download the binary using 'wget'
wget "$binary_url" -O github-action-gpt-language-check
# Make the binary executable
chmod +x github-action-gpt-language-check
shell: bash
- name: Run Rust script for each markdown file
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
suggestions=""
pr_files=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github+json" https://api.github.com/repos/$GITHUB_REPOSITORY/pulls/${{ github.event.number }}/files | jq -r '.[].filename')
for file in $pr_files; do
if [[ $file == *.md ]]; then
echo "Reviewing: $file"
suggestion=$(./github-action-gpt-language-check "$file")
if [[ ! -z "$suggestion" ]]; then
suggestions+="- $file: $suggestion\n"
echo "Suggestion found"
echo "SUGGESTION_FOUND=true" >> $GITHUB_ENV
fi
fi
done
# Use printf to set SUGGESTIONS environment variable
printf 'SUGGESTIONS<<EOF\n%s\nEOF' "$suggestions" >> $GITHUB_ENV
- name: Add a comment to the pull request
if: ${{ env.SUGGESTION_FOUND == 'true' }}
uses: actions/github-script@v5
with:
script: |
const suggestionsList = process.env.SUGGESTIONS.split('\n').filter(suggestion => suggestion.trim() !== '');
let suggestionsMarkdown = '## Suggested Changes\n';
for (const suggestion of suggestionsList) {
const [file, ...suggestionText] = suggestion.split(':');
suggestionsMarkdown += `### Reviewed File: **${file.trim()}**\n\n`;
suggestionsMarkdown += `- ${suggestionText.join(':').trim()}\n\n`;
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: suggestionsMarkdown
});