Skip to content

3. Play with GitHub REST API (using Octokit)

Pierre-Yves Lapersonne edited this page Jul 18, 2023 · 1 revision

Play with GitHub web API

Prerequisites

  • Ruby Gem: octokit 6.1.1

  • Ruby Gem: git 1.18.0

  • Ruby 2.7.1

  • Create a GitHub personal token and define it in the configuration.rb file for the GITHUB_PERSONAL_ACCESS_TOKEN variable.

  • Define the GitHub organization name in the configuration.rb file for the GITHUB_ORGANIZATION_NAME variable. It will allow to send requests to query and modify your organization.

  • Define also the logins of the GitHub adminsitrators of your organization so as to prevent to change their permisssion for example.

Prepare project

gem install octokit
gem install git

of if you have Bundler:

bundle install

Third-party elements

This project uses Octokit Ruby client, licensed under MIT license. It also uses Git Ruby gem, under MIT license.

Features

Display usage

bash GitHubWizard.sh

Get all members of organization

Keywords: #organisation #GitHub #members

Run the following command and check the file with the FILENAME_MEMBERS name (configuration.rb)

bash GitHubWizard.sh get-all-members

Get members of organization with 2FA disabled

Keywords: #organisation #GitHub #members #2FA #security

Run the following command and check the file with the FILENAME_MEMBERS_2FA_DISABLED name (configuration.rb)

bash GitHubWizard.sh get-members-2fa-disabled

Get members of organization with "company" field undefined

Keywords: #organisation #GitHub #members #company

Run the following command and check the file with the FILENAME_MEMBERS_UNDEFINED_COMPANY name (configuration.rb)

bash GitHubWizard.sh get-members-without-company

Get projects which don't have any assigned team

Keywords: #organisation #GitHub #members #teams

Run the following command and check the file with the FILENAME_PROJECTS_WITHOUT_TEAM name (configuration.rb)

bash GitHubWizard.sh get-projects-without-team

Get users which have undefined or hidden email

Keywords: #organisation #GitHub #members #email

Run the following command and check the file with the FILENAME_USERS_WITH_BAD_EMAILS name (configuration.rb)

bash GitHubWizard.sh get-users-with-bad-email

Get users which may have not suitable fullname

Keywords: #organisation #GitHub #members #fullname #name #handle

Run the following command and check the file with the FILENAME_USERS_WITH_BAD_FULLNAMES name (configuration.rb)

bash GitHubWizard.sh get-users-with-bad-fullname

Get repositories with undefined licenses

Keywords: #organisation #GitHub #projects #licenses

Run the following command and check the file with the FILENAME_PROJECTS_WITHOUT_LICENSES (configuration.rb)

bash GitHubWizard.sh get-projects-without-licenses

Get repositories which seems to be unconform (i.e. missing files)

Keywords: #organisation #GitHub #projects #guidelines #files

Run the following command and check the file with the FILENAME_PROJECTS_WITH_UNCONFORM_REPOSITORIES name (configuration.rb)

bash GitHubWizard.sh get-projects-conformity

SSH will be used to clone repositories, thus you must have your SSH configuration ready:

  1. Create an SSH key on your GitHub account settings
  2. Add the SSH key in your environment
ssh-add .ssh/id_rsa

Get repositories which seems to be empty or have not enough files

Keywords: #organisation #GitHub #projects #repository

Run the following command and check the file with the FILENAME_EMPTY_PROJECTS name (configuration.rb)

bash GitHubWizard.sh get-empty-projects

SSH will be used to clone repositories, thus you must have your SSH configuration ready:

  1. Create an SSH key on your GitHub account settings
  2. Add the SSH key in your environment
ssh-add .ssh/id_rsa

Define users permissions for all projects to "push"

Keywords: #organisation #GitHub #permissions #members #push

Run the following command to update rights of all users except GitHub teams and GitHub administrators, for all projects. Permissions will be set to "push", i.e. "write".

bash GitHubWizard.sh set-users-permissions-to-push

Define teams permissions for all projects to "push"

Keywords: #organisation #GitHub #permissions #teams #push

Run the following command to update rights of all teams, for all projects. Permissions will be set to "push", i.e. "write".

bash GitHubWizard.sh set-teams-permissions-to-push

Define teams permissions for all projects to "read"

Keywords: #organisation #GitHub #permissions #teams #read

Run the following command to update rights of all teams, for all projects. Permissions will be set to "read".

bash GitHubWizard.sh set-teams-permissions-to-read