Skip to content

Commit 9ec598c

Browse files
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 ```
1 parent 618c0c0 commit 9ec598c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

custom-completions/gh/gh-completions.nu

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,3 +568,37 @@ export def "gh pr view inlined-comments" [
568568
| select user.login body diff_hunk
569569
| rename user comment diff )
570570
}
571+
572+
def "gh get stars" [
573+
end_cursor: string = "" # endCursor from a previous query
574+
--first: int = 100 # returns the first n elements from the list
575+
] {
576+
# https://docs.github.com/en/graphql/reference/objects#user
577+
^gh api graphql -F $'first=($first)' -F $'endCursor=($end_cursor)' -f query='
578+
query($first: Int, $endCursor: String!){
579+
viewer {
580+
starredRepositories(first: $first, after: $endCursor, orderBy: {field: STARRED_AT, direction: DESC}) {
581+
edges { node { url description } starredAt }
582+
pageInfo { hasNextPage endCursor }
583+
}
584+
}
585+
}
586+
'
587+
| from json | select data.viewer.starredRepositories.edges data.viewer.starredRepositories.pageInfo
588+
| rename stars pageInfo
589+
}
590+
591+
export def "gh my stars" [] {
592+
mut stars = []
593+
mut end_cursor = ""
594+
loop {
595+
let $part = gh get stars $end_cursor
596+
$stars = $stars | append $part.stars
597+
if $part.pageInfo?.hasNextPage? == true {
598+
$end_cursor = $part.pageInfo.endCursor
599+
} else {
600+
break
601+
}
602+
}
603+
$stars | flatten | update cells --columns [starredAt] {$in| date humanize} | sort-by starredAt
604+
}

0 commit comments

Comments
 (0)