Better filter associated pull-requests

This commit is contained in:
Ivan Lezhankin 2019-04-08 22:28:08 +03:00
parent 5a909b01b0
commit 692c5a6ed2
2 changed files with 22 additions and 13 deletions

View File

@ -5,22 +5,17 @@
Rules for commit messages, branch names and everything:
- All(!) commits to master branch must originate from pull-requests.
- Commit message should contain the reference to the originative pull-request in form `#NUMBER`.
- The first sequence recognized as reference must be the originative pull-request reference.
- All pull-requests must be squash-merged or explicitly merged without rebase.
- All pull-requests to master must have at least one label prefixed with `pr-`.
- Labels that require pull-request to be backported must be red colored (#ff0000).
- Stable branch name must be of form `YY.NUMBER`.
- All stable branches must be forked directly from the master branch and never be merged back,
or merged with any other branches based on the master branch (including master branch itself).
Output of this script (if no errors occurred):
Output of this script:
- The 1st line is the last good handled commit on master branch for consecutive invocations.
- The 2nd line is the last handled commit on master branch (effectively current head).
- The 3rd line is the first handled commit on master branch (inclusive).
Errors (strictly after output):
- Commits without references to pull-requests.
- Commits with the first reference not to the originative pull-request.
- Commits without references from pull-requests.
- Pull-requests to master without proper labels.
'''
@ -79,6 +74,8 @@ for num, value in pull_requests.items():
for label in value[1]:
if label.startswith('pr-'):
label_found = True
if label in ['pr-bugfix', 'pr-performance']:
print(f'pull-request {num} should be backported')
break
if not label_found:

View File

@ -5,7 +5,7 @@ import sys
class Query:
def __init__(self, token, max_page_size=100, pull_request_page_size=2):
def __init__(self, token, max_page_size=100, pull_request_page_size=5):
self._token = token
self._max_page_size = max_page_size
self._pull_request_page_size = pull_request_page_size
@ -18,6 +18,8 @@ class Query:
query = Query._FIRST.format(max_page_size=self._max_page_size, pull_request_page_size=self._pull_request_page_size)
not_end = True
default_branch_name = self.get_default_branch()
while not_end:
result = self._run(query)['data']['repository']['defaultBranchRef']['target']['history']
not_end = result['pageInfo']['hasNextPage']
@ -33,7 +35,9 @@ class Query:
assert node['associatedPullRequests']['totalCount'] <= self._pull_request_page_size
for pull_request in node['associatedPullRequests']['nodes']:
if pull_request['mergeCommit']['oid'] == node['oid']:
if(pull_request['baseRepository']['nameWithOwner'] == 'yandex/ClickHouse' and
pull_request['baseRefName'] == default_branch_name and
pull_request['mergeCommit']['oid'] == node['oid']):
pull_requests[pull_request['number']] = (node['oid'], self._labels(pull_request))
query = Query._NEXT.format(max_page_size=self._max_page_size,
@ -76,6 +80,10 @@ Query._FIRST = '''
nodes {{
... on PullRequest {{
number
baseRefName
baseRepository {{
nameWithOwner
}}
mergeCommit {{
oid
}}
@ -124,6 +132,10 @@ Query._NEXT = '''
nodes {{
... on PullRequest {{
number
baseRefName
baseRepository {{
nameWithOwner
}}
mergeCommit {{
oid
}}