mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-07-30 13:47:46 +00:00
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 ```
This commit is contained in:
parent
618c0c035d
commit
9ec598c72a
1 changed files with 34 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue