replace hubcaps by octocrab (#502)

This commit replaced `hubcaps` by `octocrab`, which has more downloads per month
and receives more frequent release updates.

The caveats are:

1. When instantiating the API client, `octocrab` doesn't offer you a way to
specify custom user-agent. But I would argue that, at least presently, this
doesn't seem to cause issues.
2. `octocrab` doesn't export as much details of its error types as `hubcaps`
does. So we will have fewer control on the display of the error message. But I
would also argue that this is not really important. Though we should do more
tests to make sure the error looks good enough.

* hide implementation details in error message

Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
This commit is contained in:
Lucius Hu 2022-02-11 17:43:47 -05:00 committed by GitHub
parent 0a38c26f0d
commit 53c41b03d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 124 additions and 53 deletions

140
Cargo.lock generated
View file

@ -2,6 +2,15 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "addr2line"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
@ -38,6 +47,12 @@ version = "1.0.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0"
[[package]]
name = "arc-swap"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5d78ce20460b82d3fa150275ed9d55e21064fc7951177baacf86a145c4a4b1f"
[[package]]
name = "arrayvec"
version = "0.5.2"
@ -342,6 +357,21 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "backtrace"
version = "0.3.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e121dee8023ce33ab248d9ce1493df03c3b38a659b240096fcbd7048ff9c31f"
dependencies = [
"addr2line",
"cc",
"cfg-if 1.0.0",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]]
name = "base64"
version = "0.12.3"
@ -537,6 +567,7 @@ dependencies = [
"libc",
"num-integer",
"num-traits",
"serde",
"time",
"winapi",
]
@ -1278,10 +1309,16 @@ dependencies = [
"cfg-if 1.0.0",
"js-sys",
"libc",
"wasi 0.10.2+wasi-snapshot-preview1",
"wasi 0.10.0+wasi-snapshot-preview1",
"wasm-bindgen",
]
[[package]]
name = "gimli"
version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
[[package]]
name = "glob"
version = "0.3.0"
@ -1474,27 +1511,6 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "hubcaps"
version = "0.6.2"
source = "git+https://github.com/softprops/hubcaps.git#a9e6616ecc7b8eef0ea0eaf6055d9610c8961500"
dependencies = [
"base64 0.13.0",
"data-encoding",
"futures",
"http",
"hyperx",
"jsonwebtoken",
"log",
"mime",
"percent-encoding",
"reqwest",
"serde",
"serde_derive",
"serde_json",
"url",
]
[[package]]
name = "humantime"
version = "2.1.0"
@ -1829,11 +1845,11 @@ dependencies = [
"html5ever",
"html5gum",
"http",
"hubcaps",
"jwalk",
"lazy_static",
"linkify",
"log",
"octocrab",
"once_cell",
"openssl-sys",
"par-stream",
@ -2078,6 +2094,37 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
[[package]]
name = "object"
version = "0.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67ac1d3f9a1d3616fd9a60c8d74296f22406a238b6a72f5cc1e6f314df4ffbf9"
dependencies = [
"memchr",
]
[[package]]
name = "octocrab"
version = "0.15.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afcfecea7633fbd11141b7ce1cc4e49e01566570dd5d995ee1edb497dd340082"
dependencies = [
"arc-swap",
"async-trait",
"base64 0.13.0",
"bytes",
"chrono",
"hyperx",
"jsonwebtoken",
"once_cell",
"reqwest",
"serde",
"serde_json",
"serde_path_to_error",
"snafu",
"url",
]
[[package]]
name = "once_cell"
version = "1.9.0"
@ -2759,6 +2806,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "rustc-demangle"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
[[package]]
name = "rustc_version"
version = "0.4.0"
@ -2869,6 +2922,15 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_path_to_error"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7868ad3b8196a8a0aea99a8220b124278ee5320a55e4fde97794b6f85b1a377"
dependencies = [
"serde",
]
[[package]]
name = "serde_qs"
version = "0.8.5"
@ -2979,6 +3041,29 @@ version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309"
[[package]]
name = "snafu"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2eba135d2c579aa65364522eb78590cdf703176ef71ad4c32b00f58f7afb2df5"
dependencies = [
"backtrace",
"doc-comment",
"snafu-derive",
]
[[package]]
name = "snafu-derive"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a7fe9b0669ef117c5cabc5549638528f36771f058ff977d7689deb517833a75"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "socket2"
version = "0.3.19"
@ -3196,11 +3281,12 @@ dependencies = [
[[package]]
name = "time"
version = "0.1.43"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
]
@ -3579,9 +3665,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "wasm-bindgen"

View file

@ -7,9 +7,5 @@ members = [
]
resolver = "2"
[patch.crates-io]
# Switch back to version on crates.io after 0.6.3+ is released
hubcaps = { git="https://github.com/softprops/hubcaps.git" }
[profile.release]
debug = true

View file

@ -21,7 +21,6 @@ check-if-email-exists = "0.8.26"
fast_chemail = "0.9.6"
glob = "0.3.0"
http = "0.2.6"
hubcaps = "0.6.2"
linkify = "0.8.0"
openssl-sys = "0.9.72"
pulldown-cmark = "0.9.1"
@ -51,6 +50,7 @@ futures = "0.3.19"
lazy_static = "1.4.0"
html5ever = "0.25.1"
html5gum = "0.4.0"
octocrab = "0.15.4"
[dependencies.par-stream]
version = "0.10.0"

View file

@ -20,7 +20,7 @@ use http::{
header::{HeaderMap, HeaderValue},
StatusCode,
};
use hubcaps::{Credentials, Github};
use octocrab::Octocrab;
use regex::RegexSet;
use reqwest::header;
use tokio::time::sleep;
@ -242,7 +242,7 @@ impl ClientBuilder {
let github_client = match github_token {
Some(token) if !token.is_empty() => {
Some(Github::new(user_agent, Credentials::Token(token))?)
Some(Octocrab::builder().personal_token(token).build()?)
}
_ => None,
};
@ -282,7 +282,7 @@ pub struct Client {
/// Underlying `reqwest` client instance that handles the HTTP requests.
reqwest_client: reqwest::Client,
/// Github client.
github_client: Option<Github>,
github_client: Option<Octocrab>,
/// Rules to decided whether each link would be checked or ignored.
filter: Filter,
/// Maximum number of retries per request before returning an error.
@ -393,11 +393,11 @@ impl Client {
Some(client) => client,
None => return ErrorKind::MissingGitHubToken.into(),
};
let repo = match client.repo(uri.owner, uri.repo).get().await {
let repo = match client.repos(uri.owner, uri.repo).get().await {
Ok(repo) => repo,
Err(e) => return ErrorKind::GithubError(Some(e)).into(),
};
if repo.private {
if let Some(true) = repo.private {
// The private repo exists. Assume a given endpoint exists as well
// (e.g. `issues` in `github.com/org/private/issues`). This is not
// always the case but simplifies the check.

View file

@ -26,20 +26,9 @@ pub enum ErrorKind {
/// Reqwest network error
#[error("Network error (reqwest): {0}")]
ReqwestError(#[from] reqwest::Error),
/// Network error while using Github API (via hubcaps)
#[error("Network error (hubcaps) {}", match .0 {
Some(e) => match e {
hubcaps::Error::Fault { code, error } => format!(": {} [{}]", error.message.clone(), code),
hubcaps::Error::RateLimit { .. } => "Hit the rate limit".to_string(),
hubcaps::Error::Codec(e) => e.to_string(),
hubcaps::Error::Reqwest(e) => e.to_string(),
hubcaps::Error::Url(e) => e.to_string(),
hubcaps::Error::IO(e) => e.to_string(),
hubcaps::Error::JWT(e) => e.to_string(),
}
None => "".to_string(),
})]
GithubError(#[from] Option<hubcaps::Error>),
/// Network error while using Github API
#[error("Network error (GitHub client) {}", .0.as_ref().map_or(String::new(), std::string::ToString::to_string))]
GithubError(#[from] Option<octocrab::Error>),
/// The given string can not be parsed into a valid URL, e-mail address, or file path
#[error("Cannot parse {0} as website url / file path or mail address: ({1:?})")]
UrlParseError(String, (url::ParseError, Option<fast_chemail::ParseError>)),

View file

@ -154,8 +154,8 @@ impl From<reqwest::Error> for Status {
}
}
impl From<hubcaps::Error> for Status {
fn from(e: hubcaps::Error) -> Self {
impl From<octocrab::Error> for Status {
fn from(e: octocrab::Error) -> Self {
Self::Error(Box::new(e.into()))
}
}