Skip to content
This repository was archived by the owner on Nov 19, 2020. It is now read-only.
This repository was archived by the owner on Nov 19, 2020. It is now read-only.

Add minimal documentation for libgerrit #27

@gagath

Description

@gagath

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions