githubgithub-pages

How can I find the repository that has GitHub Pages enabled and is on a given domain?


I cannot determine which of my repositories is assigned to that domain name.


Solution

  • If you happened to have set the "website" setting in the "About" section of the repo, you could figure it out like this, using the GitHub CLI:

    gh repo list \
        --limit 500 --json name,homepageUrl --jq 'map(select(.homepageUrl != ""))'
    

    This shows you a list of all repos that have a homepage set.

    However, that's a setting enabled manually, and you can put any URL in there, so it might not return useful results.

    In that case, you could iterate over every repository, and try to request the Pages site via REST API. If that succeeds, there is a page associated with the repo.

    This snippet does that, suppressing errors from the call to the /pages endpoint; remove 2> /dev/null to see all the output.

    while IFS= read -r repo; do
        if url=$(gh api "repos/$repo/pages" --jq '.html_url' 2> /dev/null); then
            printf '%s uses %s\n' "$repo" "$url"
        fi
    done < <(gh repo list --limit 500 | awk '{print $1}')