Skip to content

Commit

Permalink
org_repo_perms.py - added a flag to only collect admin level permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
cknowles-moz committed May 21, 2024
1 parent 94f0029 commit e940d7d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ optional arguments:

## `org_repo_perms`
```
usage: org_repo_perms.py [-h] [--pat-key PATKEY] [--token TOKEN] [--repo REPO] [--url URL] org
usage: org_repo_perms.py [-h] [--pat-key PATKEY] [--token TOKEN] [--repo REPO]
[--all] [--admin] [--url URL]
org
Report all permissions given to repos to individuals (not by a team)
Expand All @@ -296,7 +298,11 @@ options:
-h, --help show this help message and exit
--pat-key PATKEY key in .gh_pat.toml of the PAT to use
--token TOKEN use this PAT to access resources
--repo REPO Specify a single repo to work on in the specified org if desired
--repo REPO Specify a single repo to work on in the specified org if
desired
--all Dump ALL (Well, not owners) permissions, not just non-team
singletons
--admin Only output admins of the repo
--url URL the graphql URL
```

Expand Down
15 changes: 12 additions & 3 deletions org_repo_perms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
But sometimes we just need a dump of everything - so add a flag to look for more than singles
"""

# TODO: Output only perms of ADMIN

import sys

import alive_progress
Expand Down Expand Up @@ -36,6 +38,7 @@ def parse_arguments():
help="Dump ALL (Well, not owners) permissions, not just non-team singletons",
action="store_true",
)
parser.add_argument("--admin", help="Only output admins of the repo", action="store_true")
parser.add_argument(
"--url",
type=str,
Expand Down Expand Up @@ -182,9 +185,15 @@ def main():
outputlist = []
for repo in resultdict.keys():
line = f"{repo}," # noqa: E231
for perms in resultdict[repo].keys():
line = line + f"{perms}:{':'.join(resultdict[repo][perms])}," # noqa: E231
outputlist.append(line)
if args.admin:
# print(f"keys = {resultdict[repo].keys()}, {'ADMIN' in resultdict[repo].keys()}")
if "ADMIN" in resultdict[repo].keys():
line = line + f"{'ADMIN'}:{':'.join(resultdict[repo]['ADMIN'])}," # noqa: E231
outputlist.append(line)
else:
for perms in resultdict[repo].keys():
line = line + f"{perms}:{':'.join(resultdict[repo][perms])}," # noqa: E231
outputlist.append(line)
print("RepoName, PermissionsColumns")
print("\n".join(outputlist))

Expand Down

0 comments on commit e940d7d

Please sign in to comment.