Exemplo n.º 1
0
 def on_github_issues(self, data):
     action = data["action"]
     payload = None
     repo_name = data["repository"]["name"]
     if action == "assigned" or action == "unassigned":
         payload = data["issue"]["assignee"]["login"]
     elif action == "labeled" or action == "unlabeled":
         url = yield shorten_github_url(data["issue"]["html_url"])
         fg, bg = self.github_label_colors(data["label"])
         payload = "{} ({})".format(colored(data["label"]["name"], fg, bg),
                                    url)
     elif action == "milestoned":
         payload = data["issue"]["milestone"]["title"]
     elif action == "opened":
         action = colored(action, "red")
     elif action == "reopened":
         action = colored(action, "red")
     elif action == "closed":
         action = colored(action, "dark_green")
     if not payload:
         payload = yield shorten_github_url(data["issue"]["html_url"])
     msg = ("[{repo_name}] {user} {action} Issue #{number} {title}: "
            "{payload}".format(repo_name=colored(repo_name, "blue"),
                               user=colored(data["sender"]["login"],
                                            "dark_cyan"),
                               action=action,
                               number=colored(str(data["issue"]["number"]),
                                              "dark_yellow"),
                               title=unidecode(data["issue"]["title"]),
                               payload=payload))
     self.report_to_irc(repo_name, msg)
Exemplo n.º 2
0
 def on_github_issues(self, data):
     action = data["action"]
     payload = None
     repo_name = data["repository"]["name"]
     if action == "assigned" or action == "unassigned":
         payload = data["issue"]["assignee"]["login"]
     elif action == "labeled" or action == "unlabeled":
         url = yield shorten_github_url(data["issue"]["html_url"])
         fg, bg = self.github_label_colors(data["label"])
         payload = "{} ({})".format(colored(data["label"]["name"],
                                            fg, bg), url)
     elif action == "milestoned":
         payload = data["issue"]["milestone"]["title"]
     elif action == "opened":
         action = colored(action, "red")
     elif action == "reopened":
         action = colored(action, "red")
     elif action == "closed":
         action = colored(action, "dark_green")
     if not payload:
         payload = yield shorten_github_url(data["issue"]["html_url"])
     msg = ("[{repo_name}] {user} {action} Issue #{number} {title}: "
            "{payload}".format(repo_name=colored(repo_name, "blue"),
                               user=colored(data["sender"]["login"],
                                            "dark_cyan"),
                               action=action,
                               number=colored(str(data["issue"]["number"]),
                                              "dark_yellow"),
                               title=unidecode(data["issue"]["title"]),
                               payload=payload))
     self.report_to_irc(repo_name, msg)
Exemplo n.º 3
0
 def on_github_pull_request(self, data):
     action = data["action"]
     payload = None
     repo_name = data["repository"]["name"]
     user = data["sender"]["login"]
     if action == "assigned" or action == "unassigned":
         payload = data["pull_request"]["assignee"]["login"]
     elif action == "labeled" or action == "unlabeled":
         url = yield shorten_github_url(data["pull_request"]["html_url"])
         fg, bg = self.github_label_colors(data["label"])
         payload = "{} ({})".format(colored(data["label"]["name"], fg, bg),
                                    url)
     elif action == "milestoned":
         payload = data["pull_request"]["milestone"]["title"]
     elif action == "review_requested":
         action = "requested review for"
         payload = data["requested_reviewer"]["login"]
     elif action == "review_request_removed":
         action = "removed review request for"
         payload = data["requested_reviewer"]["login"]
     elif action == "opened":
         action = colored(action, "dark_green")
     elif action == "reopened":
         action = colored(action, "dark_green")
     elif action == "closed":
         if data["pull_request"]["merged"]:
             action = colored("merged", "dark_green")
             user = data["pull_request"]["merged_by"]["login"]
         else:
             action = colored(action, "red")
     elif action == "synchronize":
         action = "synchronized"
     elif action == "ready_for_review":
         action = "marked ready for review:"
     if not payload:
         payload = yield shorten_github_url(
             data["pull_request"]["html_url"])
     msg = ("[{repo_name}] {user} {action} Pull Request #{number} {title} "
            "({head} -> {base}): {payload}".format(
                repo_name=colored(repo_name, "blue"),
                user=colored(user, "dark_cyan"),
                action=action,
                number=colored(str(data["pull_request"]["number"]),
                               "dark_yellow"),
                title=unidecode(data["pull_request"]["title"]),
                head=colored(data["pull_request"]["head"]["ref"],
                             "dark_blue"),
                base=colored(data["pull_request"]["base"]["ref"],
                             "dark_red"),
                payload=payload))
     self.report_to_irc(repo_name, msg)
