def _downloadPullRequestFromGitHub(self, projectId, pullRequestId): try: repo = self.gh.get_repo(projectId) except github.UnknownObjectException: raise InvalidProjectIdException() try: pull = repo.get_pull(pullRequestId) except github.UnknownObjectException: raise InvalidPullRequestIdException() pullPath = self._getPullRequestPath(projectId, pullRequestId) if self._pullRequestCopyIsUpToDate(pull, pullPath): return False retries = 0 while 1: shutil.rmtree(pullPath, True) util.makedirsIfNotExists(pullPath) try: self._downloadPullRequestData(pull, pullPath) break except Exception, e: if retries >= options.MAX_DOWNLOAD_RETRIES: cherrypy.log.error(traceback.format_exc()) raise FailedToDownloadPullRequestException(cause=e) else: cherrypy.log.error( "Failed to download pull request %s #%d. Retrying..." % (projectId, pullRequestId) ) retries += 1
def setUp(self): self.controller = PartitionController() self.projectOwner = 'victorclf' self.projectName = 'jcc-web-persontest' self.projectId = '%s/%s' % (self.projectOwner, self.projectName) self.pullRequestId = 1 self.pullPath = os.path.join(options.PULL_REQUESTS_PATH, self.projectOwner, self.projectName, str(self.pullRequestId)) self.tearDown() util.makedirsIfNotExists(options.PULL_REQUESTS_PATH) shutil.copytree(os.path.join(self.TEST_DATA_PATH, self.projectOwner), os.path.join(options.PULL_REQUESTS_PATH, self.projectOwner), ignore=lambda root,files: [f for f in files if f.endswith('.old')])