Use GitHub cli (gh), how do I get a current repo name?
I can get a listing of the repos I have but how do I get the current repo?
Use GitHub cli (gh), how do I get a current repo name?
I can get a listing of the repos I have but how do I get the current repo?
To get the name of the repo in the curernt working directory, run
gh repo view --json name -q ".name"
This extracts the name of the repo from the command that lists information about the repo in the current directory, and extracts the actual name from the JSON output. For instance, if you were in the working directory for the repo with a URL of http://github.com/rust-lang/rust, the output would be rust
.
gh repo view --json nameWithOwner -q ".nameWithOwner"
–
Threshold In github actions, there are environment variables that provide this information. In particular:
GITHUB_REPOSITORY
The owner and repository name. For example, octocat/Hello-World
.GITHUB_REPOSITORY_OWNER
The repository owner's name. For example, octocat
.From this you can get the name without the owner:
${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}
The repository name. For example, Hello-World
For a full list of variables, see: https://docs.github.com/en/actions/learn-github-actions/variables
© 2022 - 2024 — McMap. All rights reserved.