Skip to content

Commit

Permalink
Adding org_list.py to list all orgs the running user belongs to (MoCo…
Browse files Browse the repository at this point in the history
…-GHE-Admin#140)

* Adding org_list.py to output complete list of orgs you belong to

* Updating README for org_list.py
  • Loading branch information
cknowles-moz authored Jun 14, 2024
1 parent 7027a77 commit c8bd2df
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,18 @@ options:
Type of repo, all (default), public, private
```

## `org_list.py`
```
usage: org_list.py [-h] [--pat-key PATKEY] [--token TOKEN]
Gets a list of the organizations that the user belongs to. Useful as input to scripts that take a list of orgs. Note if you have personal orgs, this will be included.
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
```

## `org_owners.py`
```
usage: org_owners.py [-h] [--pat-key PATKEY] [--token TOKEN] [orgs ...]
Expand Down
36 changes: 36 additions & 0 deletions org_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python
"""
Script to list the organizations that the runner belongs to.
"""

from github3 import login

from github_scripts import utils


def parse_args():
"""
Parse the command line.
Detects if no PAT is given, asks for it.
:return: Returns the parsed CLI datastructures.
"""

parser = utils.GH_ArgParser(
description="Gets a list of the organizations that the user belongs to. Useful as input to scripts that take a list of orgs. Note if you have personal orgs, this will be included."
)
args = parser.parse_args()

return args


def main():
"""Get the list of orgs"""
args = parse_args()

gh_sess = login(token=args.token)
for org in gh_sess.organizations():
print(org.login)


if __name__ == "__main__":
main()
2 changes: 0 additions & 2 deletions orglist.ini-EXAMPLE

This file was deleted.

0 comments on commit c8bd2df

Please sign in to comment.