#535 add repositories widget
Merged 6 years ago by abompard. Opened 6 years ago by ryanlerch.
ryanlerch/fedora-hubs repos-widget  into  develop

file modified
+1
@@ -71,6 +71,7 @@ 

      'hubs.widgets.my_hubs:MyHubs',

      'hubs.widgets.pagure_pr:PagurePRs',

      'hubs.widgets.pagureissues:PagureIssues',

+     'hubs.widgets.repositories:Repositories',

      'hubs.widgets.sticky:Sticky',

      'hubs.widgets.workflow.updates2stable:Updates2Stable',

      ]

@@ -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

@@ -0,0 +1,23 @@ 

+ <table>

+ {% for repo in repos %}

+   <tr>

+     <td class="repo-name"><strong><a href='{{repo["repo_url"]}}'>{{repo["repo_name"]}}</a></strong></td>

+     <td class="issues-count pr-2"><i class="fa fa-bug mr-1"></i>{{repo["issues_count"]}}</td>

+     <td class="pr-count"><i class="fa fa-code-fork mr-1"></i>{{repo["pr_count"]}}</td>

+   </tr>

+ {% endfor %}

+ </table>

+     

+ <style>

+ .widget-repositories td.repo-name{

+   min-width:99%;

+ }

+ 

+ .widget-repositories td.issues-count, .widget-repositories td.pr-count{

+   white-space: nowrap;

+ }

+ 

+ .widget-repositories table tr{

+   line-height: 2em;

+ }

+ </style> 

\ No newline at end of file

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.

repos-widget.png

Look! Crumbs! Crumbs on his jacketses!

That looks nice! Thanks :-)

thanks for the review @abompard! just updated the commit to remove the logging stuff! nice pickup!

rebased onto e591b46c8b8f4fe22a2b2a45ecd6f7d7273e5680

6 years ago

So if you want to use .get() instead of the key lookup, make sure you use a default of [], otherwise the loop on None will fail. But the config should always return you a list anyway.

rebased onto 0747a9ce57e271bfc8099825263ee8a9fbe0d988

6 years ago

okies, updated the commit to just use the keys directly rather than .get()

/me just copied the .get() bit from the meetings widget without really understanding it properly :/

sorry!

rebased onto 79d5b6aefab9fbe124f99fd7d526b50129d640d1

6 years ago

rebased onto d5aae81

6 years ago

Commit e4ce940 fixes this pull-request

Pull-Request has been merged by abompard

6 years ago

Pull-Request has been merged by abompard

6 years ago