From 78d5de9dd3178280bc937c4a6c66dac860ac493e Mon Sep 17 00:00:00 2001 From: Ivan Lezhankin Date: Tue, 9 Apr 2019 12:55:10 +0300 Subject: [PATCH] Respect label color to check for backporting --- utils/github/__main__.py | 28 +++++++++++++++++++--------- utils/github/local.py | 12 +++++++----- utils/github/query.py | 5 +++-- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/utils/github/__main__.py b/utils/github/__main__.py index fbf772f120a..8e0be565468 100644 --- a/utils/github/__main__.py +++ b/utils/github/__main__.py @@ -26,7 +26,8 @@ import sys CHECK_MARK = '🗸' CROSS_MARK = '🗙' -AUTHOR_MARK = '⚠' +WARN_MARK = '⚠' +WAIT_MARK = '⊙' parser = argparse.ArgumentParser(description='Helper for the ClickHouse Release machinery') @@ -44,7 +45,7 @@ args = parser.parse_args() github = query.Query(args.token) repo = local.Local(args.repo, args.remote, github.get_default_branch()) -stables = repo.get_stables()[-args.number:] +stables = repo.get_stables()[-args.number:] # [(branch, base, head)] if not stables: sys.exit('No stable branches found!') else: @@ -65,32 +66,41 @@ for i in reversed(range(len(stables))): from_commit = stables[i][1] -bad_pull_requests = [] # collect and print if not empty +bad_pull_requests = [] # collect and print if not empty +need_backporting = [] for num, value in pull_requests.items(): label_found = False for label in value[1]: - if label.startswith('pr-'): + if label[0].startswith('pr-'): label_found = True + if label[1] == 'ff0000': + need_backporting.append(num) break if not label_found: bad_pull_requests.append(num) if bad_pull_requests: - print('\nPull-requests without description label:', file=sys.stderr) + print('\nPull-requests without description label:') for bad in reversed(sorted(bad_pull_requests)): print(f'{CROSS_MARK} {bad}') -# FIXME: compatibility logic, until the modification of master is not prohibited. +# FIXME: compatibility logic, until the direct modification of master is not prohibited. if bad_commits: - print('\nCommits not referenced by any pull-request:', file=sys.stderr) + print('\nCommits not referenced by any pull-request:') bad_authors = set() for bad in bad_commits: - print(f'{CROSS_MARK} {bad}', file=sys.stderr) + print(f'{CROSS_MARK} {bad}') bad_authors.add(bad.author) print('\nTell these authors not to push without pull-request and not to merge with rebase:') for author in sorted(bad_authors, key=lambda x : x.name): - print(f'{AUTHOR_MARK} {author}') + print(f'{WARN_MARK} {author}') + +# TODO: check backports. +if need_backporting: + print('\nPull-requests need to be backported:') + for bad in reversed(sorted(need_backporting)): + print(f'{CROSS_MARK} {bad}') diff --git a/utils/github/local.py b/utils/github/local.py index cc651c07cf2..55b05ecf46e 100644 --- a/utils/github/local.py +++ b/utils/github/local.py @@ -6,7 +6,6 @@ import git # gitpython import functools import os import re -import sys class Local: @@ -35,7 +34,10 @@ class Local: for commit in self._repo.iter_commits(rev_range, first_parent=True): yield commit - ''' Returns sorted list of tuples: remote branch (git.refs.remote.RemoteReference), base commit (git.Commit). + ''' Returns sorted list of tuples: + * remote branch (git.refs.remote.RemoteReference), + * base commit (git.Commit), + * head (git.Commit)). List is sorted by commits in ascending order. ''' def get_stables(self): @@ -44,10 +46,10 @@ class Local: for stable in [r for r in self._remote.refs if Local.RE_STABLE_REF.match(r.path)]: base = self._repo.merge_base(self._default, self._repo.commit(stable)) if not base: - print(f'Branch {stable.path} is not based on branch {self._default}. Ignoring.', file=sys.stderr) + print(f'Branch {stable.path} is not based on branch {self._default}. Ignoring.') elif len(base) > 1: - print(f'Branch {stable.path} has more than one base commit. Ignoring.', file=sys.stderr) + print(f'Branch {stable.path} has more than one base commit. Ignoring.') else: - stables.append((stable, base[0])) + stables.append((stable, base[0], self._repo.commit(stable))) return sorted(stables, key=lambda x : self.comparator(x[1])) diff --git a/utils/github/query.py b/utils/github/query.py index c8192d7fd29..48123fd743f 100644 --- a/utils/github/query.py +++ b/utils/github/query.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- import requests -import sys class Query: @@ -50,7 +49,7 @@ class Query: def _labels(self, pull_request): # TODO: fetch all labels - return [label['node']['name'] for label in pull_request['labels']['edges']] + return [(label['node']['name'], label['node']['color']) for label in pull_request['labels']['edges']] def _run(self, query): headers = {'Authorization': f'bearer {self._token}'} @@ -95,6 +94,7 @@ Query._FIRST = ''' edges {{ node {{ name + color }} cursor }} @@ -147,6 +147,7 @@ Query._NEXT = ''' edges {{ node {{ name + color }} cursor }}