Member-only story
Find GitHub Repository Id for use in GitHub REST API
Recently I came across a scenario to use GitHub REST API for updating Organization level secrets having visibility set to repositories.
Problem: Managing repository list of Organization level secrets manually is not feasible when you have 100+ repositories within the GitHub Organization. Whenever a new repository gets, we have to request GitHub admin has to manually set repository on GitHub Portal.
Solution: Use GitHub REST API to add selected repository to an organization secret
Pre-requisite: You will need an access token with admin:org scope to use the API endpoint.
Challenge: In order to use REST API to add a repository to Organization secret, we need repository id of the newly created repository. There is no direct way to retrieve a repository ID from GitHub settings or portal.
I found below workaround to find the repository id from GitHub portal:
- Open the GitHub Repository in portal
- Right click the home page and view page source — open Inspect / Developer Tools of the browser
- In the HTML page source, search for octolytics-dimension-repository_id
- You should find html tag that looks like-
HTML page source have a set of octolytics tags representing information about the GitHub repository
After extracting the repository id, I used the GitHub REST API through POSTMAN to add selected repository to an organization secret using below URL and bearer token — https://api.github.com/orgs/{org}/actions/secrets/{secret_name}/repositories/{repository_id}
Happy Coding!!!