From 9ec598c72a54db67c356e00d2b5eefa72465bcba Mon Sep 17 00:00:00 2001 From: Francesc Elies Date: Thu, 1 May 2025 18:52:42 +0200 Subject: [PATCH] feat(gh): list my stars (#1109) Sometimes you know you starred something long time ago, the you go to github.com your stars and search on the bar. That's all good but wouldn't it be great to do that from the comfort of nushell? This pr does that. You can test it with ```nu gh my stars | explore ``` --- custom-completions/gh/gh-completions.nu | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/custom-completions/gh/gh-completions.nu b/custom-completions/gh/gh-completions.nu index 895c9b6..0e94ca5 100644 --- a/custom-completions/gh/gh-completions.nu +++ b/custom-completions/gh/gh-completions.nu @@ -568,3 +568,37 @@ export def "gh pr view inlined-comments" [ | select user.login body diff_hunk | rename user comment diff ) } + +def "gh get stars" [ + end_cursor: string = "" # endCursor from a previous query + --first: int = 100 # returns the first n elements from the list +] { + # https://docs.github.com/en/graphql/reference/objects#user + ^gh api graphql -F $'first=($first)' -F $'endCursor=($end_cursor)' -f query=' + query($first: Int, $endCursor: String!){ + viewer { + starredRepositories(first: $first, after: $endCursor, orderBy: {field: STARRED_AT, direction: DESC}) { + edges { node { url description } starredAt } + pageInfo { hasNextPage endCursor } + } + } + } + ' + | from json | select data.viewer.starredRepositories.edges data.viewer.starredRepositories.pageInfo + | rename stars pageInfo +} + +export def "gh my stars" [] { + mut stars = [] + mut end_cursor = "" + loop { + let $part = gh get stars $end_cursor + $stars = $stars | append $part.stars + if $part.pageInfo?.hasNextPage? == true { + $end_cursor = $part.pageInfo.endCursor + } else { + break + } + } + $stars | flatten | update cells --columns [starredAt] {$in| date humanize} | sort-by starredAt +}