Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions website/views/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,6 @@ def github_issues_with_bounties(self, label, issue_state="open", page=1, per_pag

for issue in issues:
related_prs = []

# Only include issues, not PRs in the response
if issue.get("pull_request") is None:
formatted_issue = {
"id": issue.get("id"),
Expand Down Expand Up @@ -2729,7 +2727,6 @@ def github_issues_with_bounties(self, label="$5", issue_state="closed", page=1,
encoded_label = label.replace("$", "%24")
query_params = f"repo:OWASP-BLT/BLT+is:issue+state:{issue_state}+label:{encoded_label}"
url = f"https://api.github.com/search/issues?q={query_params}&page={page}&per_page={per_page}"

headers = {}
if settings.GITHUB_TOKEN:
headers["Authorization"] = f"token {settings.GITHUB_TOKEN}"
Expand All @@ -2739,18 +2736,18 @@ def github_issues_with_bounties(self, label="$5", issue_state="closed", page=1,
if response.status_code == 200:
data = response.json()
issues = data.get("items", [])

total_count = data.get("total_count", 0)
# Cache the results for 30 minutes
cache.set(cache_key, issues, 60 * 30)

return issues
return issues, total_count
else:
# Log the error response from GitHub
logger.error(f"GitHub API error: {response.status_code} - {response.text[:200]}")
return []
return [], 0
except Exception as e:
logger.error(f"Error fetching GitHub issues: {str(e)}")
return []
return [], 0

def post(self, request, *args, **kwargs):
"""Handle POST requests for refreshing issues or processing payments"""
Expand All @@ -2770,7 +2767,23 @@ def post(self, request, *args, **kwargs):
# Import required models
from website.models import GitHubIssue, Repo

issues = self.github_issues_with_bounties("$5", "closed", per_page=100)
page = 1
per_page = 100
all_issues = []
total_count = None
while True:
issues, api_total_count = self.github_issues_with_bounties("$5", "closed", page, per_page)
if total_count is None and api_total_count is not None:
total_count = api_total_count
if not issues:
break
all_issues.extend(issues)
if len(issues) < per_page or len(all_issues) >= total_count:
break
page += 1

issues = all_issues
count = 0
count = 0

for issue_data in issues:
Expand Down