# HG changeset patch # User Marcin Kuzminski # Date 1358620957 -3600 # Node ID 5d1d25c1c700bc5bd75891ee03355fda06ff1188 # Parent 37c0ac5fe42f76ee72fe75c48c4cc858d15bafef set the status of changesets initially on pull request, and make sure we care of version collisions. Fixes issues #690 and #587 diff -r 37c0ac5fe42f -r 5d1d25c1c700 rhodecode/controllers/pullrequests.py --- a/rhodecode/controllers/pullrequests.py Sat Jan 19 18:20:52 2013 +0100 +++ b/rhodecode/controllers/pullrequests.py Sat Jan 19 19:42:37 2013 +0100 @@ -224,6 +224,7 @@ h.flash(_('Successfully opened new pull request'), category='success') except Exception: + raise h.flash(_('Error occurred during sending pull request'), category='error') log.error(traceback.format_exc()) diff -r 37c0ac5fe42f -r 5d1d25c1c700 rhodecode/model/changeset_status.py --- a/rhodecode/model/changeset_status.py Sat Jan 19 18:20:52 2013 +0100 +++ b/rhodecode/model/changeset_status.py Sat Jan 19 19:42:37 2013 +0100 @@ -111,22 +111,17 @@ st = status or ChangesetStatus.DEFAULT return str(st) - def set_status(self, repo, status, user, comment, revision=None, + def set_status(self, repo, status, user, comment=None, revision=None, pull_request=None, dont_allow_on_closed_pull_request=False): """ Creates new status for changeset or updates the old ones bumping their version, leaving the current status at :param repo: - :type repo: :param revision: - :type revision: :param status: - :type status: :param user: - :type user: :param comment: - :type comment: :param dont_allow_on_closed_pull_request: don't allow a status change if last status was for pull request and it's closed. We shouldn't mess around this manually @@ -134,14 +129,21 @@ repo = self._get_repo(repo) q = ChangesetStatus.query() - + if not comment: + from rhodecode.model.comment import ChangesetCommentsModel + comment = ChangesetCommentsModel().create( + text='Auto status change', + repo=repo, + user=user, + pull_request=pull_request, + ) if revision: q = q.filter(ChangesetStatus.repo == repo) q = q.filter(ChangesetStatus.revision == revision) elif pull_request: pull_request = self.__get_pull_request(pull_request) q = q.filter(ChangesetStatus.repo == pull_request.org_repo) - q = q.filter(ChangesetStatus.pull_request == pull_request) + q = q.filter(ChangesetStatus.revision.in_(pull_request.revisions)) cur_statuses = q.all() #if statuses exists and last is associated with a closed pull request @@ -153,6 +155,7 @@ 'Changing status on closed pull request is not allowed' ) + #update all current statuses with older version if cur_statuses: for st in cur_statuses: st.version += 1 diff -r 37c0ac5fe42f -r 5d1d25c1c700 rhodecode/model/forms.py --- a/rhodecode/model/forms.py Sat Jan 19 18:20:52 2013 +0100 +++ b/rhodecode/model/forms.py Sat Jan 19 19:42:37 2013 +0100 @@ -365,7 +365,8 @@ org_ref = v.UnicodeString(strip=True, required=True) other_repo = v.UnicodeString(strip=True, required=True) other_ref = v.UnicodeString(strip=True, required=True) - revisions = All(v.NotReviewedRevisions(repo_id)(), v.UniqueList(not_empty=True)) + revisions = All(#v.NotReviewedRevisions(repo_id)(), + v.UniqueList(not_empty=True)) review_members = v.UniqueList(not_empty=True) pullrequest_title = v.UnicodeString(strip=True, required=True, min=3) diff -r 37c0ac5fe42f -r 5d1d25c1c700 rhodecode/model/pull_request.py --- a/rhodecode/model/pull_request.py Sat Jan 19 18:20:52 2013 +0100 +++ b/rhodecode/model/pull_request.py Sat Jan 19 19:42:37 2013 +0100 @@ -33,7 +33,8 @@ from rhodecode.model.meta import Session from rhodecode.lib import helpers as h from rhodecode.model import BaseModel -from rhodecode.model.db import PullRequest, PullRequestReviewers, Notification +from rhodecode.model.db import PullRequest, PullRequestReviewers, Notification,\ + ChangesetStatus from rhodecode.model.notification import NotificationModel from rhodecode.lib.utils2 import safe_unicode @@ -54,8 +55,9 @@ repo = self._get_repo(repo) return PullRequest.query().filter(PullRequest.other_repo == repo).all() - def create(self, created_by, org_repo, org_ref, other_repo, - other_ref, revisions, reviewers, title, description=None): + def create(self, created_by, org_repo, org_ref, other_repo, other_ref, + revisions, reviewers, title, description=None): + from rhodecode.model.changeset_status import ChangesetStatusModel created_by_user = self._get_user(created_by) org_repo = self._get_repo(org_repo) @@ -78,6 +80,14 @@ reviewer = PullRequestReviewers(_usr, new) self.sa.add(reviewer) + #reset state to under-review + ChangesetStatusModel().set_status( + repo=org_repo, + status=ChangesetStatus.STATUS_UNDER_REVIEW, + user=created_by_user, + pull_request=new + ) + #notification to reviewers notif = NotificationModel() diff -r 37c0ac5fe42f -r 5d1d25c1c700 rhodecode/templates/pullrequests/pullrequest_show.html --- a/rhodecode/templates/pullrequests/pullrequest_show.html Sat Jan 19 18:20:52 2013 +0100 +++ b/rhodecode/templates/pullrequests/pullrequest_show.html Sat Jan 19 19:42:37 2013 +0100 @@ -65,7 +65,7 @@ ${c.pull_request.org_ref_parts[0]} : ${c.pull_request.org_ref_parts[1]} - ${c.pull_request.org_repo.clone_url()} + ${c.pull_request.org_repo.clone_url()}