示例#1
0
文件: github.py 项目: dellis23/harold
    def dispatch_pullrequest(self, parsed):
        yield self.database.process_pullrequest(
            parsed["pull_request"], parsed["repository"]["full_name"])

        if parsed["action"] != "opened":
            return

        repository_name = parsed["repository"]["full_name"]
        repository = self.config.repositories_by_name[repository_name]

        html_link = parsed["pull_request"]["_links"]["html"]["href"]
        short_url = yield self.shortener.make_short_url(html_link)
        submitter = self.config.nick_by_user(parsed["sender"]["login"])
        message = ("%(user)s opened pull request #%(id)d (%(short_url)s) "
                   "on %(repo)s: %(title)s")
        self.bot.send_message(
            repository.channel, message % dict(
                user=dehilight(submitter),
                id=parsed["number"],
                short_url=short_url,
                repo=repository_name,
                title=parsed["pull_request"]["title"][:72],
            ))

        reviewers = _extract_reviewers(parsed["pull_request"]["body"])
        reviewers = map(self.config.nick_by_user, reviewers)
        if reviewers:
            self.bot.send_message(
                repository.channel, "%(reviewers)s: %(user)s has requested "
                "your review of ^" % {
                    "reviewers": ", ".join(reviewers),
                    "user": dehilight(submitter),
                })
示例#2
0
    def dispatch_pullrequest(self, parsed):
        pull_request = parsed["pull_request"]
        timestamp = _parse_timestamp(pull_request["created_at"])
        repository_name = parsed["repository"]["full_name"]
        repository = self.config.repositories_by_name[repository_name]
        pull_request_id = parsed["number"]
        sender = self.config.nick_by_user(parsed["sender"]["login"])

        yield self.database.process_pullrequest(pull_request, repository_name)

        html_link = pull_request["_links"]["html"]["href"]
        short_url = yield self.shortener.make_short_url(html_link)

        if parsed["action"] == "review_requested":
            username = parsed["requested_reviewer"]["login"]
            yield self.database.add_review_request(
                repo=repository_name,
                pull_request_id=pull_request_id,
                username=username,
                timestamp=timestamp,
            )

            message = self.messages_by_emoji[":eyeglasses:"]
            self.bot.send_message(repository.channel, message % {
                "reviewers": self.config.nick_by_user(username),
                "user": dehilight(sender),
                "repo": repository_name,
                "id": pull_request_id,
                "short_url": short_url,
            })
        elif parsed["action"] == "review_request_removed":
            username = parsed["requested_reviewer"]["login"]
            yield self.database.remove_review_request(
                repo=repository_name,
                pull_request_id=pull_request_id,
                username=username,
            )
        elif parsed["action"] == "opened":
            message = ("%(user)s opened pull request #%(id)d (%(short_url)s) "
                       "on %(repo)s: %(title)s")
            self.bot.send_message(repository.channel, message % dict(
                user=dehilight(sender),
                id=pull_request_id,
                short_url=short_url,
                repo=repository_name,
                title=pull_request["title"][:72],
            ))

            reviewers = _extract_reviewers(pull_request["body"])
            reviewers = map(self.config.nick_by_user, reviewers)
            if reviewers:
                self.bot.send_message(repository.channel,
                                      "%(reviewers)s: %(user)s has requested "
                                      "your review of ^" % {
                                          "reviewers": ", ".join(reviewers),
                                          "user": dehilight(sender),
                                      })
