diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 815ec93..1afeac3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: # catch git merge/rebase problems - id: check-merge-conflict - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.5 + rev: v0.6.1 hooks: # lint & attempt to correct failures (e.g. pyupgrade) - id: ruff diff --git a/count_votes.py b/count_votes.py index f5c890b..8d83bbb 100644 --- a/count_votes.py +++ b/count_votes.py @@ -1,25 +1,29 @@ import sys import requests + def fetch_github_comment(comment_url): # Extract the necessary parts from the comment URL - parts = comment_url.split('/') + parts = comment_url.split("/") owner, repo = parts[3], parts[4] comment_id = comment_url.split("#issuecomment-")[-1] # Construct the API URL - api_url = f"https://api.github.com/repos/{owner}/{repo}/issues/comments/{comment_id}" + api_url = ( + f"https://api.github.com/repos/{owner}/{repo}/issues/comments/{comment_id}" + ) # Make the request to the GitHub API response = requests.get(api_url) if response.status_code == 200: - return response.json()['body'] + return response.json()["body"] else: raise Exception(f"Failed to fetch comment: {response.status_code}") + def parse_votes(text): - lines = text.split('\n') + lines = text.split("\n") yes_votes = [] no_votes = [] abstain_votes = [] @@ -30,23 +34,23 @@ def parse_votes(text): for line in lines: line = line.strip() - - if line.startswith('@'): + + if line.startswith("@"): # This line contains the voter's information if current_voter and vote_count == 0: not_voted.append(current_voter) current_voter = line vote_count = 0 - elif line.startswith('- [x]') or line.startswith('- [ ]'): + elif line.startswith("- [x]") or line.startswith("- [ ]"): # This line contains a vote if current_voter: - if '[x]' in line: + if "[x]" in line: vote_count += 1 - if 'yes' in line.lower(): + if "yes" in line.lower(): yes_votes.append(current_voter) - elif 'no' in line.lower(): + elif "no" in line.lower(): no_votes.append(current_voter) - elif 'abstain' in line.lower(): + elif "abstain" in line.lower(): abstain_votes.append(current_voter) else: # If we encounter any other type of line, check if the previous voter's vote was valid @@ -67,30 +71,43 @@ def parse_votes(text): return yes_votes, no_votes, abstain_votes, not_voted, invalid_votes + def print_results(yes_votes, no_votes, abstain_votes, not_voted, invalid_votes): - total_voters = len(yes_votes) + len(no_votes) + len(abstain_votes) + len(not_voted) + len(invalid_votes) + total_voters = ( + len(yes_votes) + + len(no_votes) + + len(abstain_votes) + + len(not_voted) + + len(invalid_votes) + ) valid_voters = len(yes_votes) + len(no_votes) + len(abstain_votes) - print(f"Total voters: {total_voters} (valid: {valid_voters} = {valid_voters / total_voters * 100:.2f}%)") - print(f"\nYes votes ({len(yes_votes)} / {len(yes_votes) / valid_voters * 100:.2f}%):") + print( + f"Total voters: {total_voters} (valid: {valid_voters} = {valid_voters / total_voters * 100:.2f}%)" + ) + print( + f"\nYes votes ({len(yes_votes)} / {len(yes_votes) / valid_voters * 100:.2f}%):" + ) for voter in yes_votes: print(f"- {voter}") - + print(f"\nNo votes ({len(no_votes)} / {len(no_votes) / valid_voters * 100:.2f}%)):") for voter in no_votes: print(f"- {voter}") - - print(f"\nAbstain votes ({len(abstain_votes)} / {len(abstain_votes) / valid_voters * 100:.2f}%):") + + print( + f"\nAbstain votes ({len(abstain_votes)} / {len(abstain_votes) / valid_voters * 100:.2f}%):" + ) for voter in abstain_votes: print(f"- {voter}") - + print(f"\nNot voted ({len(not_voted)}):") for voter in not_voted: print(f"- {voter}") - + print(f"\nInvalid votes ({len(invalid_votes)}):") for voter in invalid_votes: print(f"- {voter}") - + # print("\nGitHub handles summary:") # print("Yes:", ", ".join([vote.split()[0] for vote in yes_votes])) # print("No:", ", ".join([vote.split()[0] for vote in no_votes])) @@ -98,6 +115,7 @@ def print_results(yes_votes, no_votes, abstain_votes, not_voted, invalid_votes): # print("Not voted:", ", ".join([vote.split()[0] for vote in not_voted])) # print("Invalid votes:", ", ".join([vote.split()[0] for vote in invalid_votes])) + # Example usage comment_url = "https://github.com/conda/ceps/pull/75#issuecomment-2203197834" @@ -106,7 +124,9 @@ def print_results(yes_votes, no_votes, abstain_votes, not_voted, invalid_votes): comment_url = sys.argv[1] comment_text = fetch_github_comment(comment_url) - yes_votes, no_votes, abstain_votes, not_voted, invalid_votes = parse_votes(comment_text) + yes_votes, no_votes, abstain_votes, not_voted, invalid_votes = parse_votes( + comment_text + ) print_results(yes_votes, no_votes, abstain_votes, not_voted, invalid_votes) except Exception as e: - print(f"An error occurred: {e}") \ No newline at end of file + print(f"An error occurred: {e}") diff --git a/pixi.toml b/pixi.toml index 6a0a125..82c6ac5 100644 --- a/pixi.toml +++ b/pixi.toml @@ -1,14 +1,14 @@ +[dependencies] +python = ">=3.12.4,<3.13" +requests = ">=2.32.3,<2.33" + [project] authors = ["Wolf Vollprecht "] channels = ["conda-forge"] name = "governance" -platforms = ["osx-64", "osx-arm64", "win-64" , "linux-64"] +platforms = ["osx-64", "osx-arm64", "win-64", "linux-64"] version = "0.1.0" [tasks] -vote_markdown = "python to_vote.py" count_votes = "python count_votes.py" - -[dependencies] -python = ">=3.12.4,<3.13" -requests = ">=2.32.3,<2.33" +vote_markdown = "python to_vote.py"