aboutsummaryrefslogtreecommitdiff
path: root/applications/github/github_admins.py
diff options
context:
space:
mode:
Diffstat (limited to 'applications/github/github_admins.py')
-rw-r--r--applications/github/github_admins.py31
1 files changed, 19 insertions, 12 deletions
diff --git a/applications/github/github_admins.py b/applications/github/github_admins.py
index d737887..b6db534 100644
--- a/applications/github/github_admins.py
+++ b/applications/github/github_admins.py
@@ -5,54 +5,59 @@ and list each user's permission per repo.
import requests
-GITHUB_TOKEN = 'your_personal_access_token'
-ORGANIZATION = 'your_organization'
+GITHUB_TOKEN = "your_personal_access_token"
+ORGANIZATION = "your_organization"
TIMEOUT = 30
# Headers for authentication
headers = {
- 'Authorization': f'token {GITHUB_TOKEN}',
- 'Accept': 'application/vnd.github.v3+json'
+ "Authorization": f"token {GITHUB_TOKEN}",
+ "Accept": "application/vnd.github.v3+json",
}
+
def get_org_members(org):
"""
Get members of an organization
"""
- url = f'https://api.github.com/orgs/{org}/members'
+ url = f"https://api.github.com/orgs/{org}/members"
response = requests.get(url, headers=headers, timeout=TIMEOUT)
response.raise_for_status()
return response.json()
+
def get_org_repos(org):
"""
Get repositories of an organization
"""
- url = f'https://api.github.com/orgs/{org}/repos'
+ url = f"https://api.github.com/orgs/{org}/repos"
response = requests.get(url, headers=headers, timeout=TIMEOUT)
response.raise_for_status()
return response.json()
+
def get_repo_collaborators(org, repo):
"""
Get collaborators of a repository with their permissions
"""
- url = f'https://api.github.com/repos/{org}/{repo}/collaborators'
+ url = f"https://api.github.com/repos/{org}/{repo}/collaborators"
response = requests.get(url, headers=headers, timeout=TIMEOUT)
response.raise_for_status()
return response.json()
+
def get_user_permissions(org, repo, user):
"""
Get a user's permissions for a repository
"""
- url = f'https://api.github.com/repos/{org}/{repo}/collaborators/{user}/permission'
+ url = f"https://api.github.com/repos/{org}/{repo}/collaborators/{user}/permission"
response = requests.get(url, headers=headers, timeout=TIMEOUT)
response.raise_for_status()
return response.json()
+
# Main script
-if __name__ == '__main__':
+if __name__ == "__main__":
# Get organization members
members = get_org_members(ORGANIZATION)
print(f"Members of the organization '{ORGANIZATION}':")
@@ -67,10 +72,12 @@ if __name__ == '__main__':
# Get collaborators for each repository and their permissions
for repository in repositories:
- repository_name = repository['name']
+ repository_name = repository["name"]
collaborators = get_repo_collaborators(ORGANIZATION, repository_name)
print(f"\nCollaborators for the repository '{repository_name}':")
for collaborator in collaborators:
- user_login = collaborator['login']
- permissions = get_user_permissions(ORGANIZATION, repository_name, user_login)
+ user_login = collaborator["login"]
+ permissions = get_user_permissions(
+ ORGANIZATION, repository_name, user_login
+ )
print(f"- {user_login}: {permissions['permission']}")