示例#3
0
    def dispatch_comment(self, parsed):
        if parsed["action"] != "created":
            return

        body = parsed["comment"]["body"]
        emoji, message = self.find_emoji(body)
        if not emoji:
            return

        repository_name = parsed["repository"]["full_name"]
        repository = yield self.salons.get_repository(repository_name)
        html_link = parsed["issue"]["pull_request"]["html_url"]
        short_url = yield self.shortener.make_short_url(html_link)
        pr_id = int(parsed["issue"]["number"])
        timestamp = _parse_timestamp(parsed["comment"]["created_at"])

        yield self.database.update_review_state(repository_name, pr_id,
                                                parsed["comment"]["body"],
                                                timestamp,
                                                parsed["sender"]["login"],
                                                emoji)

        owner = yield self.salons.get_nick_for_user(
            parsed["issue"]["user"]["login"])
        user = yield self.salons.get_nick_for_user(parsed["sender"]["login"])
        message_info = dict(
            user=dehilight(user),
            owner=owner,
            owner_de=dehilight(owner),
            id=str(pr_id),
            short_url=short_url,
            repo=repository_name,
        )

        if "%(reviewers)s" in message:
            if emoji == ":eyeglasses:":
                reviewers = _extract_reviewers(body)
                if not reviewers:
                    return
            else:
                reviewers = yield self.database.get_reviewers(
                    repository_name, pr_id)

            mapped_reviewers = []
            for reviewer_username in reviewers:
                nick = yield self.salons.get_nick_for_user(reviewer_username)
                mapped_reviewers.append(nick)
            message_info["reviewers"] = " & ".join(
                mapped_reviewers or ["(no one in particular)"])

        if repository:
            self.bot.send_message(repository.channel, message % message_info)
示例#4
0
    def dispatch_review(self, parsed):
        if parsed["action"] != "submitted":
            return

        repository_name = parsed["repository"]["full_name"]
        repository = yield self.salons.get_repository(repository_name)
        html_link = parsed["pull_request"]["html_url"]
        short_url = yield self.shortener.make_short_url(html_link)
        pr_id = int(parsed["pull_request"]["number"])
        timestamp = _parse_timestamp(parsed["review"]["submitted_at"])

        emoji_by_state = {
            "approved": ":fish:",
            "changes_requested": ":nail_care:",
        }
        emoji = emoji_by_state.get(parsed["review"]["state"])
        if not emoji:
            return
        message = self.messages_by_emoji[emoji]

        yield self.database.update_review_state(repository_name, pr_id,
                                                parsed["review"]["body"],
                                                timestamp,
                                                parsed["sender"]["login"],
                                                emoji)

        owner = yield self.salons.get_nick_for_user(
            parsed["pull_request"]["user"]["login"])
        user = yield self.salons.get_nick_for_user(parsed["sender"]["login"])
        message_info = dict(
            user=dehilight(user),
            owner=owner,
            owner_de=dehilight(owner),
            id=str(pr_id),
            short_url=short_url,
            repo=repository_name,
        )

        if "%(reviewers)s" in message:
            reviewers = yield self.database.get_reviewers(
                repository_name, pr_id)
            mapped_reviewers = []
            for reviewer_username in reviewers:
                nick = yield self.salons.get_nick_for_user(reviewer_username)
                mapped_reviewers.append(nick)
            message_info["reviewers"] = " & ".join(
                mapped_reviewers or ["(no one in particular)"])

        if repository:
            self.bot.send_message(repository.channel, message % message_info)
示例#5
0
文件: github.py 项目: spladug/harold
    def dispatch_comment(self, parsed):
        if parsed["action"] != "created":
            return

        body = parsed["comment"]["body"]
        emoji, message = self.find_emoji(body)
        if not emoji:
            return

        repository_name = parsed["repository"]["full_name"]
        repository = yield self.salons.get_repository(repository_name)
        html_link = parsed["issue"]["pull_request"]["html_url"]
        short_url = yield self.shortener.make_short_url(html_link)
        pr_id = int(parsed["issue"]["number"])
        timestamp = _parse_timestamp(parsed["comment"]["created_at"])

        yield self.database.update_review_state(
            repository_name, pr_id, parsed["comment"]["body"],
            timestamp, parsed["sender"]["login"], emoji)

        owner = yield self.salons.get_nick_for_user(parsed["issue"]["user"]["login"])
        user = yield self.salons.get_nick_for_user(parsed["sender"]["login"])
        message_info = dict(
            user=dehilight(user),
            owner=owner,
            owner_de=dehilight(owner),
            id=str(pr_id),
            short_url=short_url,
            repo=repository_name,
        )

        if "%(reviewers)s" in message:
            if emoji == ":eyeglasses:":
                reviewers = _extract_reviewers(body)
                if not reviewers:
                    return
            else:
                reviewers = yield self.database.get_reviewers(repository_name,
                                                              pr_id)

            mapped_reviewers = []
            for reviewer_username in reviewers:
                nick = yield self.salons.get_nick_for_user(reviewer_username)
                mapped_reviewers.append(nick)
            message_info["reviewers"] = " & ".join(mapped_reviewers or
                                                  ["(no one in particular)"])

        if repository:
            self.bot.send_message(repository.channel, message % message_info)