Exemplo n.º 4
0
 def on_github_pull_request(self, data):
     action = data["action"]
     payload = None
     repo_name = data["repository"]["name"]
     user = data["pull_request"]["user"]["login"]
     if action == "assigned" or action == "unassigned":
         payload = data["pull_request"]["assignee"]["login"]
     elif action == "labeled" or action == "unlabeled":
         url = yield shorten_github_url(data["pull_request"]["html_url"])
         fg, bg = self.github_label_colors(data["label"])
         payload = "{} ({})".format(colored(data["label"]["name"],
                                            fg, bg), url)
     elif action == "milestoned":
         payload = data["pull_request"]["milestone"]["title"]
     elif action == "review_requested":
         action = "requested review for"
         payload = data["requested_reviewer"]["login"]
     elif action == "review_request_removeded":
         action = "removed review request for"
         payload = data["requested_reviewer"]["login"]
     elif action == "opened":
         action = colored(action, "dark_green")
     elif action == "reopened":
         action = colored(action, "dark_green")
     elif action == "closed":
         if data["pull_request"]["merged"]:
             action = colored("merged", "dark_green")
             user = data["pull_request"]["merged_by"]["login"]
         else:
             action = colored(action, "red")
             user = data["sender"]["login"]
     elif action == "synchronize":
         action = "synchronized"
     if not payload:
         payload = yield shorten_github_url(
             data["pull_request"]["html_url"])
     msg = ("[{repo_name}] {user} {action} Pull Request #{number} {title} "
            "({head} -> {base}): {payload}".format(
                repo_name=colored(repo_name, "blue"),
                user=colored(user, "dark_cyan"),
                action=action,
                number=colored(str(data["pull_request"]["number"]),
                               "dark_yellow"),
                title=unidecode(data["pull_request"]["title"]),
                head=colored(data["pull_request"]["head"]["ref"],
                             "dark_blue"),
                base=colored(data["pull_request"]["base"]["ref"],
                             "dark_red"),
                payload=payload))
     self.report_to_irc(repo_name, msg)
Exemplo n.º 5
0
 def on_github_push(self, data):
     action = "pushed"
     if data["deleted"]:
         action = colored("deleted", "red")
     elif data["forced"]:
         action = colored("force pushed", "red")
     url = yield shorten_github_url(data["compare"])
     repo_name = data["repository"]["name"]
     branch = data["ref"].split("/", 2)[-1]
     msg = ("[{repo_name}] {pusher} {action} {num_commits} commit(s) to "
            "{branch}: {compare}".format(
                repo_name=colored(repo_name, "blue"),
                pusher=colored(unidecode(data["pusher"]["name"]),
                               "dark_cyan"),
                action=action,
                num_commits=len(data["commits"]),
                branch=colored(branch, "dark_green"),
                compare=url))
     self.report_to_irc(repo_name, msg)
     self.commits_to_irc(repo_name, data["commits"], github=True)
     # subset of information that is common for both GitHUb and GitLab
     # only a few useful pieces of information
     subset = {"commits": data["commits"],
               "branch": branch,
               "project": {"name": data["repository"]["name"],
                           "namespace": data["repository"]["full_name"].split(
                               "/")[0],
                           "description": data["repository"]["description"],
                           "url": data["repository"]["html_url"],
                           "homepage": data["repository"]["homepage"]},
               "pusher": {"name": data["pusher"]["name"],
                          "username": data["sender"]["login"],
                          "id": data["sender"]["id"]}}
     self.push_hooks(subset)
Exemplo n.º 6
0
 def on_github_release(self, data):
     repo_name = data["repository"]["name"]
     url = yield shorten_github_url(data["release"]["html_url"])
     msg = "[{repo_name}] New release {url}".format(
         repo_name=colored(data["repository"]["name"], "blue"),
         url=url)
     self.report_to_irc(repo_name, msg)
Exemplo n.º 7
0
 def on_github_release(self, data):
     repo_name = data["repository"]["name"]
     url = yield shorten_github_url(data["release"]["html_url"])
     msg = "[{repo_name}] New release {url}".format(repo_name=colored(
         data["repository"]["name"], "blue"),
                                                    url=url)
     self.report_to_irc(repo_name, msg)
