Example #1
0
def handle_delete_branch(irc: IrcConnection, data: Dict[str, Any]) -> None:
    author = irccolors.colorize(data["pusher"]["name"], "bold")
    action = irccolors.colorize("deleted", "red")

    branch = get_branch_name_from_push_event(data)
    branch = irccolors.colorize(branch, "bold-blue")

    irc.schedule_message("{} {} {} {}".format(fmt_repo(data), author, action,
                                              branch))
Example #2
0
def handle_pull_request(irc: IrcConnection, data: Dict[str, Any]) -> None:
    repo = fmt_repo(data)
    author = irccolors.colorize(data["sender"]["login"], "bold")
    if not data["action"] in config.GH_PR_ENABLED_EVENTS:
        return

    action = fmt_pr_action(data["action"], data["pull_request"]["merged"])
    pr_num = irccolors.colorize("#" + str(data["number"]), "bold-blue")
    title = data["pull_request"]["title"]
    link = short_gh_link(data["pull_request"]["html_url"])

    irc.schedule_message("{} {} {} pull request {}: {} ({})".format(
        repo, author, action, pr_num, title, link))
Example #3
0
def handle_issue(irc: IrcConnection, data: Dict[str, Any]) -> None:
    repo = fmt_repo(data)
    user = irccolors.colorize(data["sender"]["login"], "bold")

    action = data["action"]
    if not action in ["opened", "closed"]:
        return
    action_color = "red" if action == "opened" else "green"
    action = irccolors.colorize(action, action_color)

    issue_num = irccolors.colorize("#" + str(data["issue"]["number"]),
                                   "bold-blue")
    title = data["issue"]["title"]
    link = short_gh_link(data["issue"]["html_url"])

    irc.schedule_message("{} {} {} issue {}: {} ({})".format(
        repo, user, action, issue_num, title, link))
Example #4
0
def handle_forward_push(irc: IrcConnection, data: Dict[str, Any]) -> None:
    author = irccolors.colorize(data["pusher"]["name"], "bold")

    num_commits = len(data["commits"])
    num_commits_str = str(num_commits) + " commit" + ("s" if num_commits > 1
                                                      else "")

    num_commits_str = irccolors.colorize(num_commits_str, "bold-teal")

    branch = get_branch_name_from_push_event(data)
    branch = irccolors.colorize(branch, "bold-blue")

    irc.schedule_message("{} {} pushed {} to {} ({}):".format(
        fmt_repo(data), author, num_commits, branch,
        short_gh_link(data["compare"])))

    commits = fmt_last_commits(data)
    for commit in commits:
        irc.schedule_message(commit)

    print("Push event")
Example #5
0
def handle_force_push(irc: IrcConnection, data: Dict[str, Any]) -> None:
    author = irccolors.colorize(data["pusher"]["name"], "bold")

    before = irccolors.colorize(data["before"][:10], "bold-red")
    after = irccolors.colorize(data["after"][:10], "bold-red")

    branch = get_branch_name_from_push_event(data)
    branch = irccolors.colorize(branch, "bold-blue")

    irc.schedule_message("{} {} force-pushed {} from {} to {} ({}):".format(
        fmt_repo(data),
        author,
        branch,
        before,
        after,
        short_gh_link(data["compare"]),
    ))

    commits = fmt_last_commits(data)
    for commit in commits:
        irc.schedule_message(commit)

    print("Force push event")
Example #6
0
        self.wfile.write(bytes("OK", "utf-8"))

        if irc is not None:
            events.handle_event(irc, event_type, json.loads(data))


# Just run IRC connection event loop
def worker() -> None:
    if irc is not None:
        irc.loop()


irc = IrcConnection(
    server=config.IRC_SERVER,
    channel=config.IRC_CHANNEL,
    nick=config.IRC_NICK,
    passw=config.IRC_PASS,
    port=config.IRC_PORT,
)

t = threading.Thread(target=worker)
t.start()

# Run Github webhook handling server
try:
    server = HTTPServer((config.SERVER_HOST, config.SERVER_PORT), MyHandler)
    server.serve_forever()
except KeyboardInterrupt:
    print("Exiting")
    server.socket.close()
    irc.stop_loop()
Example #7
0
def run():
    channel_list = CHANNELS.lower().split(',')
    irc_conn = IrcConnection(TOKEN, channel_list)
    irc_conn.connect()
Example #8
0
        data = self.rfile.read(content_len)

        self.send_response(200)
        self.send_header('content-type', 'text/html')
        self.end_headers()
        self.wfile.write(bytes('OK', 'utf-8'))

        events.handle_event(irc, event_type, json.loads(data.decode()))
        return


def worker():
    irc.loop()


irc = IrcConnection('config.ini')

t = threading.Thread(target=worker)
t.start()

if irc.widelands['webhook']['start']:
    # Run Github webhook handling server
    try:
        server = HTTPServer((irc.widelands['webhook']['host'],
                             irc.widelands['webhook']['port']), MyHandler)
        server.serve_forever()
    except KeyboardInterrupt:
        print("Exiting")
        server.socket.close()
        irc.stop_loop()