示例#6
0
文件: github.py 项目: spladug/harold
    def dispatch_review(self, parsed):
        if parsed["action"] != "submitted":
            return

        repository_name = parsed["repository"]["full_name"]
        repository = yield self.salons.get_repository(repository_name)
        html_link = parsed["pull_request"]["html_url"]
        short_url = yield self.shortener.make_short_url(html_link)
        pr_id = int(parsed["pull_request"]["number"])
        timestamp = _parse_timestamp(parsed["review"]["submitted_at"])

        emoji_by_state = {
            "approved": ":fish:",
            "changes_requested": ":nail_care:",
        }
        emoji = emoji_by_state.get(parsed["review"]["state"])
        if not emoji:
            return
        message = self.messages_by_emoji[emoji]

        yield self.database.update_review_state(
            repository_name, pr_id, parsed["review"]["body"],
            timestamp, parsed["sender"]["login"], emoji)

        owner = yield self.salons.get_nick_for_user(parsed["pull_request"]["user"]["login"])
        user = yield self.salons.get_nick_for_user(parsed["sender"]["login"])
        message_info = dict(
            user=dehilight(user),
            owner=owner,
            owner_de=dehilight(owner),
            id=str(pr_id),
            short_url=short_url,
            repo=repository_name,
        )

        if "%(reviewers)s" in message:
            reviewers = yield self.database.get_reviewers(repository_name, pr_id)
            mapped_reviewers = []
            for reviewer_username in reviewers:
                nick = yield self.salons.get_nick_for_user(reviewer_username)
                mapped_reviewers.append(nick)
            message_info["reviewers"] = " & ".join(mapped_reviewers or
                                                  ["(no one in particular)"])

        if repository:
            self.bot.send_message(repository.channel, message % message_info)
示例#7
0
文件: github.py 项目: dellis23/harold
    def dispatch_comment(self, parsed):
        if parsed["action"] != "created":
            return

        body = parsed["comment"]["body"]
        emoji, message = self.find_emoji(body)
        if not emoji:
            return

        yield self.database.process_comment(parsed["comment"], emoji)

        repository_name = parsed["repository"]["full_name"]
        repository = self.config.repositories_by_name[repository_name]
        html_link = parsed["issue"]["pull_request"]["html_url"]
        short_url = yield self.shortener.make_short_url(html_link)
        pr_id = int(parsed["issue"]["number"])

        owner = self.config.nick_by_user(parsed["issue"]["user"]["login"])
        message_info = dict(
            user=dehilight(self.config.nick_by_user(
                parsed["sender"]["login"])),
            owner=owner,
            owner_de=dehilight(owner),
            id=str(pr_id),
            short_url=short_url,
            repo=repository_name,
        )

        if "%(reviewers)s" in message:
            if emoji == ":eyeglasses:":
                reviewers = _extract_reviewers(body)
                if not reviewers:
                    return
            else:
                reviewers = yield self.database.get_reviewers(
                    repository_name, pr_id)

            mapped_reviewers = map(self.config.nick_by_user, reviewers)
            message_info["reviewers"] = ", ".join(
                mapped_reviewers or ["(no one in particular)"])

        self.bot.send_message(repository.channel, message % message_info)
