-
Notifications
You must be signed in to change notification settings - Fork 70
61 lines (54 loc) · 1.95 KB
/
plagiarism-check.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
on:
issue_comment:
types: [created]
permissions:
contents: read
issues: read
pull-requests: write
jobs:
permission-check-job:
runs-on: ubuntu-latest
if: |
github.event.issue.pull_request &&
contains(github.event.comment.body, '/plagiarismcheck')
outputs:
permission: ${{ steps.permissions-check.outputs.defined }}
steps:
- name: Check for Secret availability
id: permissions-check
shell: bash
run: |
echo "defined=${{ contains(fromJSON(secrets.WIKI_REVIEWERS), github.actor) }}" >> $GITHUB_OUTPUT;
plagiarism-check:
runs-on: ubuntu-latest
name: "Checks a new article from a PR for plagiarism"
needs: [ permission-check-job ]
if: needs.permission-check-job.outputs.permission == 'true'
env:
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Go to PR files
run: gh pr checkout "${{ github.event.issue.number }}"
- name: Save article contents
run: |
pr_number="${{ github.event.issue.number }}"
file_path="$(gh pr diff --name-only $pr_number | grep '\.md' | head -n 1)"
if [ -n "$file_path" ]; then
cat "$file_path" > article.txt
else
gh pr comment "${{ github.event.issue.number }}" --body "No .md file found in the PR."
exit 1
fi
- name: Check for plagiarism
run: |
content="$(cat article.txt)"
escaped_content=$(jq -Rs . <<<"$content")
result="$(curl -X POST "${{ secrets.WORKER_URL }}" -H "Content-Type: application/json" -d "{\"text\": $escaped_content}")"
echo "$result" > results.txt
- name: Format and post response
run: |
response=$(cat results.txt)
results=$(echo "$response" | jq -r '.results')
gh pr comment "${{ github.event.issue.number }}" --body "$results"