Exemplo n.º 8
0
 def on_github_commit_comment(self, data):
     repo_name = data["repository"]["name"]
     url = yield shorten_github_url(data["comment"]["html_url"])
     msg = "[{repo_name}] {user} commented on commit {url}".format(
         repo_name=colored(repo_name, "blue"),
         user=colored(data["comment"]["user"]["login"], "dark_cyan"),
         url=url)
     self.report_to_irc(repo_name, msg)
Exemplo n.º 9
0
 def on_github_commit_comment(self, data):
     repo_name = data["repository"]["name"]
     url = yield shorten_github_url(data["comment"]["html_url"])
     msg = "[{repo_name}] {user} commented on commit {url}".format(
         repo_name=colored(repo_name, "blue"),
         user=colored(data["comment"]["user"]["login"], "dark_cyan"),
         url=url)
     self.report_to_irc(repo_name, msg)
Exemplo n.º 10
0
 def on_github_fork(self, data):
     repo_name = data["repository"]["name"]
     url = yield shorten_github_url(data["forkee"]["html_url"])
     msg = "[{repo_name}] {user} created fork {url}".format(
         repo_name=colored(repo_name, "blue"),
         user=colored(data["forkee"]["owner"]["login"], "dark_cyan"),
         url=url)
     self.report_to_irc(repo_name, msg)
Exemplo n.º 11
0
 def on_github_fork(self, data):
     repo_name = data["repository"]["name"]
     url = yield shorten_github_url(data["forkee"]["html_url"])
     msg = "[{repo_name}] {user} created fork {url}".format(
         repo_name=colored(repo_name, "blue"),
         user=colored(data["forkee"]["owner"]["login"], "dark_cyan"),
         url=url)
     self.report_to_irc(repo_name, msg)
Exemplo n.º 12
0
 def on_github_issue_comment(self, data):
     url = yield shorten_github_url(data["comment"]["html_url"])
     repo_name = data["repository"]["name"]
     msg = ("[{repo_name}] {user} {action} comment on Issue #{number} "
            "{title} {url}".format(
                repo_name=colored(repo_name, "blue"),
                user=colored(data["comment"]["user"]["login"], "dark_cyan"),
                action=data["action"],
                number=colored(str(data["issue"]["number"]), "dark_yellow"),
                title=unidecode(data["issue"]["title"]),
                url=url))
     self.report_to_irc(repo_name, msg)
Exemplo n.º 13
0
 def on_github_issue_comment(self, data):
     url = yield shorten_github_url(data["comment"]["html_url"])
     repo_name = data["repository"]["name"]
     msg = ("[{repo_name}] {user} {action} comment on Issue #{number} "
            "{title} {url}".format(
                repo_name=colored(repo_name, "blue"),
                user=colored(data["comment"]["user"]["login"], "dark_cyan"),
                action=data["action"],
                number=colored(str(data["issue"]["number"]), "dark_yellow"),
                title=unidecode(data["issue"]["title"]),
                url=url))
     self.report_to_irc(repo_name, msg)
Exemplo n.º 14
0
 def on_github_pull_request_review_comment(self, data):
     if self.prevent_github_review_flood:
         self._gh_review_comment_buffer.append(data)
         if self._gh_review_comment_delayed_call:
             self._gh_review_comment_delayed_call.cancel()
         self._gh_review_comment_delayed_call = reactor.callLater(
             GitWebhookServer.GH_ReviewFloodPrevention_Delay,
             self.github_handle_review_flood, True)
     else:
         url = yield shorten_github_url(data["comment"]["html_url"])
         self._github_PR_review_send_msg(
             True, data["repository"]["name"],
             data["comment"]["user"]["login"],
             data["pull_request"]["number"], data["pull_request"]["title"],
             data["action"], data["pull_request"]["head"]["ref"],
             data["pull_request"]["base"]["ref"], [url])
Exemplo n.º 15
0
 def on_github_pull_request_review_comment(self, data):
     repo_name = data["repository"]["name"]
     url = yield shorten_github_url(data["comment"]["html_url"])
     msg = ("[{repo_name}] {user} commented on Pull Request #{number} "
            "{title} ({head} -> {base}): {url}".format(
                repo_name=colored(repo_name, "blue"),
                user=colored(data["comment"]["user"]["login"], "dark_cyan"),
                number=colored(str(data["pull_request"]["number"]),
                               "dark_yellow"),
                title=unidecode(data["pull_request"]["title"]),
                head=colored(data["pull_request"]["head"]["ref"],
                             "dark_blue"),
                base=colored(data["pull_request"]["base"]["ref"],
                             "dark_red"),
                url=url))
     self.report_to_irc(repo_name, msg)
Exemplo n.º 16
0
 def commits_to_irc(self, repo_name, commits, github=False):
     for i, commit in enumerate(commits):
         if i == 3:
             self.report_to_irc(repo_name, "+{} more commits".format(
                 len(commits) - 3))
             break
         if github:
             url = yield shorten_github_url(commit["url"])
         else:
             url = commit["url"]
         message = unidecode(commit["message"].split("\n")[0])
         if len(message) > 100:
             message = message[:100] + "..."
         self.report_to_irc(repo_name, "{author}: {message} ({url})".format(
             author=colored(unidecode(commit["author"]["name"]),
                            "dark_cyan"),
             message=message,
             url=url))
Exemplo n.º 17
0
 def commits_to_irc(self, repo_name, commits, github=False):
     for i, commit in enumerate(commits):
         if i == 3:
             self.report_to_irc(repo_name,
                                "+{} more commits".format(len(commits) - 3))
             break
         if github:
             url = yield shorten_github_url(commit["url"])
         else:
             url = commit["url"]
         message = unidecode(commit["message"].split("\n")[0])
         if len(message) > 100:
             message = message[:100] + "..."
         self.report_to_irc(
             repo_name,
             "{author}: {message} ({url})".format(author=colored(
                 unidecode(commit["author"]["name"]), "dark_cyan"),
                                                  message=message,
                                                  url=url))
Exemplo n.º 18
0
 def on_github_push(self, data):
     action = "pushed"
     if data["deleted"]:
         action = colored("deleted", "red")
     elif data["forced"]:
         action = colored("force pushed", "red")
     url = yield shorten_github_url(data["compare"])
     repo_name = data["repository"]["name"]
     branch = data["ref"].split("/", 2)[-1]
     msg = ("[{repo_name}] {pusher} {action} {num_commits} commit(s) to "
            "{branch}: {compare}".format(
                repo_name=colored(repo_name, "blue"),
                pusher=colored(unidecode(data["pusher"]["name"]),
                               "dark_cyan"),
                action=action,
                num_commits=len(data["commits"]),
                branch=colored(branch, "dark_green"),
                compare=url))
     self.report_to_irc(repo_name, msg)
     self.commits_to_irc(repo_name, data["commits"], github=True)
     # subset of information that is common for both GitHUb and GitLab
     # only a few useful pieces of information
     subset = {
         "commits": data["commits"],
         "branch": branch,
         "project": {
             "name": data["repository"]["name"],
             "namespace": data["repository"]["full_name"].split("/")[0],
             "description": data["repository"]["description"],
             "url": data["repository"]["html_url"],
             "homepage": data["repository"]["homepage"]
         },
         "pusher": {
             "name": data["pusher"]["name"],
             "username": data["sender"]["login"],
             "id": data["sender"]["id"]
         }
     }
     self.push_hooks(subset)
Exemplo n.º 19
0
 def github_handle_review_flood(self, is_comment):
     # Clear buffer and callID first as later async calls give control
     # back to the reactor. This way, the buffer could be changed in the
     # middle of this function and events could be lost
     if is_comment:
         buffer = self._gh_review_comment_buffer
         self._gh_review_comment_buffer = []
         self._gh_review_comment_delayed_call = None
         type_ = "comment"
     else:
         buffer = self._gh_review_buffer
         self._gh_review_buffer = []
         self._gh_review_delayed_call = None
         type_ = "review"
     partition = {}
     for event in buffer:
         repo_name = event["repository"]["name"]
         user = event[type_]["user"]["login"]
         pr_number = event["pull_request"]["number"]
         action = event["action"]
         key = (repo_name, pr_number, user, action)
         if key not in partition:
             partition[key] = []
         partition[key].append(event)
     for k, events in partition.items():
         repo_name, pr_number, user, action = k
         title = events[0]["pull_request"]["title"]
         head = events[0]["pull_request"]["head"]["ref"]
         base = events[0]["pull_request"]["base"]["ref"]
         # remove duplicate urls
         full_urls = {e[type_]["html_url"] for e in events}
         urls_defers = [shorten_github_url(url) for url in full_urls]
         results = yield defer.DeferredList(urls_defers)
         urls = [res[1] for res in results]
         self._github_PR_review_send_msg(is_comment, repo_name, user,
                                         pr_number, title, action, head,
                                         base, urls)