| |
@@ -1,104 +0,0 @@
|
| |
- from __future__ import unicode_literals
|
| |
-
|
| |
- import requests
|
| |
-
|
| |
- from hubs.utils import validators
|
| |
- from hubs.widgets.base import Widget
|
| |
- from hubs.widgets.view import RootWidgetView
|
| |
- from hubs.widgets.caching import CachedFunction
|
| |
-
|
| |
-
|
| |
- # TODO: use a checkbox set to select which repos to use from the hub's
|
| |
- # configuration.
|
| |
-
|
| |
-
|
| |
- class GitHubIssues(Widget):
|
| |
-
|
| |
- name = "githubissues"
|
| |
- label = "Github: Newest Open Tickets"
|
| |
- position = "right"
|
| |
- parameters = [
|
| |
- dict(
|
| |
- name="org",
|
| |
- label="Username",
|
| |
- default=None,
|
| |
- validator=validators.GithubOrganization,
|
| |
- help="Github Organization or username",
|
| |
- ), dict(
|
| |
- name="repo",
|
| |
- label="Repository",
|
| |
- default=None,
|
| |
- validator=validators.GithubRepo,
|
| |
- help="Github repository",
|
| |
- ), dict(
|
| |
- name="display_number",
|
| |
- label="Number of tickets",
|
| |
- default=10,
|
| |
- validator=validators.Integer,
|
| |
- help="The number of tickets to display.",
|
| |
- )]
|
| |
-
|
| |
- def validate_parameters(self, values):
|
| |
- config = {}
|
| |
- config["org"] = \
|
| |
- validators.GithubOrganization(values["org"])
|
| |
- config["repo"] = \
|
| |
- validators.GithubRepo('/'.join([values["org"],
|
| |
- values["repo"]]))
|
| |
- config["display_number"] = \
|
| |
- validators.Integer(values["display_number"])
|
| |
- return config
|
| |
-
|
| |
-
|
| |
- class BaseView(RootWidgetView):
|
| |
-
|
| |
- def get_context(self, instance, *args, **kwargs):
|
| |
- get_issues = GetIssues(instance)
|
| |
- return dict(
|
| |
- org=instance.config["org"],
|
| |
- repo=instance.config["repo"],
|
| |
- display_number=instance.config["display_number"],
|
| |
- all_issues=get_issues(),
|
| |
- )
|
| |
-
|
| |
-
|
| |
- class GetIssues(CachedFunction):
|
| |
- ''' Data for Github Issues widget. Queries github api for issues '''
|
| |
-
|
| |
- def execute(self):
|
| |
- org = self.instance.config["org"]
|
| |
- repo = self.instance.config["repo"]
|
| |
- display_number = int(self.instance.config["display_number"])
|
| |
- url = '/'.join(['https://api.github.com/repos', org, repo, "issues"])
|
| |
- issues = requests.get(url).json()
|
| |
-
|
| |
- all_issues = []
|
| |
- for issue in issues[:display_number]:
|
| |
- issue_details = {}
|
| |
- issue_details['num'] = issue['number']
|
| |
- issue_details['title'] = issue['title']
|
| |
- issue_details['openedby'] = issue['user']['login']
|
| |
-
|
| |
- issue_assignee = None
|
| |
- if issue['assignee'] is not None:
|
| |
- issue_assignee = issue['assignee']['login']
|
| |
-
|
| |
- issue_details['assignee'] = issue_assignee
|
| |
- all_issues.append(issue_details)
|
| |
-
|
| |
- all_issues.reverse()
|
| |
- return all_issues
|
| |
-
|
| |
- def should_invalidate(self, message):
|
| |
- if ".github.issue." not in message["topic"]:
|
| |
- return False
|
| |
- try:
|
| |
- org = message['msg']['organization']
|
| |
- repo = message['msg']['repository']
|
| |
- except KeyError:
|
| |
- return False
|
| |
- return (
|
| |
- org == self.instance.config["org"]
|
| |
- and
|
| |
- repo == self.instance.config["repo"]
|
| |
- )
|
| |
This adds a new widget called issues that replaces the
githubissues and pagureissues widgets. It consolodates these into a
single widget that draws the repos from the team hub config