Skip to content

Commit

Permalink
merging PR Chaosthebot#497: Implementing the DB stuff
Browse files Browse the repository at this point in the history
Chaosthebot#497: Implementing the DB stuff

Description:
This introduces the database into chaosbot. Currently on my fork, the issue commands and meritocracy tables are implemented and working, and those are provided with this PR.

The API for the database ORM is pretty simple. See [here](http://docs.peewee-orm.com/en/latest/peewee/quickstart.html) for a quickstart to doing various operations.

Hope you all enjoy! This took a surprising amount of work to get implemented.

:white_check_mark: PR passed with a vote of 11 for and 1 against, a weighted total of 10.0 and a threshold of 6.5, and a current meritocracy review.

Vote record:
@Leigende: 1
@PlasmaPower: 1
@Swizz: 1
@andrewda: 1
@anythingbot: -1
@e-beach: 1
@ike709: 1
@JustynC7: 1
@mark-i-m: 1
@md678685: 1
@rhengles: 1
@rudehn: 1
  • Loading branch information
rudehn authored and chaosbot committed Jun 5, 2017
1 parent a936b7a commit a42223e
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 378 deletions.
1 change: 1 addition & 0 deletions chaos.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def main():

logging.getLogger("requests").propagate = False
logging.getLogger("sh").propagate = False
logging.getLogger("peewee").propagate = False

log = logging.getLogger("chaosbot")

Expand Down
21 changes: 4 additions & 17 deletions cron/poll_pull_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import sys
from os.path import join, abspath, dirname
from lib.db import DB
from lib.db.models import MeritocracyMentioned

import settings
import github_api as gh
Expand All @@ -16,18 +16,6 @@
def poll_pull_requests(api):
__log.info("looking for PRs")

db = DB.get_instance()

try:
db.query("""
CREATE TABLE IF NOT EXISTS meritocracy_mentioned (
id INTEGER PRIMARY KEY,
commit_hash VARCHAR(40)
)
""")
except:
__log.exception("Failed to create meritocracy mentioned DB table")

# get voting window
base_voting_window = gh.voting.get_initial_voting_window()

Expand Down Expand Up @@ -90,12 +78,11 @@ def poll_pull_requests(api):
# check if we need to mention the meritocracy
try:
commit = pr["head"]["sha"]
if not db.query("SELECT * FROM meritocracy_mentioned WHERE commit_hash=?",
(commit,)):

mm, created = MeritocracyMentioned.get_or_create(commit_hash=commit)
if created:
meritocracy_mentions = meritocracy - {pr["user"]["login"].lower(),
"chaosbot"}
db.query("INSERT INTO meritocracy_mentioned (commit_hash) VALUES (?)",
(commit,))
gh.comments.leave_meritocracy_comment(api, settings.URN, pr["number"],
meritocracy_mentions)
except:
Expand Down
Loading

0 comments on commit a42223e

Please sign in to comment.