From df7645d72d14cddb1cc39656af26eb3d4aebe65d Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Thu, 22 Aug 2019 16:45:34 -0400 Subject: [PATCH 1/3] tools: sync tool for envoyproxy/assignable team. Bulk update of team to match envoyproxy organization. While at it, cleaned up some venv stuff in shell_utils.sh. Risk level: Low Testing: Synced 157 members from envoyproxy to envoyproxy/assignable. Signed-off-by: Harvey Tuch --- .../deprecate_features/deprecate_features.sh | 9 +-- tools/deprecate_version/deprecate_version.sh | 9 +-- tools/github/requirements.txt | 1 + tools/github/sync_assignable.py | 55 +++++++++++++++++++ tools/github/sync_assignable.sh | 7 +++ tools/shell_utils.sh | 12 ++++ 6 files changed, 77 insertions(+), 16 deletions(-) create mode 100644 tools/github/requirements.txt create mode 100644 tools/github/sync_assignable.py create mode 100755 tools/github/sync_assignable.sh diff --git a/tools/deprecate_features/deprecate_features.sh b/tools/deprecate_features/deprecate_features.sh index 43878548be09..661b348e0f0d 100644 --- a/tools/deprecate_features/deprecate_features.sh +++ b/tools/deprecate_features/deprecate_features.sh @@ -4,11 +4,4 @@ set -e -SCRIPT_DIR=$(realpath "$(dirname "$0")") -BUILD_DIR=build_tools -VENV_DIR="$BUILD_DIR"/deprecate_features - -source_venv "$VENV_DIR" -pip install -r "${SCRIPT_DIR}"/requirements.txt - -python "${SCRIPT_DIR}/deprecate_features.py" $* +python_venv deprecate_features diff --git a/tools/deprecate_version/deprecate_version.sh b/tools/deprecate_version/deprecate_version.sh index fe77384bcb6c..5421f66565b5 100755 --- a/tools/deprecate_version/deprecate_version.sh +++ b/tools/deprecate_version/deprecate_version.sh @@ -4,11 +4,4 @@ set -e -SCRIPT_DIR=$(realpath "$(dirname "$0")") -BUILD_DIR=build_tools -VENV_DIR="$BUILD_DIR"/deprecate_version - -source_venv "$VENV_DIR" -pip install -r "${SCRIPT_DIR}"/requirements.txt - -python "${SCRIPT_DIR}/deprecate_version.py" $* +python_venv deprecate_version diff --git a/tools/github/requirements.txt b/tools/github/requirements.txt new file mode 100644 index 000000000000..e1b66335b79b --- /dev/null +++ b/tools/github/requirements.txt @@ -0,0 +1 @@ +PyGithub==1.43.8 diff --git a/tools/github/sync_assignable.py b/tools/github/sync_assignable.py new file mode 100644 index 000000000000..e9c247ccdbbc --- /dev/null +++ b/tools/github/sync_assignable.py @@ -0,0 +1,55 @@ +# Sync envoyproxy organization users to envoyproxy/assignable team. +# +# This can be used for bulk cleanups if envoyproxy/assignable is not consistent with organizaiton +# member. In general, prefer to add new members by editing the envoyproxy/assignable in the GitHub +# UI, which will also cause an organization invite to be sent; this reduces the need to manually +# manage access tokens. +# +# Note: the access token supplied must have admin:org (write:org, read:org) +# permissions (and ideally be scoped no more widely than this). See Settings -> Developer settings +# -> Personal access tokens for access token generation. Ideally, these should be cleaned up after +# use. + +import os +import sys + +import github + + +def GetConfirmation(): + """Obtain stdin confirmation to add users in GH.""" + return input('Add users to envoyproxy/assignable ? [yN] ').strip().lower() in ( + 'y', 'yes') + + +def SyncAssignable(access_token): + organization = github.Github(access_token).get_organization('envoyproxy') + team = organization.get_team_by_slug('assignable') + organization_members = set(organization.get_members()) + assignable_members = set(team.get_members()) + missing = organization_members.difference(assignable_members) + + if not missing: + print('envoyproxy/assignable is consistent with organization membership.') + return 0 + + print( + 'The following organization members are missing from envoyproxy/assignable:' + ) + for m in missing: + print(m.login) + + if not GetConfirmation(): + return 1 + + for m in missing: + team.add_membership(m, 'member') + + +if __name__ == '__main__': + access_token = os.getenv('GH_ACCESS_TOKEN') + if not access_token: + print('Missing GH_ACCESS_TOKEN') + sys.exit(1) + + sys.exit(SyncAssignable(access_token)) diff --git a/tools/github/sync_assignable.sh b/tools/github/sync_assignable.sh new file mode 100755 index 000000000000..ac11d9ccc3c8 --- /dev/null +++ b/tools/github/sync_assignable.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +. tools/shell_utils.sh + +set -e + +python_venv sync_assignable diff --git a/tools/shell_utils.sh b/tools/shell_utils.sh index 4d0471e89aea..bb5a14c25e9e 100644 --- a/tools/shell_utils.sh +++ b/tools/shell_utils.sh @@ -9,3 +9,15 @@ source_venv() { echo "Found existing virtualenv" fi } + +python_venv() { + SCRIPT_DIR=$(realpath "$(dirname "$0")") + + BUILD_DIR=build_tools + VENV_DIR="$BUILD_DIR/$1" + + source_venv "$VENV_DIR" + pip install -r "${SCRIPT_DIR}"/requirements.txt + + python3 "${SCRIPT_DIR}/$1.py" $* +} From 2cc37b86aa23a0c0f946fb973b88cfe8025179cc Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Thu, 22 Aug 2019 17:46:41 -0400 Subject: [PATCH 2/3] Format/typo fixes. Signed-off-by: Harvey Tuch --- tools/github/sync_assignable.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tools/github/sync_assignable.py b/tools/github/sync_assignable.py index e9c247ccdbbc..3c4a5200562b 100644 --- a/tools/github/sync_assignable.py +++ b/tools/github/sync_assignable.py @@ -1,14 +1,15 @@ # Sync envoyproxy organization users to envoyproxy/assignable team. # -# This can be used for bulk cleanups if envoyproxy/assignable is not consistent with organizaiton -# member. In general, prefer to add new members by editing the envoyproxy/assignable in the GitHub -# UI, which will also cause an organization invite to be sent; this reduces the need to manually -# manage access tokens. +# This can be used for bulk cleanups if envoyproxy/assignable is not consistent +# with organization membership. In general, prefer to add new members by editing +# the envoyproxy/assignable in the GitHub UI, which will also cause an +# organization invite to be sent; this reduces the need to manually manage +# access tokens. # # Note: the access token supplied must have admin:org (write:org, read:org) -# permissions (and ideally be scoped no more widely than this). See Settings -> Developer settings -# -> Personal access tokens for access token generation. Ideally, these should be cleaned up after -# use. +# permissions (and ideally be scoped no more widely than this). See Settings -> +# Developer settings -> Personal access tokens for access token generation. +# Ideally, these should be cleaned up after use. import os import sys @@ -18,8 +19,9 @@ def GetConfirmation(): """Obtain stdin confirmation to add users in GH.""" - return input('Add users to envoyproxy/assignable ? [yN] ').strip().lower() in ( - 'y', 'yes') + return input( + 'Add users to envoyproxy/assignable ? [yN] ').strip().lower() in ('y', + 'yes') def SyncAssignable(access_token): From 2c37c5ee051731dec3a1e5d26194bedd828ad99f Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Thu, 22 Aug 2019 18:39:50 -0400 Subject: [PATCH 3/3] Fix format again. Signed-off-by: Harvey Tuch --- tools/github/sync_assignable.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tools/github/sync_assignable.py b/tools/github/sync_assignable.py index 3c4a5200562b..3a437fa8d35f 100644 --- a/tools/github/sync_assignable.py +++ b/tools/github/sync_assignable.py @@ -19,9 +19,7 @@ def GetConfirmation(): """Obtain stdin confirmation to add users in GH.""" - return input( - 'Add users to envoyproxy/assignable ? [yN] ').strip().lower() in ('y', - 'yes') + return input('Add users to envoyproxy/assignable ? [yN] ').strip().lower() in ('y', 'yes') def SyncAssignable(access_token): @@ -35,9 +33,7 @@ def SyncAssignable(access_token): print('envoyproxy/assignable is consistent with organization membership.') return 0 - print( - 'The following organization members are missing from envoyproxy/assignable:' - ) + print('The following organization members are missing from envoyproxy/assignable:') for m in missing: print(m.login)