forked from lablab-ai/technologies
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mathias Åsberg
authored
Mar 30, 2023
1 parent
dc062bd
commit b331b02
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |