forked from opencepk/opencepk-template-base
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1472d38
commit 664d63c
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
name: github-uar.yml | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- fix/UAR-automation | ||
pull_request: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
inputs: | ||
role: | ||
description: 'Role to filter members by' | ||
required: false | ||
default: '' | ||
|
||
jobs: | ||
UAR-automation: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Get Token | ||
id: get_workflow_token | ||
uses: peter-murray/workflow-application-token-action@v3 | ||
with: | ||
application_id: ${{ secrets.GH_APP_FULL_APPLICATION_ID }} | ||
application_private_key: ${{ secrets.APPLICATION_GITHUB_APP_FULL_PRIVATE_KEY }} | ||
revoke_token: true | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install dependencies | ||
run: pip install requests | ||
|
||
- name: Run list_org_owners.py script | ||
run: python scripts/list_org_owners.py | ||
env: | ||
GITHUB_ORG_NAME: tucowsinc | ||
GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }} | ||
ROLE: ${{ github.event.inputs.role }} | ||
|
||
- name: Upload CSV as artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: org-members | ||
path: org_members.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import csv | ||
import requests | ||
import os | ||
|
||
def get_org_admins(org_name, token, role=None): | ||
url = f"https://api.github.com/orgs/{org_name}/members?role={role}" | ||
headers = { | ||
"Authorization": f"token {token}", | ||
"Accept": "application/vnd.github.v3+json" | ||
} | ||
admins = [] | ||
|
||
while url: | ||
response = requests.get(url, headers=headers) | ||
response.raise_for_status() | ||
members = response.json() | ||
admins.extend([{'login': member['login'], 'role': role} for member in members]) | ||
|
||
# Check for pagination | ||
if 'next' in response.links: | ||
url = response.links['next']['url'] | ||
else: | ||
url = None | ||
|
||
return admins | ||
|
||
def save_to_csv(data, filename): | ||
with open(filename, mode='w', newline='') as file: | ||
writer = csv.DictWriter(file, fieldnames=['login', 'role']) | ||
writer.writeheader() | ||
for row in data: | ||
writer.writerow(row) | ||
|
||
if __name__ == "__main__": | ||
org_name = os.getenv('GITHUB_ORG_NAME') | ||
token = os.getenv('GITHUB_TOKEN') | ||
role = os.getenv('ROLE') | ||
if not org_name: | ||
raise ValueError("GITHUB_ORG_NAME environment variable is not set") | ||
if not token: | ||
raise ValueError("GITHUB_TOKEN environment variable is not set") | ||
admins = get_org_admins(org_name, token, role) | ||
save_to_csv(admins, 'org_members.csv') |