def commits_by_path(self, request): if not self.project: raise api_errors.NotFoundError("project") path = request.get_form_var('path', '') ref = request.get_form_var('ref') or 'HEAD' commits = {'r': 1} cs = {} try: tree = self.project.repo.get_tree(ref, path=path, with_commit=True) for v in tree: k = v['id'] v['message_with_emoji'] = parse_emoji( escape(v['commit']['message'])) author = get_author_by_email( v['commit']['author']['email']) if author: v['contributor'] = author v['contributor_url'] = "%s/people/%s" % (DOMAIN, author) else: v['contributor'] = v['commit']['author']['name'] v['age'] = compute_relative_time(v['commit']['author']['time']) v['sha'] = v['commit']['sha'] v['commit_id'] = v['commit']['sha'] cs[k] = v commits['commits'] = cs except KeyError: commits = {'r': '0', 'err': 'Path not found'} except IOError: commits = {'r': '0', 'err': 'Path not found'} return json.dumps(commits)
def commits_by_path(self, request): if not self.project: raise api_errors.NotFoundError("project") path = request.get_form_var('path', '') ref = request.get_form_var('ref') or 'HEAD' commits = {'r': 1} cs = {} try: tree = self.project.repo.get_tree(ref, path=path, with_commit=True) for v in tree: k = v['id'] v['message_with_emoji'] = parse_emoji( escape(v['commit']['message'])) author = get_author_by_email(v['commit']['author']['email']) if author: v['contributor'] = author v['contributor_url'] = "%s/people/%s" % (DOMAIN, author) else: v['contributor'] = v['commit']['author']['name'] v['age'] = compute_relative_time(v['commit']['author']['time']) v['sha'] = v['commit']['sha'] v['commit_id'] = v['commit']['sha'] cs[k] = v commits['commits'] = cs except KeyError: commits = {'r': '0', 'err': 'Path not found'} except IOError: commits = {'r': '0', 'err': 'Path not found'} return json.dumps(commits)
def get_commits(self, path='', ref='HEAD'): if self.object_type(ref, path) != 'tree': raise IOError('get_commits works on a tree') bag = {} for item in self._list_tree(ref, path): sha = item['id'] bag[sha] = { 'id': sha, 'mode': item['mode'], 'type': item['type'], 'name': item['name'], 'path': item['path'], } latest_commit_sha = self.latest_commit(item['path'], ref) if latest_commit_sha: l_com = self.cat(latest_commit_sha) user = l_com['author']['email'] user_t = user.split('@')[0] if '@' in user else user bag[sha]['contributor'] = user_t if check_douban_email(user): bag[sha]['contributor_url'] = User(user_t).url else: bag[sha]['contributor_url'] = False bag[sha]['message'] = l_com['message'] bag[sha]['hash'] = latest_commit_sha bag[sha]['age'] = compute_relative_time(l_com['author']['ts']) else: bag[sha]['contributor'] = '' bag[sha]['contributor_url'] = '' bag[sha]['message'] = '' bag[sha]['hash'] = '' bag[sha]['age'] = '' return bag
def parse_diff(self, ref='HEAD', ignore_space=False, rename_detection=False): if self.object_type(ref) != 'commit': return False diff_data = self.cat(ref) diffs = {} diffs['parents'] = ' '.join(diff_data['parent']) diffs['author'] = diff_data['author']['name'] diffs['email'] = email_normalizer(diffs['author'], diff_data['author']['email']) diffs['time'] = compute_relative_time(diff_data['author']['ts']) diffs['message'] = diff_data['message'].replace('\n', ' ') diffs['body'] = remove_unknown_character(diff_data['body']) parents = diffs['parents'].split(' ') if parents and parents[0]: diffs['difflist'] = self.get_3dot_diff( parents[0], ref, ignore_space=ignore_space, rename_detection=rename_detection) else: diffs['difflist'] = self._get_diff_for_first_commit(ref, parents) return diffs
def get_revlist(self, max_count=20, skip=0, rev='HEAD', path='', author=None, query=None): commits = [] cs = self._gyt_repo.rev_list(rev, max_count=max_count, skip=skip, paths=path, author=author, query=query) for c in cs: commit = {} commit['parents'] = [p.hex for p in c.parents] if c.parents else '' commit['date'] = datetime.fromtimestamp( c.committer.time, FixedOffset(c.committer.offset)) commit['age'] = compute_relative_time(c.author.time) commit['author'] = c.author.name commit['email'] = email_normalizer(c.author.name, c.author.email) message_title = c.message.splitlines()[0] if c.message else '' commit['message'] = message_title commit['commit'] = c.hex commits.append(commit) return commits
def _blame_src_header(self, ref): header_data = self.cat(ref) header = {} header['message'] = header_data['message'] header['parents'] = ' '.join(header_data['parent']) header['author'] = header_data['author']['name'] header['email'] = email_normalizer( header['author'], header_data['author']['email']) header['time'] = compute_relative_time(header_data['author']['ts']) return header
def _blame_src_header(self, ref): header_data = self.cat(ref) header = {} header['message'] = header_data['message'] header['parents'] = ' '.join(header_data['parent']) header['author'] = header_data['author']['name'] header['email'] = email_normalizer(header['author'], header_data['author']['email']) header['time'] = compute_relative_time(header_data['author']['ts']) return header
def lastlog(self, request): path = request.get_form_var('path') repo = self.project.repo commit = repo.get_last_commit('HEAD', path=path) data = {"author": '', "age": '', "parents": [], "date": '', "commit": '', "message": '', "email": ''} if commit: data = commit.as_dict() data['commit'] = data['id'] data['age'] = compute_relative_time(commit.author_timestamp) return data
def parse_diff(self, ref='HEAD', ignore_space=False, rename_detection=False): if self.object_type(ref) != 'commit': return False diff_data = self.cat(ref) diffs = {} diffs['parents'] = ' '.join(diff_data['parent']) diffs['author'] = diff_data['author']['name'] diffs['email'] = email_normalizer( diffs['author'], diff_data['author']['email']) diffs['time'] = compute_relative_time(diff_data['author']['ts']) diffs['message'] = diff_data['message'].replace('\n', ' ') diffs['body'] = remove_unknown_character(diff_data['body']) parents = diffs['parents'].split(' ') if parents and parents[0]: diffs['difflist'] = self.get_3dot_diff( parents[0], ref, ignore_space=ignore_space, rename_detection=rename_detection) else: diffs['difflist'] = self._get_diff_for_first_commit(ref, parents) return diffs