| |
@@ -0,0 +1,110 @@
|
| |
+ from __future__ import unicode_literals
|
| |
+
|
| |
+ import requests
|
| |
+
|
| |
+ from hubs.utils import pagure
|
| |
+ from hubs.widgets.base import Widget
|
| |
+ from hubs.widgets.view import RootWidgetView
|
| |
+ from hubs.widgets.caching import CachedFunction
|
| |
+
|
| |
+
|
| |
+ class Repositories(Widget):
|
| |
+
|
| |
+ name = "repositories"
|
| |
+ label = "Repositories"
|
| |
+ position = "right"
|
| |
+ hub_types = ["team"]
|
| |
+
|
| |
+
|
| |
+ class BaseView(RootWidgetView):
|
| |
+
|
| |
+ def get_context(self, instance, *args, **kwargs):
|
| |
+ repos = GetRepos(instance)
|
| |
+ return dict(
|
| |
+ repos=repos(),
|
| |
+ )
|
| |
+
|
| |
+
|
| |
+ class GetRepos(CachedFunction):
|
| |
+
|
| |
+ def execute(self):
|
| |
+ repos_list = []
|
| |
+
|
| |
+ for repo in self.instance.hub.config["pagure"]:
|
| |
+ issues_url = '/'.join([pagure.PAGURE_URL, "api",
|
| |
+ "0", repo, "issues"])
|
| |
+ issues_response = requests.get(issues_url)
|
| |
+ issues_data = issues_response.json()
|
| |
+
|
| |
+ pr_url = '/'.join([pagure.PAGURE_URL, "api",
|
| |
+ "0", repo, "pull-requests"])
|
| |
+ pr_response = requests.get(pr_url)
|
| |
+ pr_data = pr_response.json()
|
| |
+
|
| |
+ out = {"repo_name": repo,
|
| |
+ "repo_url": "https://pagure.io/"+repo,
|
| |
+ "issues_count": issues_data['total_issues'],
|
| |
+ "pr_count": pr_data['total_requests'],
|
| |
+ "type": "pagure",
|
| |
+ }
|
| |
+ repos_list.append(out)
|
| |
+
|
| |
+ for repo in self.instance.hub.config["github"]:
|
| |
+ issues_url = ':'.join(
|
| |
+ [('https://api.github.com/search/issues?'
|
| |
+ 'q=""+state:open+type:issue+repo'), repo])
|
| |
+ issues_response = requests.get(issues_url)
|
| |
+ issues_count = issues_response.json()['total_count']
|
| |
+ pr_url = ':'.join(
|
| |
+ [('https://api.github.com/search/issues?'
|
| |
+ 'q=""+state:open+type:pr+repo'), repo])
|
| |
+ pr_response = requests.get(pr_url)
|
| |
+ pr_count = pr_response.json()['total_count']
|
| |
+
|
| |
+ out = {"repo_name": repo,
|
| |
+ "repo_url": "https://github.com/"+repo,
|
| |
+ "issues_count": issues_count,
|
| |
+ "pr_count": pr_count,
|
| |
+ "type": "github"
|
| |
+ }
|
| |
+ repos_list.append(out)
|
| |
+
|
| |
+ return repos_list
|
| |
+
|
| |
+ def should_invalidate(self, message):
|
| |
+ pagure_repos = self.instance.hub.config["pagure"]
|
| |
+ github_repos = self.instance.hub.config["github"]
|
| |
+ if (
|
| |
+ ".github.issue." in message["topic"] or
|
| |
+ ".github.pull_request.opened" in message["topic"] or
|
| |
+ ".github.pull_request.closed" in message["topic"]):
|
| |
+ try:
|
| |
+ repo = message['msg']['repository']['fullname']
|
| |
+ except KeyError:
|
| |
+ return False
|
| |
+ return (repo in github_repos)
|
| |
+ elif (".pagure.issue." in message["topic"]):
|
| |
+ try:
|
| |
+ repo = message['msg']['project']['name']
|
| |
+ except KeyError:
|
| |
+ return False
|
| |
+ return (repo in pagure_repos)
|
| |
+ elif (
|
| |
+ ".pagure.pull-request.new" not in message["topic"] or
|
| |
+ ".pagure.pull-request.closed" not in message["topic"]):
|
| |
+ try:
|
| |
+ repo = message['msg']['pullrequest']['project']['name']
|
| |
+ except KeyError:
|
| |
+ return False
|
| |
+ return (repo in pagure_repos)
|
| |
+ elif message["topic"].endswith('.hubs.hub.updated'):
|
| |
+ if (
|
| |
+ "github" in message["msg"]["changed_keys"] or
|
| |
+ "pagure" in message["msg"]["changed_keys"]):
|
| |
+ hub_id = message["msg"]["hub_id"]
|
| |
+ if hub_id == self.instance.hub.id:
|
| |
+ return True
|
| |
+ else:
|
| |
+ return False
|
| |
+ else:
|
| |
+ return False
|
| |
This adds a new widget called repositories. It is designed
to be shown on the team hub type only, and shows a list of
the repos set up in the team hubs config (in the dev platforms section)
It also shows how many open bugs and open PRs there are for each of
the repos set up.