def merge(self): uri = 'projects/{}/repos/{}/pull-requests/{}/merge'.format( self.fromRef.repository.project.name, self.fromRef.repository.slug, self.id) url = self._get_url(uri) params = {'version': self.version} r_json = json_loads(self._session.post(url, params=params)) commit = Commit(self._options, self._session, r_json) return commit
def projects(self): url = self._options['server'] + '/rest/api/1.0/projects' r_json = json_loads(self._session.get(url)) projects = [ Project(self._options, self._session, raw_project_json) for raw_project_json in r_json['values'] ] return projects
def repos(self, **params): url = self._options[ 'server'] + '/rest/api/1.0/projects/{}/repos'.format(self.name) if not params: params = {'limit': 1000} r_json = json_loads(self._session.get(url, params=params)) repos = [ Repo(self._options, self._session, raw_repo_json) for raw_repo_json in r_json['values'] ] return repos
def pull_requests(self, **params): uri = 'projects/{}/repos/{}/pull-requests'.format( self.project.name, self.name) url = self._get_url(uri) if not params: params = {'state': 'merged', 'limit': 1000} r_json = json_loads(self._session.get(url, params=params)) # print r_json pull_requests = [ PullRequest(self._options, self._session, raw_repo_json) for raw_repo_json in r_json['values'] ] return pull_requests
def _load(self, url, headers=CaseInsensitiveDict(), params=None, path=None): r = self._session.get(url, headers=headers, params=params) try: j = json_loads(r) except ValueError as e: logging.error("%s:\n%s" % (e, r.text)) raise e if path: j = j[path] self._parse_raw(j)
def latest_merge_commit(self, **params): uri = 'projects/{0}/repos/{1}/commits'.format(self.project.name, self.name) url = self._get_url(uri) if not params: params['merges'] = 'only' params['limit'] = 1000 r_json = json_loads(self._session.get(url, params=params)) # print r_json commits = [ Commit(self._options, self._session, raw_commit_json) for raw_commit_json in r_json['values'] ] if commits: target_commit = commits[0] else: target_commit = {'status': 'Failed', 'reason': 'No merges so far'} return target_commit
def get_merge_commit(self, **params): target_commit = None uri = 'projects/{0}/repos/{1}/commits'.format( self.fromRef.repository.project.name, self.fromRef.repository.name) url = self._get_url(uri) if not params: params['merges'] = 'only' params['limit'] = 1000 r_json = json_loads(self._session.get(url, params=params)) # print r_json commits = [ Commit(self._options, self._session, raw_commit_json) for raw_commit_json in r_json['values'] ] msg = 'Merge pull request #{0} '.format(self.id) for commit in commits: if commit.message.startswith(msg): target_commit = commit break return target_commit
def can_merge(self, **params): if self.state == 'MERGED': commit = self.get_merge_commit() if isinstance(commit, Commit): commit_id = commit.displayId else: commit_id = 'Failed to fetch commitID' return { 'canMerge': False, 'reason': 'Already merged', 'commit': commit_id } unapproved = True for self.reviewer in self.reviewers: if self.reviewer.status == 'APPROVED': unapproved = False if unapproved: return {'canMerge': False, 'reason': 'Review incomplete'} uri = 'projects/{}/repos/{}/pull-requests/{}/merge'.format( self.fromRef.repository.project.name, self.fromRef.repository.slug, self.id) url = self._get_url(uri) r_json = json_loads(self._session.get(url, params=params)) if r_json.has_key('canMerge') and r_json['canMerge'] is False \ and r_json.has_key('outcome') and r_json['outcome'] == 'CONFLICTED': return {'canMerge': False, 'reason': 'Merge conflicts'} if r_json.has_key('errors'): return {'canMerge': False, 'reason': r_json['errors']} return {'canMerge': True, 'reason': ''}