Enables autoupdate for PRs to be in sync with master. (#1363)

This commit is contained in:
Artur Souza 2021-12-06 14:59:43 -08:00 committed by GitHub
parent f6e6bd8120
commit cac03dbe87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 7 deletions

View File

@ -1,7 +1,15 @@
# ------------------------------------------------------------
# Copyright (c) Microsoft Corporation and Dapr Contributors.
# Licensed under the MIT License.
# ------------------------------------------------------------
#
# Copyright 2021 The Dapr Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This script automerges PRs in Dapr.
@ -14,9 +22,10 @@ g = Github(os.getenv("GITHUB_TOKEN"))
repo = g.get_repo(os.getenv("GITHUB_REPOSITORY"))
maintainers = [m.strip() for m in os.getenv("MAINTAINERS").split(',')]
def fetch_pulls(mergeable_state, label = 'automerge'):
def fetch_pulls(mergeable_state, labels = {'automerge'}):
return [pr for pr in repo.get_pulls(state='open', sort='created') \
if (not pr.draft) and pr.mergeable_state == mergeable_state and (not label or label in [l.name for l in pr.labels])]
if (not pr.draft) and pr.mergeable_state == mergeable_state and \
(not labels or len(labels.intersection({l.name for l in pr.labels})) > 0)]
def is_approved(pr):
approvers = [r.user.login for r in pr.get_reviews() if r.state == 'APPROVED' and r.user.login in maintainers]
@ -41,7 +50,7 @@ if len(pulls) > 0 and not merged:
print("No PR was automerged.")
# Now, update all PRs that are behind, regardless of automerge label.
pulls = fetch_pulls('behind', '')
pulls = fetch_pulls('behind', {'automerge', 'autoupdate'})
print(f"Detected {len(pulls)} open pull requests in {repo.name} to be updated.")
for pr in pulls:
print(f"Updating PR {pr.html_url}")