Skip to content

Commit f9c79ba

Browse files
committed
Refactor total commits calculation in generate_images.py to use a variable for improved readability. Initialize stargazers and forks in github_stats.py to ensure accurate statistics collection. Update comments for clarity.
1 parent ca6c085 commit f9c79ba

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

generate_images.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ async def generate_overview(s: Stats) -> None:
4141
output = re.sub("{{ contributions }}", f"{await s.total_contributions:,}", output)
4242
output = re.sub("{{ views }}", f"{await s.views:,}", output)
4343
output = re.sub("{{ repos }}", f"{len(await s.repos):,}", output)
44-
output = re.sub("{{ commits }}", f"{await s.total_commits:,}", output)
44+
commits = await s.total_commits()
45+
output = re.sub("{{ commits }}", f"{commits:,}", output)
4546
output = re.sub("{{ prs }}", f"{await s.prs:,}", output)
4647
output = re.sub("{{ issues }}", f"{await s.issues:,}", output)
4748

github_stats.py

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ async def get_stats(self) -> None:
388388
"""
389389
Get lots of summary statistics using one big query. Sets many attributes
390390
"""
391-
# Não inicializar stargazers e forks aqui, pois usaremos get_summary_stats
391+
self._stargazers = 0
392+
self._forks = 0
392393
self._languages = dict()
393394
self._repos = set()
394395

@@ -443,7 +444,8 @@ async def get_stats(self) -> None:
443444
self._repos.add(name)
444445
processed_repos += 1
445446

446-
# Não contar stars e forks aqui - usamos get_summary_stats para isso
447+
self._stargazers += repo.get("stargazers", {}).get("totalCount", 0)
448+
self._forks += repo.get("forkCount", 0)
447449

448450
for lang in repo.get("languages", {}).get("edges", []):
449451
lang_name = lang.get("node", {}).get("name", "Other")
@@ -672,13 +674,42 @@ async def views(self) -> int:
672674
@property
673675
async def total_commits(self) -> int:
674676
"""
675-
Get the total number of commits made by the user from all years.
677+
Get the total number of commits made by the user (igual ao script original).
676678
"""
677-
# Sempre recalcular se for None para garantir contagem de todos os anos
678-
if self._total_commits is None:
679-
await self.get_all_time_commits()
680-
assert self._total_commits is not None
681-
return self._total_commits
679+
total_commits = 0
680+
if self._emails:
681+
for email in self._emails:
682+
query = f'''
683+
query {{
684+
user(login: "{self.username}") {{
685+
contributionsCollection {{
686+
totalCommitContributions
687+
}}
688+
}}
689+
}}
690+
'''
691+
response = await self.queries.query(query)
692+
if 'data' in response and 'user' in response['data']:
693+
total_commit = response['data']['user']['contributionsCollection']['totalCommitContributions']
694+
total_commits += total_commit
695+
else:
696+
print(f"Erro ao buscar commits para email {email}: {response}")
697+
else:
698+
query = f'''
699+
query {{
700+
user(login: "{self.username}") {{
701+
contributionsCollection {{
702+
totalCommitContributions
703+
}}
704+
}}
705+
}}
706+
'''
707+
response = await self.queries.query(query)
708+
if 'data' in response and 'user' in response['data']:
709+
total_commits = response['data']['user']['contributionsCollection']['totalCommitContributions']
710+
else:
711+
print(f"Erro ao buscar commits para username {self.username}: {response}")
712+
return total_commits
682713

683714
@property
684715
async def prs(self) -> int:

0 commit comments

Comments
 (0)