diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index d925580..b53456d 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -1437,6 +1437,15 @@ def new_issue(session, repo, title, content, user, ticketfolder, issue_id=None, ''' Create a new issue for the specified repo. ''' user_obj = get_user(session, user) + # Only store the priority if there is one in the project + priorities = repo.priorities + try: + priority = int(priority) + except (ValueError, TypeError): + priority = None + if str(priority) not in priorities: + priority = None + issue = model.Issue( id=issue_id or get_next_id(session, repo.id), project_id=repo.id, diff --git a/tests/test_pagure_lib_git.py b/tests/test_pagure_lib_git.py index e570007..e7ebd11 100644 --- a/tests/test_pagure_lib_git.py +++ b/tests/test_pagure_lib_git.py @@ -1557,6 +1557,25 @@ index 0000000..60f7480 "priority": 1, } + # Create the issue + pagure.lib.git.update_ticket_from_git( + self.session, reponame='test', namespace=None, username=None, + issue_uid='foobar', json_data=data + ) + self.session.commit() + + # Data contained a priority but not the project, so bailing + self.assertEqual(len(repo.issues), 1) + self.assertEqual(repo.issues[0].id, 1) + self.assertEqual(repo.issues[0].uid, 'foobar') + self.assertEqual(repo.issues[0].title, 'foo') + self.assertEqual(repo.issues[0].depending_text, []) + self.assertEqual(repo.issues[0].blocking_text, []) + self.assertEqual(repo.issues[0].milestone, 'Next Release') + self.assertEqual(repo.issues[0].priority, None) + self.assertEqual(repo.milestones, {'Next Release': None}) + + # Edit the issue pagure.lib.git.update_ticket_from_git( self.session, reponame='test', namespace=None, username=None, issue_uid='foobar', json_data=data