Skip to content

Commit 88e4131

Browse files
committed
Add user tagging, add env var option for token and dry_run
1 parent 722be79 commit 88e4131

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

.github/workflows/org-inactive-user-management.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
run: |
2020
python -m pip install --upgrade pip
2121
pip install -r community/org/requirements.txt
22-
python community/org/org_user_management.py -gt ${{ secrets.GH_TOKEN }}
22+
python community/org/org_user_management.py
2323
- name: Create Pull Request
2424
if: ${{ steps.uds.outputs.inactive_users_pr_description }}
2525
uses: peter-evans/create-pull-request@v4

org/org_user_management.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def delete_inactive_contributors(self, users_to_delete):
9595
contributors_yaml["contributors"] = [c for c in contributors_yaml["contributors"] if c not in users_to_delete]
9696
self._write_yaml_file(path, contributors_yaml)
9797

98-
def get_inactive_users_msg(self, users_to_delete):
98+
def get_inactive_users_msg(self, users_to_delete, tagusers):
9999
rfc = (
100100
"https://github.com/cloudfoundry/community/blob/main/toc/rfc/"
101101
"rfc-0025-define-criteria-and-removal-process-for-inactive-members.md"
@@ -104,23 +104,41 @@ def get_inactive_users_msg(self, users_to_delete):
104104
"https://github.com/cloudfoundry/community/blob/main/toc/rfc/rfc-0025-define-"
105105
"criteria-and-removal-process-for-inactive-members.md#remove-the-membership-to-the-cloud-foundry-github-organization"
106106
)
107-
users_as_list = "\n".join(str(s) for s in users_to_delete)
107+
user_tagging_prefix = "@" if tagusers else ""
108+
users_as_list = "\n".join(str(user_tagging_prefix + s) for s in users_to_delete)
108109
return (
109110
f"According to the rolues for inactivity defined in [RFC-0025]({rfc}) following users will be deleted:\n"
110111
f"{users_as_list}\nAccording to the [revocation policy in the RFC]({rfc_revocation_rules}), users have"
111112
" two weeks to refute this revocation, if they wish."
112113
)
113114

115+
@staticmethod
116+
def _get_bool_env_var(env_var_name, default):
117+
return os.getenv(env_var_name, default).lower() == "true"
118+
114119

115120
if __name__ == "__main__":
116121
one_year_back = (datetime.datetime.now() - datetime.timedelta(days=365)).strftime("%Y-%m-%dT%H:%M:%SZ")
117122

118123
parser = argparse.ArgumentParser(description="Cloud Foundry Org Inactive User Handler")
119124
parser.add_argument("-goid", "--githuborgid", default="O_kgDOAAl8sg", help="Cloud Foundry Github org ID")
120125
parser.add_argument("-go", "--githuborg", default="cloudfoundry", help="Cloud Foundry Github org name")
121-
parser.add_argument("-sd", "--sincedate", default=one_year_back, help="Since when to analyze in format '%Y-%m-%dT%H:%M:%SZ'")
122-
parser.add_argument("-gt", "--githubtoken", default="", help="Github API access token")
123-
parser.add_argument("-dr", "--dryrun", default=False, help="Dry run execution")
126+
parser.add_argument("-sd", "--sincedate", default=one_year_back, help="Since when to analyze in format 'Y-m-dTH:M:SZ'")
127+
parser.add_argument(
128+
"-gt", "--githubtoken", default=os.environ.get("GH_TOKEN"), help="Github API access token. Supported also as env var 'GH_TOKEN'"
129+
)
130+
parser.add_argument(
131+
"-dr",
132+
"--dryrun",
133+
default=InactiveUserHandler._get_bool_env_var("INACTIVE_USER_MANAGEMENT_DRY_RUN", "False"),
134+
help="Dry run execution. Supported also as env var 'INACTIVE_USER_MANAGEMENT_DRY_RUN'",
135+
)
136+
parser.add_argument(
137+
"-tu",
138+
"--tagusers",
139+
default=InactiveUserHandler._get_bool_env_var("INACTIVE_USER_MANAGEMENT_TAG_USERS", "True"),
140+
help="Tag users to be notified. Supported also as env var 'INACTIVE_USER_MANAGEMENT_TAG_USERS'",
141+
)
124142
args = parser.parse_args()
125143

126144
print("Get information about community users")
@@ -134,7 +152,7 @@ def get_inactive_users_msg(self, users_to_delete):
134152

135153
print(f"Inactive users length is {len(inactive_users)} and inactive users are {inactive_users}")
136154
users_to_delete = inactive_users - community_members_with_role
137-
inactive_users_msg = userHandler.get_inactive_users_msg(users_to_delete)
155+
inactive_users_msg = userHandler.get_inactive_users_msg(users_to_delete, args.tagusers)
138156
if args.dryrun:
139157
print(f"Dry-run mode.\nInactive_users_msg is: {inactive_users_msg}")
140158
print(f"Following users will be deleted: {inactive_users}")

org/readme.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ How to run locally:
8787
cd ./org
8888
pip install -r requirements.txt
8989
python -m org_management --help
90+
python -m org_user_management --help
9091
```
9192

9293
Usage:
@@ -103,6 +104,28 @@ optional arguments:
103104
output file for generated branch protection rules
104105
```
105106

107+
```
108+
python -m org_user_management --help
109+
usage: org_user_management.py [-h] [-goid GITHUBORGID] [-go GITHUBORG] [-sd SINCEDATE] [-gt GITHUBTOKEN] [-dr DRYRUN] [-tu TAGUSERS]
110+
111+
Cloud Foundry Org Inactive User Handler
112+
113+
options:
114+
-h, --help show this help message and exit
115+
-goid GITHUBORGID, --githuborgid GITHUBORGID
116+
Cloud Foundry Github org ID
117+
-go GITHUBORG, --githuborg GITHUBORG
118+
Cloud Foundry Github org name
119+
-sd SINCEDATE, --sincedate SINCEDATE
120+
Since when to analyze in format 'Y-m-dTH:M:SZ'
121+
-gt GITHUBTOKEN, --githubtoken GITHUBTOKEN
122+
Github API access token. Supported also as env var 'GH_TOKEN'
123+
-dr DRYRUN, --dryrun DRYRUN
124+
Dry run execution. Supported also as env var 'INACTIVE_USER_MANAGEMENT_DRY_RUN'
125+
-tu TAGUSERS, --tagusers TAGUSERS
126+
Tag users to be notified. Supported also as env var 'INACTIVE_USER_MANAGEMENT_TAG_USERS'
127+
```
128+
106129
How to run tests:
107130
```
108131
cd ./org

0 commit comments

Comments
 (0)