How to: List GitHub default Branch protection rules

  1. PowerShell script will receive the following parameters:
  • $PAT = Personal Access token to connect on GitHub organization;
  • $Organization = GitHub Organization name;
  • $Connstr = connection string to Azure SQL Database that stores the report information. To create this report, it’s necessary to create previously a Azure SQL Server and Database and run a script below:
$uriRepositories = "$($UriOrganization)/repos"$RepositoriesResult = Invoke-RestMethod -Headers $headers -Uri $uriRepositoriesforeach ($repo in $RepositoriesResult)
{
Write-Host $repo.name
Write-Host $repo.default_branch
}
$uriDefaultBranch = $repo.branches_url.Replace('{/branch}',"/$($repo.default_branch)")    $DefaultBranchResults = Invoke-RestMethod -Headers $headers -Uri $uriDefaultBranch    if ($DefaultBranchResults.protected)
{
Write-Host $DefaultBranchResults.protection_url
}
$branchProtectionResults = Invoke-RestMethod -Headers $headers -Uri $DefaultBranchResults.protection_url        
If ($branchProtectionResults)
{
$allow_deletions = $branchProtectionResults.allow_deletions.enabled
}
  • Repositories (1) = Filter report using Repositories field;
  • Default branch (2) = Filter report using Default branch field;
  • List repositories (3) = List all repositories within the GitHub organization. Here you can click on the link to redirect directly to the GitHub repository chosen from the list;
  • Require a pull request before merging (4) = checks how many default branches have the protection rule Require a pull request before merging applied;
  • Require status checks to pass before merging (5) = checks how many default branches have the protection rule Require status checks to pass before merging applied;
  • Require conversation resolution before merging (6) = checks how many default branches have the protection rule Require conversation resolution before merging applied;
  • Require signed commits (7) = checks how many default branches have the protection rule Require signed commits applied;
  • Require linear history (8) = checks how many default branches have the protection rule Require linear history applied;
  • Include administrators (9) = checks how many default branches have the protection rule Include administrators applied;
  • Restrict who can push to matching branches (10) = checks how many default branches have the protection rule Restrict who can push to matching branches applied;
  • Allow force pushes (11) = checks how many default branches have the protection rule Allow force pushes applied;
  • Allow deletions (12) = checks how many default branches have the protection rule Allow deletions applied.

--

--

--

Tech Solution Architect Manager na Accenture

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Serverless Spring MVC with AWS Lambda

8 Most Common Questions About FNE

Top Automation Programming Languages of 2021

GameDevHQ — Day 13 — Building a Better Homing Laser Pt. 1

Froxt extensibility update

25 IPython Tips for Your Next Advent of Code

15 Ways We Prove We Know Our Stuff | Web Developer

Discriminating Mirror

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vinicius Moura

Vinicius Moura

Tech Solution Architect Manager na Accenture

More from Medium

How to: Create Dashboard to visualize Branches ahead/behind on GitHub

Cheat sheet — Running a MSSQL Server instance using Docker Desktop

Create a simple azure function

It’s time to tidy up your code: How to use Visual Studio Code Autoformat