1
0
mirror of https://github.com/shimunn/gitredditor.git synced 2023-11-17 18:42:43 +01:00
This commit is contained in:
shimunn 2019-05-05 17:23:46 +02:00
commit e26ee189d7
4 changed files with 1676 additions and 0 deletions

27
.drone.yml Normal file
View File

@ -0,0 +1,27 @@
kind: pipeline
name: default
steps:
- name: build
image: rust:1.34.1
commands:
- cargo build
- name: build_relase
image: rust:1.34.1
commands:
- cargo build --release
when:
event:
- tag
- name: dockerize
image: plugins/docker
settings:
repo: gitredditor
registry: hub.docker.com
username:
from_secret: docker_username
password:
from_secret: docker_password
when:
event:
- tag

1586
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

12
Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "gitredditor"
version = "0.1.0"
authors = ["shimunn <>"]
edition = "2018"
[dependencies]
serde_json = "1.0.39"
reqwest = "0.9.16"
structopt = "0.2.15"
serde = "1.0.90"
serde_derive = "1.0.90"

51
src/model.rs Normal file
View File

@ -0,0 +1,51 @@
use serde::{Deserialize, Serialize};
use std::error::Error;
use std::iter;
use std::iter::Chain;
#[derive(Serialize, Deserialize, Debug)]
pub struct Comment {
score: u32,
id: String,
created: u64,
permalink: String,
edited: bool,
}
pub struct Comments {
pub url: String,
continuation: Option<String>,
buffer: Box<Iterator<Item = Result<Comment, Box<Error>>>>,
}
impl Iterator for Comments {
type Item = Result<Comment, Box<Error>>;
fn next(&mut self) -> Option<Self::Item> {
fn request_paged(url: &str) -> Result<(Vec<Comment>, Option<String>), Box<Error>> {
let comment_json = reqwest::get(url)?.text()?;
let continuation: Option<String> = unimplemented!();
let comments: Vec<Comment> = unimplemented!();
return Ok((comments, continuation));
}
if let Some(comment) = self.buffer.next() {
Some(comment)
} else {
self.continuation.clone().and_then(|cont| {
let page = request_paged(&self.url);
match page {
Ok((comments, cont)) => {
self.continuation = cont;
self.buffer = Box::new(comments.into_iter().map(Ok))
}
Err(e) => self.buffer = Box::new(iter::once(Err(e))),
};
self.buffer.next()
})
}
}
}