@@ -2037,12 +2037,29 @@ def fetch_model_prs(self, repo_names):
2037
2037
for pr in prs :
2038
2038
total_pr_count += 1
2039
2039
2040
+ # First try to get the user profile from the PR
2040
2041
user_profile = pr .user_profile
2041
- if user_profile :
2042
+ github_url = None
2043
+
2044
+ if user_profile and user_profile .github_url :
2042
2045
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
2046
2063
2047
2064
# Get top 10 contributors
2048
2065
top_contributors = sorted (contributors .items (), key = lambda item : item [1 ]["count" ], reverse = True )[:10 ]
@@ -2119,6 +2136,42 @@ def refresh_gsoc_project(request):
2119
2136
repo_list = "," .join (repos )
2120
2137
call_command ("fetch_gsoc_prs" , repos = repo_list , days = days )
2121
2138
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
+
2122
2175
messages .success (
2123
2176
request , f"Successfully refreshed PRs for { project_name } . { len (repos )} repositories processed."
2124
2177
)
0 commit comments