-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] brainstorming for /vote fast + prototype [WILL NOT BE UN-WIP-ED] #493
Changes from 5 commits
dd4c8bf
fd3f872
48e9fd1
a7b0e27
accf700
6cde8da
eef11e0
8b3c316
965ac7d
9872097
95659ee
20c7c08
c655b91
f5c39db
e520f3f
740a780
1c65501
c7933a5
d48f779
d147db4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
import os | ||
import sys | ||
from os.path import join, abspath, dirname | ||
from lib.db.models import MeritocracyMentioned | ||
from lib.db.models import MeritocracyMentioned, Issue | ||
|
||
import settings | ||
import github_api as gh | ||
|
@@ -73,6 +73,16 @@ def poll_pull_requests(api): | |
# the PR is mitigated or the threshold is not reached ? | ||
if variance >= threshold or not is_approved: | ||
voting_window = gh.voting.get_extended_voting_window(api, settings.URN) | ||
|
||
# read the db to see if this PR is expedited by /vote fast... | ||
try: | ||
issue = Issue.get(issue_id=pr["id"]) | ||
if issue.expedited: # expedite | ||
voting_window /= 2 | ||
|
||
except Issue.DoesNotExist: | ||
pass # not expedited | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, add an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @PlasmaPower This is not necessarily a failure, though... It just means nobody has posted There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure you understand. I'm saying keep the current error handler, but add another general one in case a different exception happens. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, my bad... fixed |
||
|
||
if (settings.IN_PRODUCTION and vote_total >= threshold / 2 and | ||
seconds_since_updated > base_voting_window and not meritocracy_satisfied): | ||
# check if we need to mention the meritocracy | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
|
||
# If no subcommands, map cmd: None | ||
COMMAND_LIST = { | ||
"/vote": ("close", "reopen") | ||
"/vote": ("close", "reopen", "fast") | ||
} | ||
|
||
__log = logging.getLogger("read_issue_comments") | ||
|
@@ -38,9 +38,12 @@ def get_seconds_remaining(api, comment_id): | |
def insert_or_update(api, cmd_obj): | ||
# Find the comment, or create it if it doesn't exit | ||
comment_id = cmd_obj["global_comment_id"] | ||
issue, _ = Issue.get_or_create(issue_id=cmd_obj["issue_id"]) | ||
user, _ = User.get_or_create(login=cmd_obj["user"]["login"], | ||
user_id=cmd_obj["user"]["id"]) | ||
issue, _ = Issue.get_or_create(issue_id=cmd_obj["issue_id"], | ||
user=user, # TODO: I don't think this is the right one | ||
created_at=cmd_obj["created_at"], # TODO: I don't think this is the right one | ||
expedited=False) | ||
|
||
comment, _ = Comment.get_or_create(comment_id=comment_id, | ||
user=user, text=cmd_obj["comment_text"], | ||
|
@@ -131,7 +134,10 @@ def get_command_votes(api, urn, comment_id): | |
return votes | ||
|
||
|
||
def handle_vote_command(api, command, issue_id, comment_id, votes): | ||
def handle_vote_command(api, command, cmdmeta, votes): | ||
issue_id = cmdmeta.issue.issue_id | ||
comment_id = cmdmeta.comment.comment_id | ||
|
||
orig_command = command[:] | ||
# Check for correct command syntax, ie, subcommands | ||
log_warning = False | ||
|
@@ -143,6 +149,33 @@ def handle_vote_command(api, command, issue_id, comment_id, votes): | |
elif sub_command == "reopen": | ||
gh.issues.open_issue(api, settings.URN, issue_id) | ||
gh.comments.leave_issue_reopened_comment(api, settings.URN, issue_id) | ||
elif sub_command == "fast": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe pull this out into it's own function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
comment_updated_at = cmdmeta.comment.updated_at | ||
comment_created_at = cmdmeta.comment.created_at | ||
comment_poster = cmdmeta.comment.user | ||
issue_poster = cmdmeta.issue.user | ||
issue_created_at = cmdmeta.issue.created_at | ||
|
||
# The post should not have been updated | ||
if updated_at != created_at: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe leave some kind of response indicating why the command didn't run? Makes debugging easier There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... yes, I see your point... but would this be prone to inducing spam? |
||
return | ||
|
||
# The comment poster must be in the meritocracy | ||
meritocracy = {} | ||
with open('server/meritocracy.json', 'r') as mfp: | ||
fs = fp.read() | ||
if fs: | ||
meritocracy = json.loads(fs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems a bit flaky. How about defining a function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @md678685 What should I do instead? Would it be ok to define There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it would need re-implemented when the DB is ready. Sure, the DB could be used, but there's no point in that since this code and the main loop (PRs) run in the same process (so they share the same memoization cache). |
||
|
||
if comment_poster not in meritocracy: | ||
return | ||
|
||
# The comment must posted within 5 min of the issue | ||
if (arrow.get(comment_created) - arrow.get(issue_created_at)).total_seconds() > 5*60: | ||
return | ||
|
||
# Leave a note on the issue that it is expedited | ||
Issue.update(expedited=True).where(Issue.issue_id == cmdmeta.issue.issue_id).execute() | ||
else: | ||
# Implement other commands | ||
pass | ||
|
@@ -174,7 +207,7 @@ def handle_comment(api, cmd): | |
comment=comment_text)) | ||
|
||
if command == "/vote": | ||
handle_vote_command(api, parsed_comment, issue_id, comment_id, votes) | ||
handle_vote_command(api, parsed_comment, cmd, votes) | ||
|
||
update_command_ran(api, comment_id, "Command Ran") | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code needs to be moved out of the if statement for the extended voting window. Currently this just halves the extended voting window.