0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GitHub CLI で、OrganizationのMember一覧を取得する【GitHub】

Last updated at Posted at 2024-08-29

やりたいこと

GitHubのOrganizationのメンバー棚卸しをしたい。
GitHub CLI で、OrganizationのMember一覧を取得する。

やりかた

とりあえずメンバーのユーザー名一覧だけ取得したい場合

YOUR_ORGANIZATION_NAME="hoge"
gh api "/orgs/$YOUR_ORGANIZATION_NAME/members?per_page=100" | jq '.[].login'

メンバーの権限も併せて取得したい場合

ユーザー棚卸しではOrganizationの権限(Member or Owner)を見たいことがあります。

YOUR_ORGANIZATION_NAME="hoge"

members=($(gh api "orgs/$YOUR_ORGANIZATION_NAME/members?per_page=100" | jq -r '.[].login'))

for member in $members; do
  role=($(gh api orgs/$YOUR_ORGANIZATION_NAME/memberships/$member | jq -r '.role'))
  echo "Username: $member / Role: $role"
done

結果
Owner権限を持つユーザーのRoleは「admin」と表示されるようです。

Username: yamada-taro / Role: admin
Username: sato-jiro / Role: member

参考URL

公式ドキュメント - Organization メンバーの REST API エンドポイント

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?