Skip to content

Commit 58c6a23

Browse files
committed
Enhance GSoC PR contributor tracking and user profile linking
- Improve contributor identification by extracting GitHub URLs from PR metadata - Add fallback mechanism to link PRs to user profiles when direct profile is missing - Implement user profile update logic for PRs without existing profile associations - Add error handling and bot account filtering during profile linking process
1 parent 1fec488 commit 58c6a23

File tree

1 file changed

+57
-4
lines changed

1 file changed

+57
-4
lines changed

website/views/issue.py

+57-4
Original file line numberDiff line numberDiff line change
@@ -2037,12 +2037,29 @@ def fetch_model_prs(self, repo_names):
20372037
for pr in prs:
20382038
total_pr_count += 1
20392039

2040+
# First try to get the user profile from the PR
20402041
user_profile = pr.user_profile
2041-
if user_profile:
2042+
github_url = None
2043+
2044+
if user_profile and user_profile.github_url:
20422045
github_url = user_profile.github_url
2043-
if github_url and not github_url.endswith("[bot]") and "bot" not in github_url.lower():
2044-
contributors[github_url]["count"] += 1
2045-
contributors[github_url]["github_url"] = github_url
2046+
else:
2047+
# If no user profile, try to extract GitHub username from PR URL
2048+
# Example PR URL: https://github.com/adeyosemanputra/PyGoat/pull/123
2049+
try:
2050+
# Extract username from PR URL by parsing the URL
2051+
pr_url_parts = pr.url.split("/")
2052+
if len(pr_url_parts) >= 5 and pr_url_parts[2] == "github.com":
2053+
# Construct a GitHub profile URL
2054+
github_url = f"https://github.com/{pr_url_parts[3]}"
2055+
except (IndexError, AttributeError):
2056+
# If we can't extract the username, skip this PR
2057+
continue
2058+
2059+
# Skip bot accounts
2060+
if github_url and not github_url.endswith("[bot]") and "bot" not in github_url.lower():
2061+
contributors[github_url]["count"] += 1
2062+
contributors[github_url]["github_url"] = github_url
20462063

20472064
# Get top 10 contributors
20482065
top_contributors = sorted(contributors.items(), key=lambda item: item[1]["count"], reverse=True)[:10]
@@ -2119,6 +2136,42 @@ def refresh_gsoc_project(request):
21192136
repo_list = ",".join(repos)
21202137
call_command("fetch_gsoc_prs", repos=repo_list, days=days)
21212138

2139+
# Update user profiles for PRs that don't have them
2140+
for repo_full_name in repos:
2141+
try:
2142+
owner, repo_name = repo_full_name.split("/")
2143+
repo = Repo.objects.filter(name=repo_name).first()
2144+
2145+
if repo:
2146+
# Get PRs without user profiles
2147+
prs_without_profiles = GitHubIssue.objects.filter(
2148+
repo=repo, type="pull_request", is_merged=True, merged_at__gte=since_date, user_profile=None
2149+
)
2150+
2151+
for pr in prs_without_profiles:
2152+
try:
2153+
# Extract username from PR URL
2154+
pr_url_parts = pr.url.split("/")
2155+
if len(pr_url_parts) >= 5 and pr_url_parts[2] == "github.com":
2156+
# Get or create a user profile
2157+
github_url = f"https://github.com/{pr_url_parts[3]}"
2158+
2159+
# Skip bot accounts
2160+
if github_url.endswith("[bot]") or "bot" in github_url.lower():
2161+
continue
2162+
2163+
# Find existing user profile with this GitHub URL
2164+
user_profile = UserProfile.objects.filter(github_url=github_url).first()
2165+
2166+
if user_profile:
2167+
# Link the PR to the user profile
2168+
pr.user_profile = user_profile
2169+
pr.save()
2170+
except (IndexError, AttributeError):
2171+
continue
2172+
except Exception as e:
2173+
messages.warning(request, f"Error updating user profiles for {repo_full_name}: {str(e)}")
2174+
21222175
messages.success(
21232176
request, f"Successfully refreshed PRs for {project_name}. {len(repos)} repositories processed."
21242177
)

0 commit comments

Comments
 (0)