Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit 47725ef55cdcfea42c4966f6c1bfb43fd94a7c1f
Author: Tomas Radej <tradej(a)redhat.com>
Date: Thu May 16 16:45:10 2013 +0200
Repo file generation + GUI link
---------------------------------------------------------------
coprs_frontend/coprs/templates/coprs/copr.repo | 6 +++
.../coprs/templates/coprs/detail/overview.html | 4 ++
.../coprs/views/coprs_ns/coprs_general.py | 33 ++++++++++++++++++++
.../test_views/test_coprs_ns/test_coprs_general.py | 32 +++++++++++++++++++
4 files changed, 75 insertions(+), 0 deletions(-)
diff --git a/coprs_frontend/coprs/templates/coprs/copr.repo
b/coprs_frontend/coprs/templates/coprs/copr.repo
new file mode 100644
index 0000000..7833fd9
--- /dev/null
+++ b/coprs_frontend/coprs/templates/coprs/copr.repo
@@ -0,0 +1,6 @@
+[{{ copr.owner.name }}-{{ copr.name }}]
+
+name=Copr repo for {{ copr.name }} owned by {{ copr.owner.name }}
+description={{ copr.description }}
+baseurl={{ url }}
+skip_if_unavailable=True
diff --git a/coprs_frontend/coprs/templates/coprs/detail/overview.html
b/coprs_frontend/coprs/templates/coprs/detail/overview.html
index a038913..d924378 100644
--- a/coprs_frontend/coprs/templates/coprs/detail/overview.html
+++ b/coprs_frontend/coprs/templates/coprs/detail/overview.html
@@ -9,6 +9,10 @@
<div class="shift-right">{{ copr.description_or_not_filled
}}</div>
<h2>Installation Instructions</h2>
<div class="shift-right">{{
copr.instructions_or_not_filled}}</div>
+ <h2>Yum repo</h2>
+ <div class="shift-right">
+ <a href="{{ url_for('coprs_ns.generate_repo_file',
reponame=copr.owner.name+'-'+copr.name) }}">
+ {{ copr.owner.name }}-{{ copr.name }}.repo</a></div>
<h2>Active Releases</h2>
<table class="releases">
<tr>
diff --git a/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
b/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
index 9d5be98..34f62a1 100644
--- a/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
+++ b/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
@@ -272,3 +272,36 @@ def copr_legal_flag(username, coprname):
db.session.commit()
flask.flash('Admin was noticed about your report and will investigate the copr
shortly.')
return flask.redirect(flask.url_for('coprs_ns.copr_detail',
username=username, coprname=coprname))
+
+(a)coprs_ns.route('/repo/<reponame>.repo')
+def generate_repo_file(reponame):
+ ''' Generate repo file for a given repo name.
+ Reponame = username-coprname '''
+ # This solution is used because flask splits off the last part after a
+ # dash, therefore user-re-po resolves to user-re/po instead of user/re-po
+ # FAS usernames may not contain dashes, so this construction is safe.
+
+ if '-' not in reponame:
+ return page_not_found('Bad repository name: {0}. Must be
username-coprname'.format(reponame))
+
+ username, coprname = reponame.split('-', 1)
+ copr = None
+ try:
+ # query.one() is used since it fetches all builds, unlike query.first().
+ copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname,
+ with_builds=True).one()
+ except sqlalchemy.orm.exc.NoResultFound:
+ return page_not_found('Copr {0}/{1} does not exist'.format(username,
coprname))
+
+ url = ''
+ for build in copr.builds:
+ if build.results:
+ url = build.results
+ break
+
+ if not url:
+ return page_not_found('Repository not initialized: No finished builds in
{0}/{1}.'.format(username, coprname))
+
+ response = flask.make_response(flask.render_template('coprs/copr.repo',
copr=copr, url=url))
+ response.mimetype='text/plain'
+ return response
diff --git a/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py
b/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py
index 380d59d..906ece1 100644
--- a/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py
+++ b/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py
@@ -1,4 +1,5 @@
import flask
+import pytest
from flexmock import flexmock
@@ -456,3 +457,34 @@ class TestCoprDelete(CoprsTestCase):
assert 'Copr was deleted successfully' not in r.data
assert not self.models.Action.query.first()
assert
self.models.Copr.query.filter(self.models.Copr.id==self.c1.id).first()
+
+class TestCoprRepoGeneration(CoprsTestCase):
+ @pytest.fixture
+ def f_custom_builds(self):
+ ''' Custom builds are used in order not to break the default ones
'''
+ self.b5 = self.models.Build(copr=self.c1, user=self.u1,
chroots='fedora-18-x86_64', submitted_on=9, ended_on=200,
results='foo://bar.baz', status=1)
+ self.b6 = self.models.Build(copr=self.c1, user=self.u1,
chroots='fedora-18-x86_64', submitted_on=11)
+ self.b7 = self.models.Build(copr=self.c1, user=self.u1,
chroots='fedora-18-x86_64', submitted_on=10, ended_on=150,
results='foo://bar.baz', status=1)
+
+ self.db.session.add_all([self.b5, self.b6, self.b7])
+
+ def test_fail_on_missing_dash(self):
+ r = self.tc.get('/coprs/repo/reponamewithoutdash.repo')
+ assert r.status_code == 404
+ assert 'Bad repository name' in r.data
+
+ def test_fail_on_nonexistent_copr(self):
+ r = self.tc.get('/coprs/repo/bogus-nonexistent-repo.repo')
+ assert r.status_code == 404
+ assert 'bogus/nonexistent-repo does not exist' in r.data
+
+ def test_fail_on_no_finished_builds(self, f_users, f_coprs, f_db):
+ r = self.tc.get(
+ '/coprs/repo/{0}-{1}.repo'.format(self.u1.name, self.c1.name))
+ assert r.status_code == 404
+ assert 'Repository not initialized' in r.data
+
+ def test_works_on_older_builds(self, f_users, f_coprs, f_custom_builds, f_db):
+ r = self.tc.get('/coprs/repo/{0}-{1}.repo'.format(self.u1.name,
self.c1.name))
+ assert r.status_code == 200
+ assert 'baseurl=foo://bar.baz' in r.data