Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listing all public repositories of a github user/organization #1419

Closed
cbcoutinho opened this Issue Feb 17, 2017 · 4 comments

Comments

Projects
None yet
4 participants
@cbcoutinho
Copy link

cbcoutinho commented Feb 17, 2017

I really enjoy using hub, this is such a great tool.

I was wondering if it's possible to use hub to list all the github repos associated with a particular user - either through a command or autocompletion at the command line. I use bash on Linux if that makes a difference.

Cheers,
C

@mislav

This comment has been minimized.

Copy link
Member

mislav commented Feb 22, 2017

Hi, thanks for writing in with a feature idea.

Listing repositories isn't something that most git users will perform on the command-line. It seems that this would be more suited for a generic "data dump" command that could output raw data from the API for script consumption: #1407

Once that is done, we could tweak our shell completion scripts to autocomplete hub clone github/hu to github/hubot (or offer choices if there are multiple matches), but this is a long way down the road from now, and I'm not sure when we could get to that.

I'm going to close this as a duplicate. This will be possible when we have a generic API command for fetching arbitrary data.

@mislav mislav closed this Feb 22, 2017

@tfcat

This comment has been minimized.

Copy link

tfcat commented Mar 17, 2019

Think this would still be a really good feature to have! Feels out-of-place to be able to create and delete repositories from the command line, but not view them. Doing this using the generic API command becomes less trivial when you want to view private repositories.

Still hope to see this feature one day!

@mislav

This comment has been minimized.

Copy link
Member

mislav commented Mar 18, 2019

Until then, fetching all your repositories can be done with hub api:

repos() {
  local user="${1?}"
  shift 1
  paginate hub api -t graphql -f user="$user" "$@" -f query='
    query($user: String!, $per_page: Int = 100, $after: String) {
      user(login: $user) {
        repositories(first: $per_page, after: $after) {
          nodes {
            nameWithOwner
          }
          pageInfo {
            hasNextPage
            endCursor
          }
        }
      }
    }
  '
}

paginate() {
  local output cursor
  output="$("$@")"
  cursor="$(awk '/\.hasNextPage/ { has_next=$2 } /\.endCursor/ { if (has_next=="true") print $2 }' <<<"$output")"
  printf "%s\n" "$output"
  [ -z "$cursor" ] || paginate "$@" -f after="$cursor"
}

repos "tfcat" | awk '/\.nameWithOwner\t/ { print $2 }'
@gko

This comment has been minimized.

Copy link

gko commented Mar 25, 2019

In case you want to show repositories of local user(that was logged in via hub):

repos() {
  local user="${1?}"
  shift 1
  paginate hub api -t graphql -f user="$user" "$@" -f query='
    query($user: String!, $per_page: Int = 100, $after: String) {
      user(login: $user) {
        repositories(first: $per_page, after: $after) {
          nodes {
            nameWithOwner
          }
          pageInfo {
            hasNextPage
            endCursor
          }
        }
      }
    }
  '
}

paginate() {
  local output cursor
  output="$("$@")"
  cursor="$(awk '/\.hasNextPage/ { has_next=$2 } /\.endCursor/ { if (has_next=="true") print $2 }' <<<"$output")"
  printf "%s\n" "$output"
  [ -z "$cursor" ] || paginate "$@" -f after="$cursor"
}

user() {
  hub api --flat user | grep .login | awk '/.login/ {print $2}'
}

repos "$(user)" | awk '/\.nameWithOwner\t/ { print $2 }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.