Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: sync tool for envoyproxy/assignable team. #8015

Merged
merged 3 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions tools/deprecate_features/deprecate_features.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 1 addition & 8 deletions tools/deprecate_version/deprecate_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions tools/github/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PyGithub==1.43.8
53 changes: 53 additions & 0 deletions tools/github/sync_assignable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Sync envoyproxy organization users to envoyproxy/assignable team.
#
# 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.

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))
7 changes: 7 additions & 0 deletions tools/github/sync_assignable.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

. tools/shell_utils.sh

set -e

python_venv sync_assignable
12 changes: 12 additions & 0 deletions tools/shell_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" $*
}