Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
hminaee-tc committed Sep 24, 2024
1 parent 1472d38 commit 664d63c
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/github-uar.yml
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
43 changes: 43 additions & 0 deletions scripts/list_org_owners.py
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')

0 comments on commit 664d63c

Please sign in to comment.