-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.rs
80 lines (70 loc) · 2.09 KB
/
main.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
use clap::Parser;
use color_eyre::eyre;
use octocrab::models::issues::Issue;
/// Summarize the recent activity of the given user within the given timeframe
#[derive(Parser, Debug)]
#[clap(author, version, about)]
struct Args {
#[clap(subcommand)]
command: commands::Commands,
/// Github personal access token
#[clap(short, long, env = "GITHUB_TOKEN")]
github_token: String,
}
mod commands {
mod reviewers;
mod user;
use color_eyre::eyre;
use reviewers::Reviewers;
use user::User;
use clap::Subcommand;
#[derive(Subcommand, Debug)]
pub enum Commands {
/// Lookup activity by user and timeframe
User(User),
/// Lookup review activity by repo, timeframe, and tags
Reviewers(Reviewers),
}
impl Commands {
pub async fn run(&self) -> eyre::Result<()> {
match self {
Commands::User(user) => user.run().await,
Commands::Reviewers(reviewers) => reviewers.run().await,
}
}
}
}
#[tokio::main]
async fn main() -> eyre::Result<()> {
// not an error if dotenv isn't present, so completely discard the results
let _ = dotenv::dotenv();
color_eyre::config::HookBuilder::default().install()?;
let args = Args::parse();
octocrab::initialise(
octocrab::Octocrab::builder().personal_token(args.github_token.to_string()),
)?;
args.command.run().await?;
Ok(())
}
trait IssueExt {
fn repo(&self) -> &str;
fn owner(&self) -> &str;
}
impl IssueExt for Issue {
fn repo(&self) -> &str {
self.repository_url
.path_segments()
.expect("repo urls will always have some path segments")
.rev()
.next()
.expect("the last path segment of a repo url is always the repo name")
}
fn owner(&self) -> &str {
self.repository_url
.path_segments()
.expect("repo urls will always have some path segments")
.rev()
.nth(1)
.expect("the second to last path segment of a repo url is always the owner name")
}
}