示例#8
0
    def kick(self, irc, sender, channel, user):
        if channel != self.config.channel:
            return

        if user not in self.queue:
            self.irc.bot.send_message(
                channel, "%s, %s is not in the queue" % (sender, dehilight(user)))
            return

        self.queue.remove(user)
        self._update_conch()
        self._update_topic()
示例#9
0
文件: deploy.py 项目: dellis23/harold
    def kick(self, irc, sender, channel, user):
        if channel != self.config.channel:
            return

        if user not in self.queue:
            self.irc.bot.send_message(
                channel,
                "%s, %s is not in the queue" % (sender, dehilight(user)))
            return

        self.queue.remove(user)
        self._update_conch()
        self._update_topic()
示例#10
0
文件: deploy.py 项目: spladug/harold
    def kick(self, irc, sender, channel, user):
        salon = yield self.salons.by_channel(channel)
        if not (salon and salon.allow_deploys):
            return

        if user not in salon.queue:
            irc.send_message(channel, "@%s: %s is not in the queue" % (sender, dehilight(user)))
            return

        salon.queue.remove(user)
        salon.update_conch(irc)
        salon.update_topic(irc)

        if user == sender:
            irc.send_message(channel, ":nelson: stop kicking yourself! stop kicking yourself!")
示例#11
0
    def kick(self, irc, sender, channel, user):
        if channel != self.config.channel:
            return

        if user not in self.queue:
            self.irc.bot.send_message(
                channel,
                "@%s: %s is not in the queue" % (sender, dehilight(user)))
            return

        self.queue.remove(user)
        self._update_conch()
        self._update_topic()

        if user == sender:
            self.irc.bot.send_message(
                channel,
                ":nelson: stop kicking yourself! stop kicking yourself!")
示例#12
0
    def kick(self, irc, sender, channel, user):
        salon = yield self.salons.by_channel(channel)
        if not (salon and salon.allow_deploys):
            return

        if user not in salon.queue:
            irc.send_message(
                channel,
                "@%s: %s is not in the queue" % (sender, dehilight(user)))
            return

        salon.queue.remove(user)
        salon.update_conch(irc)
        salon.update_topic(irc)

        if user == sender:
            irc.send_message(
                channel,
                ":nelson: stop kicking yourself! stop kicking yourself!")
示例#13
0
文件: github.py 项目: andytuba/harold
    def dispatch_pullrequest(self, parsed):
        pull_request = parsed["pull_request"]
        timestamp = _parse_timestamp(pull_request["created_at"])
        repository_name = parsed["repository"]["full_name"]
        repository = yield self.salons.get_repository(repository_name)
        pull_request_id = parsed["number"]
        sender = yield self.salons.get_nick_for_user(parsed["sender"]["login"])

        yield self.database.process_pullrequest(pull_request, repository_name)

        html_link = pull_request["_links"]["html"]["href"]
        short_url = yield self.shortener.make_short_url(html_link)

        if parsed["action"] == "review_requested":
            if "requested_reviewer" not in parsed:
                return

            username = parsed["requested_reviewer"]["login"]
            is_new_request = yield self.database.add_review_request(
                repo=repository_name,
                pull_request_id=pull_request_id,
                username=username,
                timestamp=timestamp,
            )

            if is_new_request:
                message = self.messages_by_emoji[":eyeglasses:"]
            else:
                message = self.messages_by_emoji[":haircut:"]

                yield self.database.update_review_state(
                    repository_name, pull_request_id, "",
                    timestamp, parsed["sender"]["login"], ":haircut:")

            reviewer = yield self.salons.get_nick_for_user(username)

            if repository:
                self.bot.send_message(repository.channel, message % {
                    "reviewers": reviewer,
                    "owner_de": dehilight(sender),
                    "user": dehilight(sender),
                    "repo": repository_name,
                    "id": pull_request_id,
                    "short_url": short_url,
                })
        elif parsed["action"] == "review_request_removed":
            username = parsed["requested_reviewer"]["login"]
            yield self.database.remove_review_request(
                repo=repository_name,
                pull_request_id=pull_request_id,
                username=username,
            )
        elif parsed["action"] == "opened":
            message = ("%(user)s opened pull request #%(id)d (%(short_url)s) "
                       "on %(repo)s: %(title)s")

            if repository:
                self.bot.send_message(repository.channel, message % dict(
                    user=dehilight(sender),
                    id=pull_request_id,
                    short_url=short_url,
                    repo=repository_name,
                    title=pull_request["title"][:72],
                ))

            reviewer_usernames = _extract_reviewers(pull_request["body"])
            reviewers = []
            for reviewer_username in reviewer_usernames:
                nick = yield self.salons.get_nick_for_user(reviewer_username)
                reviewers.append(nick)
            if repository and reviewers:
                self.bot.send_message(repository.channel,
                                      "%(reviewers)s: %(user)s has requested "
                                      "your review of ^" % {
                                          "reviewers": " & ".join(reviewers),
                                          "user": dehilight(sender),
                                      })
