Skip to content

Commit d116a78

Browse files
committed
remove error_chain dependency in favor of std::error
1 parent 89f0bb9 commit d116a78

36 files changed

+831
-874
lines changed

Diff for: CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 0.6.0
22

3-
* BREAKING CHANGE: Migrate from old `futures` crate futures to std library futures making it possible to use `async`/`await` with this library. Please see the examples directory for updated examples of how to use these. [#254](https://github.com/softprops/hubcaps/pull/254)
3+
* BREAKING CHANGE: Migrate from old `futures` crate futures to std library futures making it possible to use `async`/`await` with this library. This puts this library in better compatibility with the current rust async ecosystem. Please see the examples directory for updated examples of how to use these. [#254](https://github.com/softprops/hubcaps/pull/254)
4+
* BREAKING CHANGE: replace `error_chain` derived errors with `std::error::Error` implementing `Error` enum. The motivation is that the error crate ecosystem is a moving target. The `std::error` package is not. This also makes for a smaller crate and smaller surface area. This moves away from errors of the form `Error(ErrorKind::Codec(_), _)` to errors of the form `Error::Codec(_)`
45
* Add support for Content create and update apis [#253](https://github.com/softprops/hubcaps/pull/253)
56
* Add description field to label apis [#252](https://github.com/softprops/hubcaps/pull/252)
67
* Make status fields `created_at`, `updated_at` and `target_url` optional [#250](https://github.com/softprops/hubcaps/pull/250) [#249](https://github.com/softprops/hubcaps/pull/249)

Diff for: Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ reqwest = { version = "0.10", default-features = false }
3333
serde = { version = "1.0.84", features = ['derive'] }
3434
serde_derive = "1.0"
3535
serde_json = "1.0"
36-
error-chain = "0.12"
3736
base64 = "0.12"
3837
percent-encoding = "2"
3938

Diff for: examples/assignees.rs

+25-29
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
1+
use hubcaps::{Credentials, Github};
12
use std::env;
2-
3-
use hubcaps::{Credentials, Github, Result};
3+
use std::error::Error;
44

55
#[tokio::main]
6-
async fn main() -> Result<()> {
6+
async fn main() -> Result<(), Box<dyn Error>> {
77
pretty_env_logger::init();
8-
match env::var("GITHUB_TOKEN").ok() {
9-
Some(token) => {
10-
let github = Github::new(
11-
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
12-
Credentials::Token(token),
13-
)?;
14-
let pull = github
15-
.repo("softprops", "hubcaps")
16-
.pulls()
17-
.get(122)
18-
.assignees()
19-
.add(vec!["softprops"])
20-
.await?;
21-
println!("{:#?}", pull);
8+
let token = env::var("GITHUB_TOKEN")?;
9+
let github = Github::new(
10+
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
11+
Credentials::Token(token),
12+
)?;
13+
let pull = github
14+
.repo("softprops", "hubcaps")
15+
.pulls()
16+
.get(122)
17+
.assignees()
18+
.add(vec!["softprops"])
19+
.await?;
20+
println!("{:#?}", pull);
2221

23-
let issue = github
24-
.repo("softprops", "hubcaps")
25-
.issues()
26-
.get(125)
27-
.assignees()
28-
.add(vec!["softprops"])
29-
.await?;
30-
println!("{:#?}", issue);
31-
Ok(())
32-
}
33-
_ => Err("example missing GITHUB_TOKEN".into()),
34-
}
22+
let issue = github
23+
.repo("softprops", "hubcaps")
24+
.issues()
25+
.get(125)
26+
.assignees()
27+
.add(vec!["softprops"])
28+
.await?;
29+
println!("{:#?}", issue);
30+
Ok(())
3531
}

Diff for: examples/branches.rs

+48-53
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,58 @@
1-
use std::env;
2-
31
use futures::prelude::*;
4-
52
use hubcaps::branches::Protection;
6-
use hubcaps::{Credentials, Github, Result};
3+
use hubcaps::{Credentials, Github};
4+
use std::env;
5+
use std::error::Error;
76

87
#[tokio::main]
9-
async fn main() -> Result<()> {
8+
async fn main() -> Result<(), Box<dyn Error>> {
109
pretty_env_logger::init();
11-
match env::var("GITHUB_TOKEN").ok() {
12-
Some(token) => {
13-
let github = Github::new(
14-
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
15-
Credentials::Token(token),
16-
)?;
10+
let token = env::var("GITHUB_TOKEN")?;
11+
let github = Github::new(
12+
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
13+
Credentials::Token(token),
14+
)?;
1715

18-
if let Err(err) = github
19-
.repo("softprops", "hubcaps")
20-
.branches()
21-
.iter()
22-
.try_for_each(|branch| async move {
23-
println!("{:#?}", branch);
24-
Ok(())
25-
})
26-
.await
27-
{
28-
println!("err {:#?}", err)
29-
}
16+
if let Err(err) = github
17+
.repo("softprops", "hubcaps")
18+
.branches()
19+
.iter()
20+
.try_for_each(|branch| async move {
21+
println!("{:#?}", branch);
22+
Ok(())
23+
})
24+
.await
25+
{
26+
println!("err {:#?}", err)
27+
}
3028

31-
match github
32-
.repo("softprops", "hubcaps")
33-
.branches()
34-
.get("master")
35-
.await
36-
{
37-
Ok(branch) => println!("{:#?}", branch),
38-
Err(err) => println!("err {:#?}", err),
39-
}
29+
match github
30+
.repo("softprops", "hubcaps")
31+
.branches()
32+
.get("master")
33+
.await
34+
{
35+
Ok(branch) => println!("{:#?}", branch),
36+
Err(err) => println!("err {:#?}", err),
37+
}
4038

41-
// protect master branch
42-
match github
43-
.repo("softprops", "hubcaps")
44-
.branches()
45-
.protection(
46-
"master",
47-
&Protection {
48-
required_status_checks: None,
49-
enforce_admins: false,
50-
required_pull_request_reviews: None,
51-
restrictions: None,
52-
},
53-
)
54-
.await
55-
{
56-
Ok(pro) => println!("{:#?}", pro),
57-
Err(err) => println!("err {:#?}", err),
58-
}
59-
Ok(())
60-
}
61-
_ => Err("example missing GITHUB_TOKEN".into()),
39+
// protect master branch
40+
match github
41+
.repo("softprops", "hubcaps")
42+
.branches()
43+
.protection(
44+
"master",
45+
&Protection {
46+
required_status_checks: None,
47+
enforce_admins: false,
48+
required_pull_request_reviews: None,
49+
restrictions: None,
50+
},
51+
)
52+
.await
53+
{
54+
Ok(pro) => println!("{:#?}", pro),
55+
Err(err) => println!("err {:#?}", err),
6256
}
57+
Ok(())
6358
}

Diff for: examples/checks.rs

+11-19
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
1-
use std::env;
2-
use std::fs::File;
3-
use std::io::Read;
4-
51
use hubcaps::checks::{
62
Action, Annotation, AnnotationLevel, CheckRunOptions, Conclusion, Image, Output,
73
};
84
use hubcaps::git::GetReferenceResponse;
9-
use hubcaps::{Credentials, Github, InstallationTokenGenerator, JWTCredentials, Result};
10-
11-
fn var(name: &str) -> Result<String> {
12-
if let Ok(v) = env::var(name) {
13-
Ok(v)
14-
} else {
15-
Err(format!("example missing {}", name).into())
16-
}
17-
}
5+
use hubcaps::{Credentials, Github, InstallationTokenGenerator, JWTCredentials};
6+
use std::env;
7+
use std::error::Error;
8+
use std::fs::File;
9+
use std::io::Read;
1810

1911
const USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
2012

2113
#[tokio::main]
22-
async fn main() -> Result<()> {
14+
async fn main() -> Result<(), Box<dyn Error>> {
2315
pretty_env_logger::init();
24-
let key_file = var("GH_APP_KEY")?;
25-
let app_id = var("GH_APP_ID")?;
26-
let user_name = var("GH_USERNAME")?;
27-
let repo = var("GH_REPO")?;
28-
let branch = var("GH_BRANCH")?;
16+
let key_file = env::var("GH_APP_KEY")?;
17+
let app_id = env::var("GH_APP_ID")?;
18+
let user_name = env::var("GH_USERNAME")?;
19+
let repo = env::var("GH_REPO")?;
20+
let branch = env::var("GH_BRANCH")?;
2921

3022
let mut key = Vec::new();
3123
File::open(&key_file)?.read_to_end(&mut key)?;

Diff for: examples/collaborators.rs

+38-41
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,50 @@
1-
use hubcaps::{self, Credentials, Github, Result};
1+
use hubcaps::{self, Credentials, Github};
22
use std::env;
3+
use std::error::Error;
34

45
#[tokio::main]
5-
async fn main() -> Result<()> {
6+
async fn main() -> Result<(), Box<dyn Error>> {
67
pretty_env_logger::init();
7-
match env::var("GITHUB_TOKEN").ok() {
8-
Some(token) => {
9-
let github = Github::new(
10-
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
11-
Credentials::Token(token),
12-
)?;
8+
let token = env::var("GITHUB_TOKEN")?;
9+
let github = Github::new(
10+
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
11+
Credentials::Token(token),
12+
)?;
1313

14-
println!("My organizations:");
15-
println!();
14+
println!("My organizations:");
15+
println!();
1616

17-
for org in github.orgs().list().await? {
18-
println!("{}", org.login);
19-
println!("=============");
20-
println!("Repos:");
17+
for org in github.orgs().list().await? {
18+
println!("{}", org.login);
19+
println!("=============");
20+
println!("Repos:");
2121

22-
for repo in github
23-
.org_repos(&org.login[..])
24-
.list(&Default::default())
25-
.await?
26-
{
27-
println!("* {}", repo.name);
22+
for repo in github
23+
.org_repos(&org.login[..])
24+
.list(&Default::default())
25+
.await?
26+
{
27+
println!("* {}", repo.name);
2828

29-
// If you have push permissions on an org, you can list collaborators.
30-
// Otherwise, don't print them.
31-
if let Ok(collabs) = github
32-
.repo(&org.login[..], &repo.name[..])
33-
.collaborators()
34-
.list()
35-
.await
36-
{
37-
println!(
38-
" * Collaborators: {}",
39-
collabs
40-
.into_iter()
41-
.map(|c| { c.login })
42-
.collect::<Vec<_>>()
43-
.join(", ")
44-
);
45-
}
46-
}
47-
println!()
29+
// If you have push permissions on an org, you can list collaborators.
30+
// Otherwise, don't print them.
31+
if let Ok(collabs) = github
32+
.repo(&org.login[..], &repo.name[..])
33+
.collaborators()
34+
.list()
35+
.await
36+
{
37+
println!(
38+
" * Collaborators: {}",
39+
collabs
40+
.into_iter()
41+
.map(|c| { c.login })
42+
.collect::<Vec<_>>()
43+
.join(", ")
44+
);
4845
}
49-
Ok(())
5046
}
51-
_ => Err("example missing GITHUB_TOKEN".into()),
47+
println!()
5248
}
49+
Ok(())
5350
}

Diff for: examples/comments.rs

+14-17
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
use hubcaps::comments::CommentOptions;
2-
use hubcaps::{Credentials, Github, Result};
2+
use hubcaps::{Credentials, Github};
33
use std::env;
4+
use std::error::Error;
45

56
const USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
67

78
#[tokio::main]
8-
async fn main() -> Result<()> {
9+
async fn main() -> Result<(), Box<dyn Error>> {
910
pretty_env_logger::init();
10-
match env::var("GITHUB_TOKEN").ok() {
11-
Some(token) => {
12-
let github = Github::new(USER_AGENT, Credentials::Token(token))?;
11+
let token = env::var("GITHUB_TOKEN")?;
12+
let github = Github::new(USER_AGENT, Credentials::Token(token))?;
1313

14-
let issue = github.repo("softprops", "hubcat").issues().get(1);
15-
let f = issue.comments().create(&CommentOptions {
16-
body: format!("Hello, world!\n---\nSent by {}", USER_AGENT),
17-
});
14+
let issue = github.repo("softprops", "hubcat").issues().get(1);
15+
let f = issue.comments().create(&CommentOptions {
16+
body: format!("Hello, world!\n---\nSent by {}", USER_AGENT),
17+
});
1818

19-
match f.await {
20-
Ok(comment) => println!("{:?}", comment),
21-
Err(err) => println!("err {}", err),
22-
}
23-
24-
Ok(())
25-
}
26-
_ => Err("example missing GITHUB_TOKEN".into()),
19+
match f.await {
20+
Ok(comment) => println!("{:?}", comment),
21+
Err(err) => println!("err {}", err),
2722
}
23+
24+
Ok(())
2825
}

Diff for: examples/conditional_requests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use hubcaps::Result;
21
#[cfg(feature = "httpcache")]
32
use hubcaps::{Github, HttpCache};
43
#[cfg(feature = "httpcache")]
54
use reqwest::Client;
5+
use std::error::Error;
66

77
#[tokio::main]
8-
async fn main() -> Result<()> {
8+
async fn main() -> Result<(), Box<dyn Error>> {
99
pretty_env_logger::init();
1010

1111
#[cfg(not(feature = "httpcache"))]

0 commit comments

Comments
 (0)