This repository was archived by the owner on Nov 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
This repository was archived by the owner on Nov 19, 2020. It is now read-only.
Add minimal documentation for libgerrit #27
Copy link
Copy link
Open
Description
Hello,
First thanks for your implementation, I was starting to copy Gerrit's JSON answers as structs for Serde and though someone else must have been working on this elsewhere.
However I am only using the structs right now with reqwest HTTP library because there is no documentation on how to use the libgerrit as a client. Here is my current code if anyone is interrested:
extern crate reqwest;
extern crate libgerrit;
extern crate chrono;
extern crate env_proxy;
extern crate serde_json;
use reqwest::Error;
use reqwest::Url;
use chrono::prelude::*;
use libgerrit::entities::ChangeInfo;
fn run() -> Result<(), Error> {
let url = Url::parse("https://example.com/gerrit/a/changes/?q=project:test+status:open&n=100&O=81").unwrap();
let proxy = env_proxy::for_url(&url).raw_value().unwrap();
let mut res = reqwest::Client::builder()
.proxy(reqwest::Proxy::http(&proxy)?)
.build()?
.get(url)
.basic_auth("test", Some("not_a_chance"))
.send()?;
let text = res.text()?;
// The first 4 characters of the Gerrit API are garbage for some reasons
let items: Vec<ChangeInfo> = serde_json::from_str(&text[4..]).unwrap();
println!("There are {} reviews open:", items.len());
for item in items {
let created = Utc.datetime_from_str(&item.created, "%Y-%m-%d %H:%M:%S.%f").unwrap();
let now = Utc::now();
println!("{:?} -> {}", now.signed_duration_since(created).num_days(), item.subject);
}
Ok(())
}
fn main() {
run().unwrap();
}I think if you add a minimum of documentation we can switch to using your lib with curl instead of this custom implementation. However I am not even sure how to pass http_auth arguments by reading the code.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels