From 49f9801a6d7ae1a99a5874482a2349b39d5f71b0 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 02 2015 12:11:37 +0000 Subject: [PATCH 1/5] Add a method to retrieve the tags object rather than their name --- diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 6ae3dee..dde2750 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -935,3 +935,17 @@ def get_git_tags(project): if 'refs/tags/' in tag ] return tags + + +def get_git_tags_objects(project): + """ Returns the list of references of the tags created in the git + repositorie the specified project. + """ + repopath = pagure.get_repo_path(project) + repo_obj = pygit2.Repository(repopath) + tags = [ + repo_obj.lookup_reference(tag) + for tag in repo_obj.listall_references() + if 'refs/tags/' in tag + ] + return tags From 0197ec7d29fbd3a372157821a2e7d591566d37b0 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 02 2015 12:18:01 +0000 Subject: [PATCH 2/5] Adjust style and inline comment --- diff --git a/tests/test_progit_flask_api_project.py b/tests/test_progit_flask_api_project.py index 0795d1b..957f590 100644 --- a/tests/test_progit_flask_api_project.py +++ b/tests/test_progit_flask_api_project.py @@ -93,8 +93,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): "0.0.1", first_commit.oid.hex, pygit2.GIT_OBJ_COMMIT, tagger, "Release 0.0.1") - - # Close PR + # Check tags output = self.app.get('/api/0/test/git/tags') self.assertEqual(output.status_code, 200) data = json.loads(output.data) From f63ab53bc720a44bf0618e9c84149e1b16d93c9f Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 02 2015 12:18:17 +0000 Subject: [PATCH 3/5] Add a new endpoint view_tags presenting the tags in a project --- diff --git a/pagure/static/pagure.css b/pagure/static/pagure.css index a12b094..a75c4be 100644 --- a/pagure/static/pagure.css +++ b/pagure/static/pagure.css @@ -370,7 +370,8 @@ pre { } .tree_list .view_commit, -.tree_list .filehex +.tree_list .filehex, +.tag_list .tagid { float: right; text-align: right; @@ -378,6 +379,7 @@ pre { .tree_list li:nth-child(odd), .commit_list li:nth-child(odd), +.tag_list li:nth-child(odd), table.list tr:nth-child(odd) td { background-color: #ededed; @@ -387,21 +389,25 @@ table.list tr:nth-child(odd) td padding-left: 25px; } -.commit_list ul { +.commit_list ul, +.tag_list ul, { padding-left: 0; } -.commit_list li { +.commit_list li, +.tag_list li { list-style-type: none; } .commit_list li, -.tree_list li { +.tree_list li, +.tag_list li { padding:0 .5em; } .tree_list li:hover, .commit_list li:hover, +.tag_list li:hover, table.list tr:hover td { @@ -411,7 +417,9 @@ table.list tr:hover td .tree_list li:hover a, .commit_list li:hover a, +.tag_list li:hover a, .commit_list li:hover > a > span.commitid, +.tag_list li:hover > a > span.tagid, .commit_list li:hover > a > span.commitdate, .tree_list li:hover > a > span.filehex, table.list tr:hover td > a @@ -420,12 +428,14 @@ table.list tr:hover td > a } .commit_list li > a:first-child, .tree_list li > a:first-child, +.tag_list li > a:first-child, table.list tbody td > a { display: block; } .commit_list li > a > span.commitid, +.tag_list li > a > span.tagid, .tree_list li > a > span.filehex { color: #4d4d4d; diff --git a/pagure/templates/tags.html b/pagure/templates/tags.html new file mode 100644 index 0000000..0ddba2e --- /dev/null +++ b/pagure/templates/tags.html @@ -0,0 +1,31 @@ +{% extends "repo_master.html" %} + +{% block title %}Tags - {{ repo.name }}{% endblock %} +{%block tag %}home{% endblock %} + + +{% block repo %} + +

Tags

+ +
+ {% if tags %} + + {% else %} +

+ This project has not been tagged. +

+ {% endif %} +
+ +{% endblock %} diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 00639d0..b47307d 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -620,6 +620,29 @@ def view_forks(repo, username=None): ) +@APP.route('//tags/') +@APP.route('//tags') +@APP.route('/fork///tags/') +@APP.route('/fork///tags') +def view_tags(repo, username=None): + """ Presents all the tags of the project. + """ + repo = pagure.lib.get_project(SESSION, repo, user=username) + + if not repo: + flask.abort(404, 'Project not found') + + tags = pagure.lib.git.get_git_tags_objects(repo) + + return flask.render_template( + 'tags.html', + select='tags', + username=username, + repo=repo, + tags=tags, + ) + + @APP.route('//settings/', methods=('GET', 'POST')) @APP.route('//settings', methods=('GET', 'POST')) @APP.route('/fork///settings/', methods=('GET', 'POST')) From d5c0123ce09945e94b52b553dcbcf8a73ffb32da Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 02 2015 12:18:31 +0000 Subject: [PATCH 4/5] Add unit-tests for the view_tags endpoint --- diff --git a/tests/test_progit_flask_ui_repo.py b/tests/test_progit_flask_ui_repo.py index 20e0212..5e0bce4 100644 --- a/tests/test_progit_flask_ui_repo.py +++ b/tests/test_progit_flask_ui_repo.py @@ -183,7 +183,6 @@ class PagureFlaskRepotests(tests.Modeltests): self.assertTrue( '
  • Group added
  • ' in output.data) - @patch('pagure.ui.repo.admin_session_timedout') def test_remove_user(self, ast): """ Test the remove_user endpoint. """ @@ -1544,6 +1543,39 @@ index 0000000..fb7093d '
  • Requests git repo updated
  • ', output.data) + def test_view_tags(self): + """ Test the view_tags endpoint. """ + output = self.app.get('/foo/tags') + # No project registered in the DB + self.assertEqual(output.status_code, 404) + + tests.create_projects(self.session) + + output = self.app.get('/test/tags') + # No git repo associated + self.assertEqual(output.status_code, 404) + + tests.create_projects_git(tests.HERE) + + output = self.app.get('/test/tags') + self.assertEqual(output.status_code, 200) + self.assertIn('This project has not been tagged.', output.data) + + # Add a README to the git repo - First commit + tests.add_readme_git_repo(os.path.join(tests.HERE, 'test.git')) + repo = pygit2.init_repository(os.path.join(tests.HERE, 'test.git')) + first_commit = repo.revparse_single('HEAD') + tagger = pygit2.Signature('Alice Doe', 'adoe@example.com', 12347, 0) + repo.create_tag( + "0.0.1", first_commit.oid.hex, pygit2.GIT_OBJ_COMMIT, tagger, + "Release 0.0.1") + + output = self.app.get('/test/tags') + self.assertEqual(output.status_code, 200) + self.assertIn('0.0.1', output.data) + self.assertIn('', output.data) + self.assertTrue(output.data.count('tagid'), 1) + if __name__ == '__main__': SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureFlaskRepotests) From 3112e97afecc8c0b61a9d623d39ebb1637fe516d Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 02 2015 12:20:18 +0000 Subject: [PATCH 5/5] Link the page listing all tags to the main repo menu --- diff --git a/pagure/templates/repo_master.html b/pagure/templates/repo_master.html index 3622dc1..70c8203 100644 --- a/pagure/templates/repo_master.html +++ b/pagure/templates/repo_master.html @@ -54,6 +54,11 @@ repo=repo.name, identifier=branchname) }}">Tree +
  • + Tags +
  • + {% if repo.settings.get('issue_tracker', True) %}