Skip to content

Commit

Permalink
Github Actions for plagarism check
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias Åsberg authored Mar 30, 2023
1 parent dc062bd commit b331b02
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/scripts/plagiarism_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import sys
import glob
import requests
import json

def check_plagiarism(file_path, api_key):
with open(file_path, 'r') as file:
content = file.read()

headers = {
'apikey': api_key,
'Content-Type': 'application/json'
}

data = {
'base64': content.encode('utf-8').decode('utf-8')
}

response = requests.post('https://api.copyleaks.com/v3/businesses/submit/url',
headers=headers, data=json.dumps(data))

if response.status_code != 200:
print(f'Error checking plagiarism for {file_path}: {response.text}')
return False

result = response.json()
return result['found']

def main():
api_key = os.environ['COPYLEAKS_API_KEY']
md_files = glob.glob('**/*.mdx', recursive=True)

plagiarism_found = False

for md_file in md_files:
if check_plagiarism(md_file, api_key):
print(f'Plagiarism detected in {md_file}')
plagiarism_found = True

if plagiarism_found:
print('Plagiarism check failed. Please review the flagged files.')
sys.exit(1)
else:
print('No plagiarism detected.')

if __name__ == '__main__':
main()
29 changes: 29 additions & 0 deletions .github/workflows/plagiarism_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Plagiarism Check

on:
pull_request:
paths:
- '**.mdx'

jobs:
plagiarism_check:
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
- name: Check plagiarism
run: |
python .github/scripts/plagiarism_check.py
env:
COPYLEAKS_API_KEY: ${{ secrets.COPYLEAKS_API_KEY }}

0 comments on commit b331b02

Please sign in to comment.