Skip to content

Commit

Permalink
Merge pull request #4 from orf/remove-reqwest
Browse files Browse the repository at this point in the history
Remove reqwest
  • Loading branch information
orf authored Oct 19, 2019
2 parents 433808e + 9577c88 commit 2b8dbbe
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 39 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GCM_INTERACTIVE: never
GIT_TERMINAL_PROMPT: 0
RUST_BACKTRACE: "1"
steps:
- uses: actions/checkout@master
- name: Switch SSH to https
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ failure = "0.1.6"
structopt = "0.3.3"
rayon = "1.2.0"
graphql_client = "0.8.0"
reqwest = "0.9.22"
walkdir = "2.2.9"
fs_extra = "1.1.0"
indicatif = { version = "0.12.0", features = ["with_rayon"] }
console = { version = "0.9.0", default_features = false } # We don't care about unicode widths
atomic-counter = "1.0.1"
ureq = { version = "0.11.0", features = ["json"] }
serde_json = "1.0.41"

[target."cfg(unix)".dependencies]
expanduser = "1.2.1"
Expand Down
31 changes: 16 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ extern crate expanduser;
extern crate fs_extra;
extern crate graphql_client;
extern crate indicatif;
extern crate reqwest;
extern crate serde;
extern crate ureq;
#[macro_use]
extern crate serde_json;
extern crate structopt;
extern crate walkdir;

Expand Down Expand Up @@ -86,17 +88,16 @@ fn handle_main(args: Args) -> Result<(), Error> {
.context("Error expanding git workspace path")?;
}

let path_str = (match workspace_path.exists() {
true => &workspace_path,
false => {
fs_extra::dir::create_all(&workspace_path, false).context(format!(
"Error creating workspace directory {}",
&workspace_path.display()
))?;
println!("Created {} as it did not exist", &workspace_path.display());
let path_str = (if workspace_path.exists() {
&workspace_path
} else {
fs_extra::dir::create_all(&workspace_path, false).context(format!(
"Error creating workspace directory {}",
&workspace_path.display()
))?;
println!("Created {} as it did not exist", &workspace_path.display());

&workspace_path
}
&workspace_path
})
.canonicalize()
.context(format!(
Expand All @@ -107,11 +108,11 @@ fn handle_main(args: Args) -> Result<(), Error> {
match args.command {
Command::List { full } => list(&workspace_path, full)?,
Command::Update { threads } => {
lock(&workspace_path)?;
update(&workspace_path, threads)?
lock(&path_str)?;
update(&path_str, threads)?
}
Command::Fetch { threads } => fetch(&workspace_path, threads)?,
Command::Add(provider) => add_provider_to_config(&workspace_path, provider)?,
Command::Fetch { threads } => fetch(&path_str, threads)?,
Command::Add(provider) => add_provider_to_config(&path_str, provider)?,
};
Ok(())
}
Expand Down
16 changes: 7 additions & 9 deletions src/providers/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ impl Provider for GithubProvider {
fn fetch_repositories(&self) -> Result<Vec<Repository>, Error> {
let github_token =
env::var("GITHUB_TOKEN").context("Missing GITHUB_TOKEN environment variable")?;
let client = reqwest::Client::new();
let mut repositories = vec![];

let mut after = None;
Expand All @@ -66,15 +65,14 @@ impl Provider for GithubProvider {
login: self.name.clone(),
after,
});
let mut res = client
.post("https://api.github.com/graphql")
.bearer_auth(github_token.as_str())
.json(&q)
.send()?;
let response_body: Response<repositories::ResponseData> = res.json()?;
let response_data: repositories::ResponseData =
response_body.data.expect("missing response data");
let res = ureq::post("https://api.github.com/graphql")
.set("Authorization", format!("Bearer {}", github_token).as_str())
.send_json(json!(&q));
let response_data: Response<repositories::ResponseData> =
serde_json::from_value(res.into_json()?)?;
let response_repositories = response_data
.data
.expect("Missing data")
.repository_owner
.expect("missing repository owner")
.repositories;
Expand Down
29 changes: 15 additions & 14 deletions src/providers/gitlab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ impl GitlabProvider {
) -> Result<Vec<Repository>, Error> {
let github_token =
env::var("GITLAB_TOKEN").context("Missing GITLAB_TOKEN environment variable")?;
let client = reqwest::Client::new();
let mut repositories = vec![];
let q = UserRepositories::build_query(user_repositories::Variables {
name: name.to_string(),
after: Some("".to_string()),
});
let mut res = client
.post(format!("{}/api/graphql", url).as_str())
.bearer_auth(github_token.as_str())
.json(&q)
.send()?;
let response_body: Response<user_repositories::ResponseData> = res.json()?;
let res = ureq::post(format!("{}/api/graphql", url).as_str())
.set("Authorization", format!("Bearer {}", github_token).as_str())
.set("Content-Type", "application/json")
.send_json(json!(&q));
let json = res.into_json()?;
let response_body: Response<user_repositories::ResponseData> =
serde_json::from_value(json)?;
let gitlab_repositories = response_body
.data
.expect("Missing data")
Expand All @@ -97,6 +97,7 @@ impl GitlabProvider {
.filter_map(|x| x)
// Extract the node, which is also Some(T)
.filter_map(|x| x.node);

for repo in gitlab_repositories {
if repo.archived.unwrap() {
continue;
Expand All @@ -120,18 +121,18 @@ impl GitlabProvider {
) -> Result<Vec<Repository>, Error> {
let github_token =
env::var("GITLAB_TOKEN").context("Missing GITLAB_TOKEN environment variable")?;
let client = reqwest::Client::new();
let mut repositories = vec![];
let q = GroupRepositories::build_query(group_repositories::Variables {
name: name.to_string(),
after: Some("".to_string()),
});
let mut res = client
.post(format!("{}/api/graphql", url).as_str())
.bearer_auth(github_token.as_str())
.json(&q)
.send()?;
let response_body: Response<group_repositories::ResponseData> = res.json()?;
let res = ureq::post(format!("{}/api/graphql", url).as_str())
.set("Authorization", format!("Bearer {}", github_token).as_str())
.set("Content-Type", "application/json")
.send_json(json!(&q));
let json = res.into_json()?;
let response_body: Response<group_repositories::ResponseData> =
serde_json::from_value(json)?;
let gitlab_repositories = response_body
.data
.expect("Missing data")
Expand Down

0 comments on commit 2b8dbbe

Please sign in to comment.