-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
op_backfill.rs
92 lines (80 loc) · 2.88 KB
/
op_backfill.rs
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! bPrint to stdout a new maintainer list Nix file, with as many IDs
//! filled in as possible.
#![warn(missing_docs)]
use crate::cli::ExitError;
use crate::filemunge;
use crate::maintainerhistory::{Confidence, MaintainerHistory};
use crate::maintainers::{GitHubID, GitHubName, MaintainerList};
use hubcaps::Github;
use std::collections::HashMap;
use std::fs::read_to_string;
use std::path::Path;
use tokio::runtime::Runtime;
pub fn backfill_ids(
logger: slog::Logger,
github: Github,
file: &Path,
maintainers: MaintainerList,
) -> Result<(), ExitError> {
let mut rt = Runtime::new().unwrap();
let missing_ids = maintainers
.into_iter()
.filter(|(_handle, maintainer)| {
maintainer.github.is_some() && maintainer.github_id.is_none()
})
.map(|(handle, maintainer)| {
(
maintainer
.github
.clone()
.expect("should be safe because of prior filter"),
maintainer,
handle,
)
});
info!(logger, "Loading the maintainer list's GitHub accounts and blame history";
"commit" => "");
let history = MaintainerHistory::load(logger.clone(), file);
info!(logger, "Loaded the maintainer list's GitHub accounts and blame history";
"commit" => "");
let found_ids: HashMap<GitHubName, GitHubID> = missing_ids
.filter_map(|(github_name, maintainer, handle)| {
debug!(logger, "Getting ID for user";
"github_account" => %github_name,
);
match rt.block_on(github.users().get(github_name.to_string())) {
Ok(user) => {
debug!(logger, "Found ID for user";
"github_account" => %github_name,
"id" => %user.id);
Some((github_name, maintainer, GitHubID::new(user.id), handle))
}
Err(e) => {
warn!(logger, "Error fetching ID for user";
"github_account" => %github_name,
"e" => %e);
None
}
}
})
.filter_map(|(github_name, _maintainer, github_id, handle)| {
let confidence =
history.confidence_for_user(&github, &handle, &github_name, github_id)?;
if confidence == Confidence::Total {
Some((github_name, github_id))
} else {
info!(logger,
"Non-total confidence for user";
"confidence" => %format!("{:#?}", confidence),
"user" => %handle,
);
None
}
})
.collect();
println!(
"{}",
filemunge::backfill_file(found_ids, read_to_string(file)?,)
);
Ok(())
}