-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #169
- Loading branch information
Showing
6 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |