From 182370af56c2f12c47a49c6a8876a53c6483ec6a Mon Sep 17 00:00:00 2001 From: Jim Winstead Date: Thu, 22 Aug 2024 18:26:32 -0700 Subject: [PATCH 1/3] Add simple script to dump org members and teams in wiki format --- dump-gh-org/README.md | 12 ++++++++++++ dump-gh-org/dump-gh-org | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 dump-gh-org/README.md create mode 100755 dump-gh-org/dump-gh-org diff --git a/dump-gh-org/README.md b/dump-gh-org/README.md new file mode 100644 index 0000000..18989e7 --- /dev/null +++ b/dump-gh-org/README.md @@ -0,0 +1,12 @@ +This is a very simple script to dump the members of the PHP GitHub +organization in DokuWiki format. + +It requires a GitHub personal access token (classic) with `read:org` +privileges. + +To run: + +```sh +$ export GITHUB_TOKEN="..." +$ /local/systems/dump-gh-org/dump-gh-org > out.wiki +``` diff --git a/dump-gh-org/dump-gh-org b/dump-gh-org/dump-gh-org new file mode 100755 index 0000000..e86f57b --- /dev/null +++ b/dump-gh-org/dump-gh-org @@ -0,0 +1,43 @@ +#!/usr/bin/env php + [ + 'header' => [ + 'User-agent: dump-gh-org/0.0', + 'Accept: application/vnd.github+json', + 'Authorization: Bearer ' . $token, + 'X-GitHub-Api-Version: 2022-11-28' + ], + ] +]); + +echo "===== Organization Members =====\n\n"; + +function print_members(string $url, $ctx) { + $page = 1; + while ($members = json_decode(file_get_contents($url . '?page=' . $page++, false, $ctx))) { + foreach ($members as $member) { + echo " * [[{$member->html_url}|{$member->login}]]\n"; + } + } +} +print_members("https://api.github.com/orgs/{$org}/members", $ctx); + +echo "\n"; + +echo "===== Teams and Members =====\n\n"; + +$teams = json_decode(file_get_contents("https://api.github.com/orgs/{$org}/teams", false, $ctx)); + +foreach ($teams as $team) { + echo "==== [[{$team->html_url}|{$team->name}]]: {$team->description} ====\n\n"; + + print_members("https://api.github.com/orgs/{$org}/teams/{$team->slug}/members", $ctx); + + echo "\n"; +} From ef199dcb881564afd0661cec154f0e83db3986ab Mon Sep 17 00:00:00 2001 From: Jim Winstead Date: Thu, 5 Sep 2024 17:22:20 -0700 Subject: [PATCH 2/3] Dump Markdown instead of DokuWiki --- dump-gh-org/README.md | 4 ++-- dump-gh-org/dump-gh-org | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dump-gh-org/README.md b/dump-gh-org/README.md index 18989e7..b6a0c9c 100644 --- a/dump-gh-org/README.md +++ b/dump-gh-org/README.md @@ -1,5 +1,5 @@ This is a very simple script to dump the members of the PHP GitHub -organization in DokuWiki format. +organization in Markdown format. It requires a GitHub personal access token (classic) with `read:org` privileges. @@ -8,5 +8,5 @@ To run: ```sh $ export GITHUB_TOKEN="..." -$ /local/systems/dump-gh-org/dump-gh-org > out.wiki +$ /local/systems/dump-gh-org/dump-gh-org > out.md ``` diff --git a/dump-gh-org/dump-gh-org b/dump-gh-org/dump-gh-org index e86f57b..8c8b140 100755 --- a/dump-gh-org/dump-gh-org +++ b/dump-gh-org/dump-gh-org @@ -16,13 +16,13 @@ $ctx = stream_context_create([ ] ]); -echo "===== Organization Members =====\n\n"; +echo "# Organization Members\n\n"; function print_members(string $url, $ctx) { $page = 1; while ($members = json_decode(file_get_contents($url . '?page=' . $page++, false, $ctx))) { foreach ($members as $member) { - echo " * [[{$member->html_url}|{$member->login}]]\n"; + echo " * [{$member->login}]({$member->html_url})\n"; } } } @@ -30,12 +30,12 @@ print_members("https://api.github.com/orgs/{$org}/members", $ctx); echo "\n"; -echo "===== Teams and Members =====\n\n"; +echo "# Teams and Members\n\n"; $teams = json_decode(file_get_contents("https://api.github.com/orgs/{$org}/teams", false, $ctx)); foreach ($teams as $team) { - echo "==== [[{$team->html_url}|{$team->name}]]: {$team->description} ====\n\n"; + echo "## [{$team->name}]({$team->html_url}): {$team->description}\n\n"; print_members("https://api.github.com/orgs/{$org}/teams/{$team->slug}/members", $ctx); From 39baa9378be9c4d5ebcf35ba348961995b51377e Mon Sep 17 00:00:00 2001 From: Jim Winstead Date: Thu, 5 Sep 2024 18:00:54 -0700 Subject: [PATCH 3/3] Dump info on organization roles and repositories --- dump-gh-org/README.md | 2 +- dump-gh-org/dump-gh-org | 51 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/dump-gh-org/README.md b/dump-gh-org/README.md index b6a0c9c..7d70a22 100644 --- a/dump-gh-org/README.md +++ b/dump-gh-org/README.md @@ -2,7 +2,7 @@ This is a very simple script to dump the members of the PHP GitHub organization in Markdown format. It requires a GitHub personal access token (classic) with `read:org` -privileges. +and `admin:org` privileges. To run: diff --git a/dump-gh-org/dump-gh-org b/dump-gh-org/dump-gh-org index 8c8b140..e75f161 100755 --- a/dump-gh-org/dump-gh-org +++ b/dump-gh-org/dump-gh-org @@ -20,9 +20,18 @@ echo "# Organization Members\n\n"; function print_members(string $url, $ctx) { $page = 1; - while ($members = json_decode(file_get_contents($url . '?page=' . $page++, false, $ctx))) { + $query = preg_match('/\?/', $url) ? '&' : '?'; + while ($data = @file_get_contents($url . $query . 'page=' . $page++, false, $ctx)) { + $members = json_decode($data); + if (!count($members)) { + break; + } foreach ($members as $member) { - echo " * [{$member->login}]({$member->html_url})\n"; + if (property_exists($member, 'members_url')) { + echo " * @[{$member->slug}]({$member->html_url})\n"; + } else { + echo " * [{$member->login}]({$member->html_url})\n"; + } } } } @@ -30,6 +39,22 @@ print_members("https://api.github.com/orgs/{$org}/members", $ctx); echo "\n"; +echo "# Organization Roles\n\n"; +$roles = @json_decode(file_get_contents("https://api.github.com/orgs/{$org}/organization-roles", false, $ctx)); + +if ($roles === null) { + echo "Not able to access roles, need `admin:org` scope.\n\n"; +} else { + foreach ($roles as $role) { + echo "## {$role->name}: {$role->description}\n\n"; + + print_members("https://api.github.com/orgs/{$org}/organization-roles/{$role->slug}/users", $ctx); + print_members("https://api.github.com/orgs/{$org}/organization-roles/{$role->slug}/teams", $ctx); + + echo "\n"; + } +} + echo "# Teams and Members\n\n"; $teams = json_decode(file_get_contents("https://api.github.com/orgs/{$org}/teams", false, $ctx)); @@ -38,6 +63,28 @@ foreach ($teams as $team) { echo "## [{$team->name}]({$team->html_url}): {$team->description}\n\n"; print_members("https://api.github.com/orgs/{$org}/teams/{$team->slug}/members", $ctx); + print_members("https://api.github.com/orgs/{$org}/teams/{$team->slug}/teams", $ctx); echo "\n"; } + +echo "# Repositories and Members\n\n"; + +function print_repos(string $url, string $org, $ctx) { + $page = 1; + while ($repos = json_decode(file_get_contents($url . '?page=' . $page++, false, $ctx))) { + foreach ($repos as $repo) { + if ($repo->archived || $repo->disabled) { + continue; + } + echo "## [{$repo->name}]({$repo->html_url}): {$repo->description}\n\n"; + + print_members("https://api.github.com/repos/{$org}/{$repo->name}/collaborators?affiliation=direct", $ctx); + print_members("https://api.github.com/repos/{$org}/{$repo->name}/teams", $ctx); + + echo "\n"; + } + } +} + +print_repos("https://api.github.com/orgs/{$org}/repos", $org, $ctx);