bashgithubterminalgithub-pages

how to get all GitHub pages from repos associated to a username


I'm trying to write a script in MacOs terminal to quickly get all the Github.io/repository/ pages I have associated to my GitHub account.

for example: when I run this script I get the following:

https://GitHub_Username.github.io/repository1/

https://GitHub_Username.github.io/repository2/

https://GitHub_Username.github.io/repository3/

...

I have the GitHub developer setting Personal Access (classic)generated.

This is what I have so far:

#!/bin/bash

USERNAME="xxxxx"
TOKEN="ghp_yyyyy"

repos=$(curl -s -H "Authorization: token $TOKEN" "https://api.github.com/users/$USERNAME/repos")


echo "Repositories with GitHub Pages:"


for repo in $(echo "$repos" | jq -r '.[].name'); do
repo_details=$(curl -s -H "Authorization: token $TOKEN" "https://api.github.com/repos/$USERNAME/$repo")
  
 
  homepage=$(echo "$repo_details" | jq -r .homepage)

  
  if [[ "$homepage" == https://$USERNAME.github.io/* ]]; then
    echo "$repo - $homepage"
  fi
done

I then run to make it executable : chmod +x find_github_pages.sh

then to run : ./find_github_pages.sh

I get nothing so far.


Solution

  • Got the Answer..

    Don't understand why the down voting - very unnecessary..

    This is the code.

    function list-my-gh-pages() {
      curl -s "https://api.github.com/users/YOUR_USERNAME/repos?per_page=100" | \
      jq -r '.[] | select(.has_pages) | "\(.name): https://\(.owner.login).github.io/\(.name)"'
    }
    

    and run it:

    list-my-gh-pages
    

    works exactly like I want it to.