示例#14
0
文件: github.py 项目: spladug/harold
    def dispatch_pullrequest(self, parsed):
        pull_request = parsed["pull_request"]
        timestamp = _parse_timestamp(pull_request["created_at"])
        repository_name = parsed["repository"]["full_name"]
        repository = yield self.salons.get_repository(repository_name)
        pull_request_id = parsed["number"]
        sender = yield self.salons.get_nick_for_user(parsed["sender"]["login"])

        yield self.database.process_pullrequest(pull_request, repository_name)

        html_link = pull_request["_links"]["html"]["href"]
        short_url = yield self.shortener.make_short_url(html_link)

        if parsed["action"] == "review_requested":
            if "requested_reviewer" not in parsed:
                return

            # the review state change should be timestampped based on this
            # action not based on when the PR was first created
            timestamp = datetime.datetime.utcnow()

            username = parsed["requested_reviewer"]["login"]
            is_new_request = yield self.database.add_review_request(
                repo=repository_name,
                pull_request_id=pull_request_id,
                username=username,
                timestamp=timestamp,
            )

            if is_new_request:
                message = self.messages_by_emoji[":eyeglasses:"]
            else:
                message = self.messages_by_emoji[":haircut:"]

                yield self.database.update_review_state(
                    repository_name, pull_request_id, "",
                    timestamp, parsed["sender"]["login"], ":haircut:")

            reviewer = yield self.salons.get_nick_for_user(username)

            if repository:
                self.bot.send_message(repository.channel, message % {
                    "reviewers": reviewer,
                    "owner_de": dehilight(sender),
                    "user": dehilight(sender),
                    "repo": repository_name,
                    "id": pull_request_id,
                    "short_url": short_url,
                })
        elif parsed["action"] == "review_request_removed":
            username = parsed["requested_reviewer"]["login"]
            yield self.database.remove_review_request(
                repo=repository_name,
                pull_request_id=pull_request_id,
                username=username,
            )
        elif parsed["action"] == "opened":
            message = ("%(user)s opened pull request #%(id)d (%(short_url)s) "
                       "on %(repo)s: %(title)s")

            if repository:
                self.bot.send_message(repository.channel, message % dict(
                    user=dehilight(sender),
                    id=pull_request_id,
                    short_url=short_url,
                    repo=repository_name,
                    title=pull_request["title"][:72],
                ))

            reviewer_usernames = _extract_reviewers(pull_request["body"])
            reviewers = []
            for reviewer_username in reviewer_usernames:
                nick = yield self.salons.get_nick_for_user(reviewer_username)
                reviewers.append(nick)
            if repository and reviewers:
                message = self.messages_by_emoji[":eyeglasses:"]
                self.bot.send_message(repository.channel, message % {
                    "reviewers": " & ".join(reviewers),
                    "user": dehilight(sender),
                    "repo": repository_name,
                    "id": pull_request_id,
                    "short_url": short_url,
                })
示例#15
0
    def dispatch_pullrequest(self, parsed):
        pull_request = parsed["pull_request"]
        timestamp = _parse_timestamp(pull_request["created_at"])
        repository_name = parsed["repository"]["full_name"]
        repository = yield self.salons.get_repository(repository_name)
        pull_request_id = parsed["number"]
        sender_username = parsed["sender"]["login"]
        sender = yield self.salons.get_nick_for_user(sender_username)

        if parsed["action"] == "opened":
            yield self.database.emit_event(
                actor=sender_username,
                event="opened",
                repository=repository_name,
                pull_request_id=pull_request_id,
                timestamp=timestamp,
            )

            yield self.database._add_mentions(
                sender_username,
                repository_name,
                pull_request_id,
                pull_request["body"],
                timestamp,
            )

        yield self.database.process_pullrequest(sender_username, pull_request,
                                                repository_name)

        short_url = html_link = pull_request["_links"]["html"]["href"]

        if parsed["action"] == "review_requested":
            if "requested_reviewer" not in parsed:
                return

            # the review state change should be timestampped based on this
            # action not based on when the PR was first created
            timestamp = datetime.datetime.utcnow()

            username = parsed["requested_reviewer"]["login"]
            is_new_request = yield self.database.add_review_request(
                sender=sender_username,
                repo=repository_name,
                pull_request_id=pull_request_id,
                username=username,
                timestamp=timestamp,
            )

            if is_new_request:
                message = self.messages_by_emoji[":eyeglasses:"]
            else:
                message = self.messages_by_emoji[":haircut:"]

            reviewer = yield self.salons.get_nick_for_user(username)

            if repository:
                self.bot.send_message(
                    repository.channel, message % {
                        "reviewers": reviewer,
                        "owner_de": dehilight(sender),
                        "user": dehilight(sender),
                        "repo": repository_name,
                        "id": pull_request_id,
                        "short_url": short_url,
                    })
        elif parsed["action"] == "review_request_removed":
            username = parsed["requested_reviewer"]["login"]
            yield self.database.remove_review_request(
                repo=repository_name,
                pull_request_id=pull_request_id,
                username=username,
            )

            yield self.database.emit_event(
                actor=sender_username,
                event="review_request_removed",
                repository=repository_name,
                pull_request_id=pull_request_id,
                targets=[username],
            )
        elif parsed["action"] == "opened":
            message = ("%(user)s opened pull request #%(id)d (%(short_url)s) "
                       "on %(repo)s: %(title)s")

            if repository:
                self.bot.send_message(
                    repository.channel, message % dict(
                        user=dehilight(sender),
                        id=pull_request_id,
                        short_url=short_url,
                        repo=repository_name,
                        title=pull_request["title"][:72],
                    ))

            reviewer_usernames = _extract_reviewers(pull_request["body"])
            reviewers = []
            for reviewer_username in reviewer_usernames:
                nick = yield self.salons.get_nick_for_user(reviewer_username)
                reviewers.append(nick)
            if repository and reviewers:
                message = self.messages_by_emoji[":eyeglasses:"]
                self.bot.send_message(
                    repository.channel, message % {
                        "reviewers": " & ".join(reviewers),
                        "user": dehilight(sender),
                        "repo": repository_name,
                        "id": pull_request_id,
                        "short_url": short_url,
                    })
        elif parsed["action"] == "reopened":
            yield self.database.emit_event(
                actor=sender_username,
                event="reopened",
                repository=repository_name,
                pull_request_id=pull_request_id,
            )
        elif parsed["action"] == "closed":
            yield self.database.emit_event(
                actor=sender_username,
                event="closed",
                repository=repository_name,
                pull_request_id=pull_request_id,
            )