diff --git a/.github/scripts/plagiarism_check.py b/.github/scripts/plagiarism_check.py new file mode 100644 index 0000000..fc5f238 --- /dev/null +++ b/.github/scripts/plagiarism_check.py @@ -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() \ No newline at end of file diff --git a/.github/workflows/plagiarism_check.yml b/.github/workflows/plagiarism_check.yml new file mode 100644 index 0000000..23b35d4 --- /dev/null +++ b/.github/workflows/plagiarism_check.yml @@ -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 }} \ No newline at end of file