Skip to content

Commit

Permalink
count_reactions: Count negative reactions as well
Browse files Browse the repository at this point in the history
  • Loading branch information
iBug committed Sep 6, 2023
1 parent 6d2693f commit 3303ede
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Count Reactions

on:
push:
branches:
- master
schedule:
- cron: '0 0 * * *'
issues:
Expand All @@ -17,10 +20,10 @@ jobs:
issues: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4

- name: Install dependencies
run: |
Expand All @@ -30,5 +33,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run:
python scripts/count_reactions.py

python3 scripts/count_reactions.py
22 changes: 14 additions & 8 deletions scripts/count_reactions.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
#!/usr/bin/python3

import os
from github import Github


def count_reactions(token, repo_name):
g = Github(token)
repo = g.get_repo(repo_name)

issues = repo.get_issues(state="open", labels=["needvote"])

reactions_count = {}

for issue in issues:
reactions = issue.get_reactions()
reaction_dates = set()
up_dates, down_dates = set(), set()
for reaction in reactions:
date = reaction.created_at.date()
if reaction.content == "+1":
reaction_dates.add(reaction.created_at.date())
reactions_count[issue.number] = len(reaction_dates)
up_dates.add(date)
elif reaction.content == "-1":
down_dates.add(date)
reactions_count[issue.number] = (len(up_dates), len(down_dates))

sorted_reactions_count = dict(sorted(reactions_count.items(), key=lambda item: item[1], reverse=True))
sorted_reactions_count = sorted(reactions_count.items(), key=lambda item: (item[1][0] - item[1][1], item[0]), reverse=True)

table = "* Votes:\n | Title| Priority |\n | --- | --- |\n"
for issue_number, count in sorted_reactions_count.items():
table += f" | #{issue_number} | {count} |\n"
table = "## Votes\n\n| Title| Priority | Score |\n| --- | --- | --- |\n"
for issue_number, (up_count, down_count) in sorted_reactions_count:
score = up_count - down_count
table += f"| #{issue_number} | {score} | +{up_count}, -{down_count} |\n"

repo.get_issue(366).edit(body=table)

Expand Down

0 comments on commit 3303ede

Please sign in to comment.