Skip to content

Commit

Permalink
[pagure] Add pagure frontend plugin
Browse files Browse the repository at this point in the history
Fixes #169
  • Loading branch information
msimacek committed Aug 14, 2017
1 parent 8a6722f commit 05818b8
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 0 deletions.
13 changes: 13 additions & 0 deletions config.cfg.template
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ config = {
# whether to synchronize package tracked status from pkgdb
"sync_tracked": False,
},
# pagure plugin
"pagure": {
"api_url": "https://src.fedoraproject.org/api/0",
},
# copr rebuild plugin
"copr": {
# URL to copr frontend (used to construct links in UI)
Expand Down Expand Up @@ -209,6 +213,15 @@ config = {
"filename": "@CACHEDIR@/rpm-requires-cache.dbm"
},
},
"pagure": {
"users": {
"backend": "dogpile.cache.dbm",
"expiration_time": 600,
"arguments": {
"filename": "@CACHEDIR@/pagure-user-cache.dbm"
},
},
},
"plugin": {
"pkgdb": {
"users": {
Expand Down
Empty file.
51 changes: 51 additions & 0 deletions koschei/plugins/pagure_plugin/frontend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright (C) 2017 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Author: Michael Simacek <msimacek@redhat.com>

from __future__ import print_function, absolute_import

import requests

from koschei.config import get_config
from koschei.plugin import listen_event


def query_pagure(session, url):
baseurl = get_config('pagure.api_url')
req = requests.get(baseurl + '/' + url)
if not req.ok:
session.log.info("pagure query failed %s, status=%d",
url, req.status_code)
return None
return req.json()


def query_users_packages(session, username):
session.log.debug("Requesting pagure packages for {}".format(username))
user = query_pagure(session, 'user/{}'.format(username))
if not user:
return None
return [repo['name'] for repo in user['repos'] if repo['namespace'] == 'rpms']


@listen_event('get_user_packages')
def get_user_packages(session, username):
def create():
names = query_users_packages(session, username)
return names

return session.cache('pagure.users').get_or_create(str(username), create)
67 changes: 67 additions & 0 deletions test/data/pagure_msimacek.vcr.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions test/test_config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ config = {
"rpm_requires": {
"backend": "dogpile.cache.null",
},
"pagure": {
"users": {
"backend": "dogpile.cache.null",
},
},
},
"flask": {
},
Expand Down
38 changes: 38 additions & 0 deletions test/test_pagure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (C) 2017 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Author: Michael Simacek <msimacek@redhat.com>

from __future__ import print_function, absolute_import

from koschei import plugin

from test.common import DBTest, my_vcr


class TestPagure(DBTest):
def setUp(self):
super(TestPagure, self).setUp()
plugin.load_plugins('frontend', ['pagure'])

@my_vcr.use_cassette('pagure_msimacek')
def test_get_my_packages(self):
results = []
for r in plugin.dispatch_event('get_user_packages',
self.session,
username='msimacek'):
results += r
self.assertIn('rnv', results)

0 comments on commit 05818b8

Please sign in to comment.