-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
444 verify git link #452
Merged
Merged
444 verify git link #452
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8d7179a
first try of check_if_github with mistake
MarinaProsche c27b2dc
try to fix parsing
MarinaProsche f2542dc
add check for empty repo GitHub
MarinaProsche 177fedb
fix space-problem
MarinaProsche eb82e1a
full check git-links 1.0
MarinaProsche 85991d0
add deep_check
MarinaProsche e930651
all
MarinaProsche e82b317
question
MarinaProsche 03275ce
req
MarinaProsche 7397a03
changes
MarinaProsche f15190e
optimize code
MarinaProsche bc3f7ef
merge master
MarinaProsche 6289ec5
fix conflicts
MarinaProsche fd9dab0
fix aprob_mistake
MarinaProsche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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,89 @@ | ||
|
||
import re | ||
import requests | ||
from lxml import html | ||
from urllib.parse import quote | ||
|
||
from .find_def_sld import FindDefSld | ||
from ..base_check import BasePresCriterion, answer | ||
|
||
# for check if gitlab-repository is closed: | ||
# GITLAB_URL = 'https://gitlab.com/api/v4' | ||
# PRIVATE_TOKEN = 'glpat-JeZApxShRgB1nsGrMsst' | ||
|
||
|
||
class PresVerifyGitLinkCheck(BasePresCriterion): | ||
description = "Проверка действительности ссылки на github" | ||
id = 'verify_git_link' | ||
|
||
def __init__(self, file_info, deep_check=True): | ||
super().__init__(file_info) | ||
self.deep_check = deep_check | ||
self.wrong_repo_ref = [] | ||
self.empty_repo_ref = [] | ||
|
||
# self.check_aprb = FindDefSld(file_info=file_info, key_slide="Апробация") | ||
self.pattern_for_repo = r'((((((http(s)?://)?(github|gitlab|bitbucket)+)+(.com|.org)+)+/[a-zA-Z0-9_-]+)+/[a-zA-Z0-9_-]+)+/*)+' | ||
self.pattern_for_repo_incorrect = r'\(github\.com\)|\(gitlab\.com\)|\(bitbucket\.org\)|\(github\)|\(gitlab\)|\(bitbucket\)' | ||
self.pattern_repo_mention = r'репозиторий|репозитория|репозиторию|репозиториев|репозиториям|' | ||
|
||
def check(self): | ||
string_result = 'Не пройдена!' | ||
text_from_slide = [slide for page, slide in enumerate(self.file.get_text_from_slides(), 1)] | ||
string_from_text = ' '.join(text_from_slide) | ||
found_repo = re.findall(self.pattern_for_repo, string_from_text) | ||
|
||
if not found_repo: | ||
return answer(True, 'Нечего проверять!') | ||
|
||
else: | ||
if self.file.found_index['Апробация'] is not None: | ||
page_aprb = self.file.found_index['Апробация'] | ||
text_from_slide_aprb = [ | ||
slide.replace(" ", '') for page, slide in enumerate(self.file.get_text_from_slides(), 1) | ||
if str(page) == page_aprb] | ||
|
||
string_from_text_aprb = ' '.join(text_from_slide_aprb) | ||
found_repo_aprb = re.findall(self.pattern_for_repo, string_from_text_aprb) | ||
found_repo_aprb_incorrect = re.findall(self.pattern_for_repo_incorrect, string_from_text_aprb) | ||
if found_repo_aprb_incorrect: | ||
string_result += f" <br> В слайде 'Апробация' вместо выражений {', '.join([repr(repo) for repo in found_repo_aprb_incorrect])}" \ | ||
f" следует привести ссылки вида 'https//github.com/...'" | ||
if not found_repo_aprb and not found_repo_aprb_incorrect and re.findall(self.pattern_repo_mention, string_from_text_aprb): | ||
string_result += f' <br> В слайде "Апробация" есть упоминания репозиториев,' \ | ||
f'однако ссылки на них либо некорректны, либо отсутствуют.' | ||
|
||
for i in found_repo: | ||
try: | ||
link = requests.get(i[0]) | ||
if link.status_code != 200: | ||
raise requests.exceptions.ConnectionError | ||
else: | ||
if self.deep_check: | ||
self.deep_check_repo(i, link) | ||
except (requests.exceptions.SSLError, requests.exceptions.ConnectionError): | ||
self.wrong_repo_ref.append(i[0]) | ||
if self.wrong_repo_ref: | ||
string_result += f" <br> Найдены несуществующие или закрытые репозитории: {', '.join([repr(repo) for repo in self.wrong_repo_ref])}" | ||
check_result = False | ||
if self.empty_repo_ref: | ||
string_result += f" <br> Найдены пустые репозитории: {', '.join([repr(repo) for repo in self.empty_repo_ref])}" | ||
check_result = False | ||
else: | ||
string_result = 'Пройдена!' | ||
check_result = True | ||
return answer(check_result, string_result) | ||
|
||
def deep_check_repo(self, repo, link): | ||
if re.findall(r'github', repo[0]): | ||
tree = html.fromstring(link.content) | ||
if not tree.xpath("//a[@class ='js-navigation-open Link--primary']"): | ||
self.empty_repo_ref.append(repo[0]) | ||
|
||
# if re.findall(r'gitlab', i[0]): | ||
# project_id = quote(i[0].replace('https://gitlab.com/', ''), safe='') | ||
# url = f'{GITLAB_URL}/projects/{project_id}?private_token={PRIVATE_TOKEN}' | ||
# response = requests.get(url) | ||
# project_info = response.json() | ||
# if project_info['visibility'] == 'private': | ||
# wrong_repo_ref.append(i[0]) |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А почему тут True?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
На данный момент проверка сделана таким образом, что отсутствие ссылок на репозитории не является недочетом. Оценивается только их корректность (если они есть).
Уточните, пожалуйста, является ли наличие ссылок на репозитории необходимым условием для прохождения именно этой проверки?