-
-
Notifications
You must be signed in to change notification settings - Fork 288
Changed the logic of fetching leader's data #990
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
Merged
arkid15r
merged 9 commits into
OWASP:main
from
samyak003:feature/changeLeaderFetchLogic
Mar 13, 2025
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
198f9e3
Changed the logic of fetching leader's data
samyak003 584c1d1
Moved logic to RepositoryBasedEntityModel
samyak003 3c0adbe
Merge branch 'main' into feature/changeLeaderFetchLogic
kasya 6661ccd
Merge branch 'main' into feature/changeLeaderFetchLogic
arkid15r 1f23fe5
Merge branch 'OWASP:main' into feature/changeLeaderFetchLogic
samyak003 9c1b4c9
Merge branch 'OWASP:main' into feature/changeLeaderFetchLogic
samyak003 b8b47a0
Moved leader's data logic
samyak003 2e5d487
Merge branch 'main' into pr/samyak003/990
arkid15r 4dc1062
Update code
arkid15r 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| import re | ||
| from urllib.parse import urlparse | ||
|
|
||
| import requests | ||
| import yaml | ||
| from django.db import models | ||
| from django.db.models import Sum | ||
|
|
@@ -146,6 +147,39 @@ def get_top_contributors(self, repositories=()): | |
| .order_by("-total_contributions")[:TOP_CONTRIBUTORS_LIMIT] | ||
| ] | ||
|
|
||
| def get_leaders(self, repository): | ||
|
||
| """Get leaders from leaders.md file on GitHub.""" | ||
| try: | ||
| content = get_repository_file_content( | ||
| f"https://raw.githubusercontent.com/OWASP/{repository.key}/{repository.default_branch}/leaders.md" | ||
| ) | ||
| except (requests.exceptions.RequestException, ValueError) as e: | ||
| logger.exception( | ||
| "Failed to fetch leaders.md file", | ||
| extra={"repository": repository.name, "error": str(e)}, | ||
| ) | ||
| return [] | ||
| leaders = [] | ||
| try: | ||
| if not content: | ||
| logger.warning("Empty leaders.md content", extra={"repository": repository.name}) | ||
| return leaders | ||
| lines = content.split("\n") | ||
| logger.debug("Content length: %d characters", len(content)) | ||
| small_size = 500 | ||
| if len(content) < small_size: # Only log full content if it's reasonably small | ||
| logger.debug("Content: %s", content) | ||
| for line in lines: | ||
| logger.debug("Processing line: %s", line) | ||
| # Match both standard Markdown list items with links and variations | ||
| match = re.findall(r"\*\s*\[([^\]]+)\](?:\([^)]*\))?", line) | ||
| leaders.extend(match) | ||
| except AttributeError: | ||
| logger.exception( | ||
| "Unable to parse leaders.md content", extra={"repository": repository.name} | ||
| ) | ||
| return leaders | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| class GenericEntityModel(models.Model): | ||
| """Generic entity model.""" | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -108,16 +108,6 @@ def test_initialization_not_found(self, mock_session): | |
|
|
||
| assert scraper.page_tree is None | ||
|
|
||
| def test_get_leaders_no_leaders(self, mock_session): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this test needs to be refactored too based on the new logic and the code location. |
||
| invalid_html = b"<div class='sidebar'><div id='leaders'></div></div>" | ||
| mock_response = Mock() | ||
| mock_response.content = invalid_html | ||
| mock_session.get.return_value = mock_response | ||
|
|
||
| scraper = OwaspScraper("https://test.org") | ||
|
|
||
| assert scraper.get_leaders() == [] | ||
|
|
||
| def test_verify_url_invalid_url(self, mock_session): | ||
| response = Mock() | ||
| response.status_code = codes.ok | ||
|
|
||
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.
For all entities it's no longer a part of scraping process. It's now within GitHub processing part. We need to structure it properly.