-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
New hub api
command for making GitHub API requests
#2016
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This ensures that calling `hub api http://example.com/foo` doesn't accidentally send the OAuth token for `github.com` to `example.com`.
- sort query string in cache key - include "Accept", "Authorization" headers in cache key - allow caching of `/graphql` responses
Real-world usage example in bash: # Usage: search [-<LIMIT>] <SEARCH-TERM> [<PAGINATION-CURSOR>]
search() {
local args=()
if [ "${1#-}" -gt 0 ] 2>/dev/null; then
args+=(-F n="${1#-}")
shift 1
fi
args+=(-f q="${1?}")
[ $# -ge 2 ] && args+=(-f after="${2?}")
hub api -t --cache 3600 graphql "${args[@]}" -f query='
query($q: String!, $n: Int = 10, $after: String) {
search(query: $q, type: REPOSITORY, first: $n, after: $after) {
edges {
node {
...on Repository {
nameWithOwner
stargazers {
totalCount
}
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
'
}
$ search -3 "rollup plugin"
.data.search.edges.[0].node.nameWithOwner rollup/rollup-plugin-commonjs
.data.search.edges.[0].node.stargazers.totalCount 360
.data.search.edges.[1].node.nameWithOwner vuejs/rollup-plugin-vue
.data.search.edges.[1].node.stargazers.totalCount 453
.data.search.edges.[2].node.nameWithOwner rollup/rollup-plugin-node-resolve
.data.search.edges.[2].node.stargazers.totalCount 319
.data.search.pageInfo.hasNextPage true
.data.search.pageInfo.endCursor Y3Vyc29yOjM=
$ search -3 "rollup plugin" Y3Vyc29yOjM=
.data.search.edges.[0].node.nameWithOwner rollup/rollup-plugin-babel
.data.search.edges.[0].node.stargazers.totalCount 527
.data.search.edges.[1].node.nameWithOwner egoist/rollup-plugin-postcss
.data.search.edges.[1].node.stargazers.totalCount 222
.data.search.edges.[2].node.nameWithOwner rollup/rollup-plugin-typescript
.data.search.edges.[2].node.stargazers.totalCount 203
.data.search.pageInfo.hasNextPage true
.data.search.pageInfo.endCursor Y3Vyc29yOjY= |
This was referenced Jan 26, 2019
Closed
Closed
Closed
This was referenced Jan 26, 2019
netbsd-srcmastr
pushed a commit
to NetBSD/pkgsrc
that referenced
this pull request
Jan 27, 2019
pkgsrc changes: * Add logic to generate man page via pre-install target instead of generating it manually Changes: ### Changes since v2.7 * New `hub api` command for scripting with GitHub API <mislav/hub#2016> * Re-implement CLI flag parsing so that `--message <MSG>` is equivalent to `--message=<MSG>` <mislav/hub#2008> * Re-implement `make man-pages` in Go instead of Ruby <mislav/hub#1990> * `issue create --label` is now `issue create --labels` to align with existing documentation * Output crash debugging information on stderr instead of stdout * Build improvements: - respect environment LDFLAGS - strip the build path from resulting executable - enable reproducible builds with SOURCE_DATE_EPOCH
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goals:
hub api
Features:
{owner}
and{repo}
placeholders with values from current repositoryThe above abilities also make it possible to make GraphQL queries, since that simply involves encoding/decoding JSON from the
/graphql
endpoint.Examples: