From 0973ae90787a022bfabb6002e89d8521800d5680 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 29 2017 16:40:28 +0000 Subject: [PATCH 1/5] Do not send a notification upon merge conflicts Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/git.py b/pagure/lib/git.py index be31716..03c3b58 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -1239,7 +1239,7 @@ def merge_pull_request( try: tree = new_repo.index.write_tree() except pygit2.GitError as err: - _log.exception( + _log.debug( ' Could not write down the new tree: merge conflicts') shutil.rmtree(newpath) if domerge: From d49b8c72b26b3903f9acc9516e21720cee51ee56 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 29 2017 16:40:28 +0000 Subject: [PATCH 2/5] Do not let pagure return 500 when hit with bogus URL This should among other stop having pagure return 500 errors and email the admins when the URL accessed is, for example: https://pagure.io/apple-touch-icon-152x152-precomposed.png Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index bf80055..e5415d4 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -731,6 +731,9 @@ def view_commit(repo, commitid, username=None, namespace=None): """ Render a commit in a repo """ repo = flask.g.repo + if not repo: + flask.abort(404, 'Project not found') + repo_obj = flask.g.repo_obj branchname = flask.request.args.get('branch', None) diff --git a/tests/test_pagure_flask_ui_old_commit.py b/tests/test_pagure_flask_ui_old_commit.py index d42d80a..ac09026 100644 --- a/tests/test_pagure_flask_ui_old_commit.py +++ b/tests/test_pagure_flask_ui_old_commit.py @@ -44,18 +44,27 @@ class PagureFlaskRepoOldUrltests(tests.Modeltests): pagure.ui.filters.SESSION = self.session pagure.ui.repo.SESSION = self.session - pagure.APP.config['OLD_VIEW_COMMIT_ENABLED'] = True pagure.APP.config['EMAIL_SEND'] = False pagure.APP.config['UPLOAD_FOLDER_PATH'] = os.path.join( self.path, 'releases') - def tearDown(self): - """ Tear down the environnment, after every tests. """ - super(PagureFlaskRepoOldUrltests, self).tearDown() + @patch.dict('pagure.APP.config', {'OLD_VIEW_COMMIT_ENABLED': True}) + def test_view_commit_old(self): + """ Test the view_commit_old endpoint. """ - pagure.APP.config['EMAIL_SEND'] = False - pagure.APP.config['OLD_VIEW_COMMIT_ENABLED'] = False + tests.create_projects(self.session) + tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) + + # Add a README to the git repo - First commit + tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git')) + repo = pygit2.Repository(os.path.join(self.path, 'repos', 'test.git')) + commit = repo.revparse_single('HEAD') + + # View first commit + output = self.app.get('/apple-touch-icon-152x152-precomposed.png') + self.assertEqual(output.status_code, 404) + @patch.dict('pagure.APP.config', {'OLD_VIEW_COMMIT_ENABLED': True}) def test_view_commit_old(self): """ Test the view_commit_old endpoint. """ From d48706272952731af4f77cc2b193175c1445ba01 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 29 2017 16:40:28 +0000 Subject: [PATCH 3/5] When loading comment from JSON rely on username/comment rather than comment id Instead of relying on comment id which may vary from instance to instance depending on what is in the database, use the combo username/comment to find out if a comment was already made to the ticket (so that if not, it gets created). We are short-coming the case where the same user submits twice the exact same comment, so be it. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 73582ad..307119a 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -2586,6 +2586,23 @@ def get_issue_comment(session, issue_uid, comment_id): return query.first() +def get_issue_comment_by_user_and_comment( + session, issue_uid, user_id, content): + ''' Return a specific comment of a specified issue. + ''' + query = session.query( + model.IssueComment + ).filter( + model.IssueComment.issue_uid == issue_uid + ).filter( + model.IssueComment.user_id == user_id + ).filter( + model.IssueComment.comment == content + ) + + return query.first() + + def get_request_comment(session, request_uid, comment_id): ''' Return a specific comment of a specified request. ''' diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 03c3b58..486b76f 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -601,8 +601,8 @@ def update_ticket_from_git( for comment in json_data['comments']: usercomment = get_user_from_json(session, comment) - commentobj = pagure.lib.get_issue_comment( - session, issue_uid, comment['id']) + commentobj = pagure.lib.get_issue_comment_by_user_and_comment( + session, issue_uid, usercomment.id, comment['comment']) if not commentobj: pagure.lib.add_issue_comment( session, From 7b6a9d15cf1c47a0c9e4d1e83043213fd786c9bb Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 29 2017 16:40:28 +0000 Subject: [PATCH 4/5] Assume the data provided are already UTC Otherwise, if the server itself doesn't run on the UTC timezone the date ends up being converted to UTC, potentially a second time then. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 486b76f..8ab5afc 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -611,7 +611,7 @@ def update_ticket_from_git( user=usercomment.username, ticketfolder=None, notify=False, - date_created=datetime.datetime.utcfromtimestamp( + date_created=datetime.datetime.fromtimestamp( float(comment['date_created'])), ) From 34cca18b04dd38db4888120f58e8fa816ddef9b2 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 29 2017 16:40:28 +0000 Subject: [PATCH 5/5] When deleting a comment, refresh the ticket git repo Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py index 76033a6..34954de 100644 --- a/pagure/ui/issues.py +++ b/pagure/ui/issues.py @@ -131,6 +131,10 @@ def update_issue(repo, issueid, username=None, namespace=None): issue.last_updated = datetime.datetime.utcnow() SESSION.add(issue) SESSION.delete(comment) + pagure.lib.git.update_git( + issue, + repo=issue.project, + repofolder=APP.config['TICKETS_FOLDER']) try: SESSION.commit() if not is_js: