From 5048fc95e416568b951c66de8bfbf855b92f79cb Mon Sep 17 00:00:00 2001 From: Igor Cherkaev Date: Wed, 7 Sep 2022 16:00:20 -0500 Subject: [PATCH] 2.1.3: fix update_branch_protection action dismissal users and teams can now be null in GitHub's API response Signed-off-by: Igor Cherkaev --- actions/lib/formatters.py | 10 ++++++++-- actions/update_branch_protection.py | 15 ++++++++++++--- pack.yaml | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/actions/lib/formatters.py b/actions/lib/formatters.py index 2a35d8e..51a9d3b 100644 --- a/actions/lib/formatters.py +++ b/actions/lib/formatters.py @@ -37,10 +37,16 @@ def branch_protection_to_dict(branch_protection): result[attr] = {} for attr2 in required_pull_request_reviews_attributes: if attr2 == 'dismissal_users': - users = [user.login for user in req_pr_reviews.dismissal_users] + if req_pr_reviews.dismissal_users is not None: + users = [user.login for user in req_pr_reviews.dismissal_users] + else: + users = None result[attr][attr2] = users elif attr2 == 'dismissal_teams': - teams = [team.slug for team in req_pr_reviews.dismissal_teams] + if req_pr_reviews.dismissal_teams is not None: + teams = [team.slug for team in req_pr_reviews.dismissal_teams] + else: + teams = None result[attr][attr2] = teams else: result[attr][attr2] = getattr(req_pr_reviews, attr2) diff --git a/actions/update_branch_protection.py b/actions/update_branch_protection.py index 7fdf5dc..e20cc96 100644 --- a/actions/update_branch_protection.py +++ b/actions/update_branch_protection.py @@ -43,6 +43,11 @@ def run(self, user, repo, branch, required_status_checks, enforce_admins, user_push_restrictions = restrictions['user_push_restrictions'] team_push_restrictions = restrictions['team_push_restrictions'] + if not dismissal_users: + dismissal_users = NotSet + if not dismissal_teams: + dismissal_teams = NotSet + branch.edit_protection(strict=strict, contexts=contexts, enforce_admins=enforce_admins, dismissal_users=dismissal_users, @@ -64,9 +69,13 @@ def run(self, user, repo, branch, required_status_checks, enforce_admins, GITHUB_BRANCH = os.environ.get('GITHUB_BRANCH') # As produced by get_branch_protection action - BRANCH_PROTECTION = {'enforce_admins': True, - 'required_pull_request_reviews': None, - 'required_status_checks': {'contexts': [], 'strict': True}, + BRANCH_PROTECTION = {'enforce_admins': False, + 'required_pull_request_reviews': {'dismiss_stale_reviews': False, + 'dismissal_teams': None, + 'dismissal_users': None, + 'require_code_owner_reviews': False, + 'required_approving_review_count': 0}, + 'required_status_checks': None, 'restrictions': None } diff --git a/pack.yaml b/pack.yaml index 6138ecd..3c5fd56 100644 --- a/pack.yaml +++ b/pack.yaml @@ -8,7 +8,7 @@ keywords: - git - scm - serverless -version: 2.1.2 +version: 2.1.3 python_versions: - "3" author : StackStorm, Inc.