def update_from_pending_change(self, commit_id, changeset): """Updates the data from a server-side pending changeset. This will fetch the metadata from the server and update the fields on the review request. """ if not changeset: raise InvalidChangeNumberError() # If the SCM supports changesets, they should always include a number, # summary and description, parsed from the changeset description. Some # specialized systems may support the other fields, but we don't want # to clobber the user-entered values if they don't. self.commit = commit_id description = changeset.description testing_done = changeset.testing_done self.summary = changeset.summary self.description = description self.description_rich_text = False if testing_done: self.testing_done = testing_done self.testing_done_rich_text = False if changeset.branch: self.branch = changeset.branch if changeset.bugs_closed: self.bugs_closed = ','.join(changeset.bugs_closed)
def update_from_commit_id(self, commit_id): """Updates the data from a server-side changeset. If the commit ID refers to a pending changeset on an SCM which stores such things server-side (like perforce), the details like the summary and description will be updated with the latest information. If the change number is the commit ID of a change which exists on the server, the summary and description will be set from the commit's message, and the diff will be fetched from the SCM. """ scmtool = self.repository.get_scmtool() changeset = None if scmtool.supports_pending_changesets: changeset = scmtool.get_changeset(commit_id, allow_empty=True) if changeset and changeset.pending: self.update_from_pending_change(commit_id, changeset) elif self.repository.supports_post_commit: self.update_from_committed_change(commit_id) else: if changeset: raise InvalidChangeNumberError() else: raise NotImplementedError()
def update_from_pending_change(self, commit_id, changeset): """Update the data from a server-side pending changeset. This will fetch the metadata from the server and update the fields on the draft. Args: commit_id (unicode): The changeset ID that the draft will update from. changeset (reviewboard.scmtools.core.ChangeSet): The changeset information to update from. Returns: list of unicode: The list of draft fields that have been updated from the change. """ if not changeset: raise InvalidChangeNumberError() # If the SCM supports changesets, they should always include a number, # summary and description, parsed from the changeset description. Some # specialized systems may support the other fields, but we don't want # to clobber the user-entered values if they don't. self.commit = commit_id description = changeset.description testing_done = changeset.testing_done self.summary = changeset.summary self.description = description self.description_rich_text = False modified_fields = [ 'commit_id', 'summary', 'description', 'description_rich_text', ] if testing_done: self.testing_done = testing_done self.testing_done_rich_text = False modified_fields += ['testing_done', 'testing_done_rich_text'] if changeset.branch: self.branch = changeset.branch modified_fields.append('branch') if changeset.bugs_closed: self.bugs_closed = ','.join(changeset.bugs_closed) modified_fields.append('bugs_closed') return modified_fields
def update_from_commit_id(self, commit_id): """Update the data from a server-side changeset. If the commit ID refers to a pending changeset on an SCM which stores such things server-side (like Perforce), the details like the summary and description will be updated with the latest information. If the change number is the commit ID of a change which exists on the server, the summary and description will be set from the commit's message, and the diff will be fetched from the SCM. Args: commit_id (unicode): The commit ID or changeset ID that the draft will update from. Returns: list of unicode: The list of draft fields that have been updated from the commit. Raises: reviewboard.hostingsvcs.errors.HostingServiceError: The hosting service backing the repository encountered an error. reviewboard.scmtools.errors.InvalidChangeNumberError: The commit ID could not be found in the repository. reviewboard.scmtools.errors.SCMError: The repository tool encountered an error. NotImplementedError: The repository does not support fetching information from commit IDs. """ scmtool = self.repository.get_scmtool() changeset = None if scmtool.supports_pending_changesets: changeset = scmtool.get_changeset(commit_id, allow_empty=True) if changeset and changeset.pending: return self.update_from_pending_change(commit_id, changeset) elif self.repository.supports_post_commit: return self.update_from_committed_change(commit_id) else: if changeset: raise InvalidChangeNumberError() else: raise NotImplementedError()
except NotImplementedError: # This scmtool doesn't have changesets pass except SCMError, e: self.errors['changenum'] = forms.util.ErrorList([str(e)]) raise ChangeSetError() except ChangeSetError, e: self.errors['changenum'] = forms.util.ErrorList([str(e)]) raise e if not changeset: self.errors['changenum'] = forms.util.ErrorList([ 'This change number does not represent a valid ' 'changeset.' ]) raise InvalidChangeNumberError() if user.username != changeset.username: self.errors['changenum'] = forms.util.ErrorList( ['This change number is owned by another user.']) raise OwnershipError() try: review_request = ReviewRequest.objects.create( user, repository, changenum, local_site) except ChangeNumberInUseError: # The user is updating an existing review request, rather than # creating a new one. review_request = ReviewRequest.objects.get(changenum=changenum, repository=repository) review_request.update_from_changenum(changenum)