Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#161)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.5.5 → v0.6.1](astral-sh/ruff-pre-commit@v0.5.5...v0.6.1)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
pre-commit-ci[bot] authored Aug 20, 2024
1 parent 088ac63 commit 1f558b5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 42 additions & 22 deletions count_votes.py
Original file line number Diff line number Diff line change
@@ -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 = []
Expand All @@ -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
Expand All @@ -67,37 +71,51 @@ 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]))
# print("Abstain:", ", ".join([vote.split()[0] for vote in abstain_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"

Expand All @@ -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}")
print(f"An error occurred: {e}")
12 changes: 6 additions & 6 deletions pixi.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[dependencies]
python = ">=3.12.4,<3.13"
requests = ">=2.32.3,<2.33"

[project]
authors = ["Wolf Vollprecht <w.vollprecht@gmail.com>"]
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"

0 comments on commit 1f558b5

Please sign in to comment.