Search code examples
githubgithub-pages

Which private repos have GitHub Pages


I want to downgrade my GitHub account to the free plan. GitHub warns me that I have one private repository that uses GitHub Pages - a feature that the free plan doesn't support. So I want to find this repo to see if it is problematic if it becomes public.

I can't find any way to even list my repos that use Github Pages, let alone the ones that are private.

Is there a way to do this?


Solution

  • Yes, simple via GraphQL API, with or without GraphQL API Explorer, (don't forget personal access token scope if using without the explorer,) if you don't have very much private repos.

    Use query:

    query { 
      viewer {
        repositories (first:100, privacy: PRIVATE) {
          nodes {
            name
            deployments (first: 1) {
              nodes {
                environment
              }
            }
          }
        }
      }
    }
    

    Example result:

    {
      "data": {
        "viewer": {
          "repositories": {
            "nodes": [
              {
                "name": "repo-without-pages",
                "deployments": {
                  "nodes": []
                }
              },
              {
                "name": "repo-with-pages",
                "deployments": {
                  "nodes": [
                    {
                      "environment": "github-pages"
                    }
                  ]
                }
              }
            ]
          }
        }
      }
    }
    

    Typically the only possible environment is github-pages. If you have more, change the above query.

    Note GitHub GraphQL API has a limit: Values of first and last must be within 1-100. If you have more than 100, use:

        repositories (first:100, privacy: PRIVATE) {
          pageInfo {
            endCursor
          }
    

    and after getting endCursor:

        repositories (first:100, privacy: PRIVATE, after:"endCursorValue==") {
          pageInfo {
            endCursor
          }
    

    to paginate.