-
Notifications
You must be signed in to change notification settings - Fork 645
WIP: Teams #177
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
Merged
Merged
WIP: Teams #177
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
48dabb6
Add Team ownership support to crates.io
Gankra 5da6d2a
remove check; fixes #176
Gankra 7df1563
Fixup all the tests
Gankra ff22cee
make system robust to permission failures
Gankra 2009af8
some initial cleanups
Gankra 279898f
more progress
Gankra 4ca5699
tests and refactoring
Gankra a52f239
refactor
Gankra ae369c6
make tests reproducable by not me
Gankra d69e905
cleanup tests
Gankra e62e56e
cleanup http
Gankra a74c034
clean up http more
Gankra fd0cc6a
fixup krate
Gankra 19d59ae
style cleanup
Gankra c2ddecd
update erythang
Gankra cfb23d5
major overhaul
Gankra e5ace68
more tests and cleanup
Gankra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 file contains hidden or 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 file contains hidden or 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 file contains hidden or 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 file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use curl; | ||
use oauth2::*; | ||
use app::App; | ||
use util::{CargoResult, internal, ChainError, human}; | ||
use rustc_serialize::{json, Decodable}; | ||
use std::str; | ||
|
||
|
||
/// Does all the nonsense for sending a GET to Github. Doesn't handle parsing | ||
/// because custom error-code handling may be desirable. Use | ||
/// parse_github_response to handle the "common" processing of responses. | ||
pub fn github(app: &App, url: &str, auth: &Token) | ||
-> Result<curl::http::Response, curl::ErrCode> { | ||
info!("GITHUB HTTP: {}", url); | ||
|
||
let url = if app.config.env == ::Env::Test { | ||
format!("http://api.github.com{}", url) | ||
} else { | ||
format!("https://api.github.com{}", url) | ||
}; | ||
|
||
app.handle() | ||
.get(url) | ||
.header("Accept", "application/vnd.github.v3+json") | ||
.header("User-Agent", "hello!") | ||
.auth_with(auth) | ||
.exec() | ||
} | ||
|
||
/// Checks for normal responses | ||
pub fn parse_github_response<T: Decodable>(resp: curl::http::Response) | ||
-> CargoResult<T> { | ||
match resp.get_code() { | ||
200 => {} // Ok! | ||
403 => { | ||
return Err(human("It looks like you don't have permission \ | ||
to query a necessary property from Github | ||
to complete this request. \ | ||
You may need to re-authenticate on \ | ||
crates.io to grant permission to read \ | ||
github org memberships. Just go to \ | ||
https://crates.io/login")); | ||
} | ||
_ => { | ||
return Err(internal(format!("didn't get a 200 result from | ||
github: {}", resp))); | ||
} | ||
} | ||
|
||
let json = try!(str::from_utf8(resp.get_body()).ok().chain_error(||{ | ||
internal("github didn't send a utf8-response") | ||
})); | ||
|
||
json::decode(json).chain_error(|| { | ||
internal("github didn't send a valid json response") | ||
}) | ||
} | ||
|
||
/// Gets a token with the given string as the access token, but all | ||
/// other info null'd out. Generally, just to be fed to the `github` fn. | ||
pub fn token(token: String) -> Token { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a comment here indicating that this is intended to pass to the function above? (e.g. the scopes/token_type are blank) |
||
Token { | ||
access_token: token, | ||
scopes: Vec::new(), | ||
token_type: String::new(), | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function might be a lot nicer to call if it was something along the lines of:
Basically something that does the decoding for you automatically and fills in an error for bad JSON and bad utf-8-ness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response-code handling isn't uniform, though. In particular when querying team membership, 404 is how Github reports "false". Do you want this to take a closure for (maybe) processing the error code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made two fns, one for querying, one for parsing, so that you can intermediate evaluation of the request as desired.