Skip to content

Commit 7f97060

Browse files
authored
tools: sync tool for envoyproxy/assignable team. (envoyproxy#8015)
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 <[email protected]>
1 parent 225ad90 commit 7f97060

File tree

6 files changed

+75
-16
lines changed

6 files changed

+75
-16
lines changed

tools/deprecate_features/deprecate_features.sh

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,4 @@
44

55
set -e
66

7-
SCRIPT_DIR=$(realpath "$(dirname "$0")")
8-
BUILD_DIR=build_tools
9-
VENV_DIR="$BUILD_DIR"/deprecate_features
10-
11-
source_venv "$VENV_DIR"
12-
pip install -r "${SCRIPT_DIR}"/requirements.txt
13-
14-
python "${SCRIPT_DIR}/deprecate_features.py" $*
7+
python_venv deprecate_features

tools/deprecate_version/deprecate_version.sh

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,4 @@
44

55
set -e
66

7-
SCRIPT_DIR=$(realpath "$(dirname "$0")")
8-
BUILD_DIR=build_tools
9-
VENV_DIR="$BUILD_DIR"/deprecate_version
10-
11-
source_venv "$VENV_DIR"
12-
pip install -r "${SCRIPT_DIR}"/requirements.txt
13-
14-
python "${SCRIPT_DIR}/deprecate_version.py" $*
7+
python_venv deprecate_version

tools/github/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PyGithub==1.43.8

tools/github/sync_assignable.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Sync envoyproxy organization users to envoyproxy/assignable team.
2+
#
3+
# This can be used for bulk cleanups if envoyproxy/assignable is not consistent
4+
# with organization membership. In general, prefer to add new members by editing
5+
# the envoyproxy/assignable in the GitHub UI, which will also cause an
6+
# organization invite to be sent; this reduces the need to manually manage
7+
# access tokens.
8+
#
9+
# Note: the access token supplied must have admin:org (write:org, read:org)
10+
# permissions (and ideally be scoped no more widely than this). See Settings ->
11+
# Developer settings -> Personal access tokens for access token generation.
12+
# Ideally, these should be cleaned up after use.
13+
14+
import os
15+
import sys
16+
17+
import github
18+
19+
20+
def GetConfirmation():
21+
"""Obtain stdin confirmation to add users in GH."""
22+
return input('Add users to envoyproxy/assignable ? [yN] ').strip().lower() in ('y', 'yes')
23+
24+
25+
def SyncAssignable(access_token):
26+
organization = github.Github(access_token).get_organization('envoyproxy')
27+
team = organization.get_team_by_slug('assignable')
28+
organization_members = set(organization.get_members())
29+
assignable_members = set(team.get_members())
30+
missing = organization_members.difference(assignable_members)
31+
32+
if not missing:
33+
print('envoyproxy/assignable is consistent with organization membership.')
34+
return 0
35+
36+
print('The following organization members are missing from envoyproxy/assignable:')
37+
for m in missing:
38+
print(m.login)
39+
40+
if not GetConfirmation():
41+
return 1
42+
43+
for m in missing:
44+
team.add_membership(m, 'member')
45+
46+
47+
if __name__ == '__main__':
48+
access_token = os.getenv('GH_ACCESS_TOKEN')
49+
if not access_token:
50+
print('Missing GH_ACCESS_TOKEN')
51+
sys.exit(1)
52+
53+
sys.exit(SyncAssignable(access_token))

tools/github/sync_assignable.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
. tools/shell_utils.sh
4+
5+
set -e
6+
7+
python_venv sync_assignable

tools/shell_utils.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,15 @@ source_venv() {
99
echo "Found existing virtualenv"
1010
fi
1111
}
12+
13+
python_venv() {
14+
SCRIPT_DIR=$(realpath "$(dirname "$0")")
15+
16+
BUILD_DIR=build_tools
17+
VENV_DIR="$BUILD_DIR/$1"
18+
19+
source_venv "$VENV_DIR"
20+
pip install -r "${SCRIPT_DIR}"/requirements.txt
21+
22+
python3 "${SCRIPT_DIR}/$1.py" $*
23+
}

0 commit comments

Comments
 (0)