Add support for GH pull requests
This commit is contained in:
parent
e4f5c141ae
commit
301ec5c8f7
2 changed files with 100 additions and 0 deletions
16
logbot.py
16
logbot.py
|
@ -51,8 +51,11 @@ except:
|
||||||
|
|
||||||
from ircbot import SingleServerIRCBot
|
from ircbot import SingleServerIRCBot
|
||||||
from irclib import nm_to_n
|
from irclib import nm_to_n
|
||||||
|
import time
|
||||||
|
from threading import Timer
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
from pullrequest import PullRequest
|
||||||
|
|
||||||
pat1 = re.compile(r"(^|[\n ])(([\w]+?://[\w\#$%&~.\-;:=,?@\[\]+]*)(/[\w\#$%&~/.\-;:=,?@\[\]+]*)?)", re.IGNORECASE | re.DOTALL)
|
pat1 = re.compile(r"(^|[\n ])(([\w]+?://[\w\#$%&~.\-;:=,?@\[\]+]*)(/[\w\#$%&~/.\-;:=,?@\[\]+]*)?)", re.IGNORECASE | re.DOTALL)
|
||||||
|
|
||||||
|
@ -370,6 +373,16 @@ class Logbot(SingleServerIRCBot):
|
||||||
msg = msg.replace("%time%", time)
|
msg = msg.replace("%time%", time)
|
||||||
append_line(log_path, msg)
|
append_line(log_path, msg)
|
||||||
|
|
||||||
|
def check_for_prs(self, c):
|
||||||
|
p = PullRequest()
|
||||||
|
for line in p.check_all():
|
||||||
|
message = line["message"]
|
||||||
|
channel = line["channel"]
|
||||||
|
c.privmsg(channel, message)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
Timer(60*5, self.check_for_prs, [c]).start()
|
||||||
|
|
||||||
### These are the IRC events
|
### These are the IRC events
|
||||||
|
|
||||||
def on_all_raw_messages(self, c, e):
|
def on_all_raw_messages(self, c, e):
|
||||||
|
@ -384,6 +397,9 @@ class Logbot(SingleServerIRCBot):
|
||||||
for chan in self.chans:
|
for chan in self.chans:
|
||||||
c.join(chan)
|
c.join(chan)
|
||||||
|
|
||||||
|
self.check_for_prs(c)
|
||||||
|
|
||||||
|
|
||||||
def on_nicknameinuse(self, c, e):
|
def on_nicknameinuse(self, c, e):
|
||||||
"""Nickname in use"""
|
"""Nickname in use"""
|
||||||
c.nick(c.get_nickname() + "_")
|
c.nick(c.get_nickname() + "_")
|
||||||
|
|
84
pullrequest.py
Normal file
84
pullrequest.py
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
import requests
|
||||||
|
|
||||||
|
class PullRequest:
|
||||||
|
seen_prs_file = "seen_prs"
|
||||||
|
|
||||||
|
repos = [
|
||||||
|
{
|
||||||
|
"channel": "#pelux",
|
||||||
|
"name": "meta-bistro",
|
||||||
|
"uri": "https://api.github.com/repos/pelagicore/meta-bistro/pulls"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"channel": "#pelux",
|
||||||
|
"name": "meta-pelux",
|
||||||
|
"uri": "https://api.github.com/repos/pelagicore/meta-pelux/pulls"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"channel": "#pelux",
|
||||||
|
"name": "meta-bistro",
|
||||||
|
"uri": "https://api.github.com/repos/pelagicore/meta-bistro/pulls"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"channel": "#pelux",
|
||||||
|
"name": "meta-pelux-bsp-intel",
|
||||||
|
"uri": "https://api.github.com/repos/pelagicore/meta-pelux-bsp-intel/pulls"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"channel": "#pelux",
|
||||||
|
"name": "meta-pelux-bsp-rpi",
|
||||||
|
"uri": "https://api.github.com/repos/pelagicore/meta-pelux-bsp-rpi/pulls"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"channel": "#pelux",
|
||||||
|
"name": "pelux-manifests",
|
||||||
|
"uri": "https://api.github.com/repos/pelagicore/pelux-manifests/pulls"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"channel": "#pelux",
|
||||||
|
"name": "software-factory",
|
||||||
|
"uri": "https://api.github.com/repos/pelagicore/software-factory/pulls"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
def has_seen_before(self, obj):
|
||||||
|
try:
|
||||||
|
with open(self.seen_prs_file, "r") as f:
|
||||||
|
for line in f.readlines():
|
||||||
|
if line.strip() == obj["merge_commit_sha"]:
|
||||||
|
return True
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
def mark_pr_as_seen(self, obj):
|
||||||
|
with open(self.seen_prs_file, "a") as f:
|
||||||
|
f.write(obj["merge_commit_sha"] + "\n")
|
||||||
|
|
||||||
|
|
||||||
|
def prettyprint(self, repo_name, obj):
|
||||||
|
return "New PR in " + repo_name \
|
||||||
|
+ ": '" + obj["title"] \
|
||||||
|
+ "' by " \
|
||||||
|
+ obj["user"]["login"]
|
||||||
|
|
||||||
|
def check_all(self):
|
||||||
|
for repo in self.repos:
|
||||||
|
r = requests.get(repo["uri"])
|
||||||
|
if r.status_code != 200:
|
||||||
|
print "Error fetching %s", repo["name"]
|
||||||
|
break
|
||||||
|
|
||||||
|
prs = r.json()
|
||||||
|
for pr in prs:
|
||||||
|
if not self.has_seen_before(pr):
|
||||||
|
self.mark_pr_as_seen(pr)
|
||||||
|
yield {"channel": repo["channel"],
|
||||||
|
"message": self.prettyprint(repo["name"], pr)}
|
||||||
|
|
||||||
|
# Test
|
||||||
|
if __name__ == "__main__":
|
||||||
|
p = PullRequest()
|
||||||
|
for line in p.check_all():
|
||||||
|
print line["message"]
|
Loading…
Add table
Add a link
Reference in a new issue