~raboof/nixpkgs-contributor-dashboard

ref: 08df9196d56f45cbba0d6d9feeb1231481539f68 nixpkgs-contributor-dashboard/src/bin/clean_pulls.rs -rw-r--r-- 1.4 KiB
08df9196 — Arnout Engelen Add feature for clearing PR's 1 year, 8 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
extern crate nixpkgs_contributor_dashboard;
extern crate diesel;
extern crate dotenv;

use self::nixpkgs_contributor_dashboard::*;
use self::models::*;
use self::diesel::prelude::*;

use std::env;
use github_rs::client::{Executor, Github};
use serde::Deserialize;
use dotenv::dotenv;

use nixpkgs_contributor_dashboard::schema::items::dsl::*;

#[derive(Deserialize, Debug)]
pub struct Pull {
    pub state: String,
}

fn closed(client: &Github, item: &Item) -> bool {
    let owner = "nixos";
    let repo = "nixpkgs";
    let endpoint = format!(
        "repos/{}/{}/pulls/{}",
        owner, repo, item.number
        );
    println!("Getting pr {}", item.html_url);
    let pr = client.get()
        .custom_endpoint(&endpoint)
        .execute::<Pull>();
    match pr {
        Ok((_headers, _status, entity)) =>
            return entity.unwrap().state == "closed",
        Err(e) => {
            println!("{}", e);
            return false
        }
    }
}

fn main() {
    dotenv().ok();
    let client = Github::new(env::var("GITHUB_TOKEN").unwrap()).unwrap();

    let connection = establish_connection();
    let results = items.filter(kind.eq("PR")).load::<Item>(&connection)
        .expect("Error loading items");
    for item in results {
        if closed(&client, &item) {
            diesel::delete(&item).execute(&connection).expect("Error deleting");
        }
    }
}