Esempio n. 1
0
    def collab(self, commit, author=None):
        '''
        Creates a code review in code collaborator from the git logs if there is
        a 'reviewers' annotation in the commit message
        '''
        if 'reviewers' in commit['annotations']:
            reviewers = commit['annotations']['reviewers']
            cc = CodeCollabClient()
            review_id = cc.create_collab(commit['title'], commit['overview'])
            if author is None:
                author = cc.get_current_user()
            cc.add_reviewers(review_id, author, reviewers)
            cc.add_diffs(review_id, commit['unified_diff'])
            cc.done(review_id)

            work_name = self.get_work_name(commit)
            if work_name is not None:
                gus = self.__gus_session__(commit)
                work = gus.find_work(work_name)
                gus.add_collab_link(work, cc.get_review_link(review_id))

            print 'Created code review %s for author %s' % (review_id, author)
        elif 'update_review' in commit['annotations']:
            review_id = commit['annotations']['update_review']
            cc = CodeCollabClient()
            cc.add_diffs(review_id,
                         commit['unified_diff'],
                         comment='Updated Files from Commit')
            cc.add_comment(review_id, commit['title'])
            print 'Updated review %s with changes from commit' % review_id
        else:
            print 'No reviewers specified for commit, can\'t create review.  Use @reviewers or @update_review'
Esempio n. 2
0
    def remote(self, server='localhost:8000'):
        ''' 
        Establishes identities for GUS and Code collab for proxy ticket update
        and code review creation.  Code collab client cannot activate review for
        remote.
        '''
        gus = BacklogClient()
        session_id = gus.session_id()
        cc = CodeCollabClient()
        author = cc.get_current_user()
        mrhat = MrHat()
        creds = mrhat.get_current_creds()
        commit = self.buildCommit()
        commit['gus_session'] = session_id
        commit['collab_user'] = author
        commit['jenkins_user'] = creds[0]
        commit['jenkins_token'] = creds[1]

        conn = httplib.HTTPConnection(server)
        head = {
            'Content-Type': 'application/json',
            'Accept': 'application/json'
        }
        conn.request('POST', '/service/post', json.dumps(commit), head)
        response = conn.getresponse()
        data = response.read()
        conn.close()

        print data
Esempio n. 3
0
    def validate(self, comment):
        messages = []
        annotations = comment.annotations()
        
        if 'update_review' in annotations:
            cc = CodeCollabClient()
            user = cc.get_current_user()
            author = cc.get_review_author(annotations['update_review'])
            if user != author:
                messages.append("You are not the author of review %s.  Please ensure you have the correct review id for @update_review." % annotations['update_review'])
                
            status = cc.get_review_status(annotations['update_review'])
            if status == 'Completed':
                messages.append("The review specified (%s) is already Complete.  Create a new review with @reviewers" % annotations['update_review'])

        return messages