cargo fix + fmt + clippy

This commit is contained in:
Timothy Andrew 2020-06-06 01:03:30 +05:30
parent 251f476577
commit de80a197ed
No known key found for this signature in database
GPG Key ID: ABD64509E977B249
7 changed files with 42 additions and 39 deletions

View File

@ -22,7 +22,7 @@ pub enum PullRequestStatus {
#[serde(rename = "open")]
Open,
#[serde(rename = "closed")]
Closed
Closed,
}
#[derive(Deserialize, Debug, Clone)]
@ -34,7 +34,7 @@ pub struct PullRequest {
title: String,
url: String,
body: String,
state: PullRequestStatus
state: PullRequestStatus,
}
impl PullRequest {
@ -57,7 +57,7 @@ impl PullRequest {
pub fn title(&self) -> String {
match &self.state {
PullRequestStatus::Open => self.title.to_owned(),
PullRequestStatus::Closed => format!("~~{}~~", &self.title.trim())
PullRequestStatus::Closed => format!("~~{}~~", &self.title.trim()),
}
}

View File

@ -1,10 +1,8 @@
use regex::Regex;
use crate::graph::FlatDep;
use crate::api::search::PullRequestStatus;
use crate::graph::FlatDep;
fn process_ref(git_ref: &str) -> String {
let re = Regex::new("heap:").unwrap();
re.replace_all(git_ref, "").into_owned()
git_ref.replace("heap:", "")
}
/// For all open pull requests in the graph, generate a series of commands
@ -13,10 +11,10 @@ fn process_ref(git_ref: &str) -> String {
/// here" marker), and is required because of our squash-merge workflow.
/// TODO: Move this directly into Rust.
pub fn generate_rebase_script(deps: FlatDep) -> String {
let deps = deps.iter().filter(|(dep, _)| {
*dep.state() == PullRequestStatus::Open
}).collect::<Vec<_>>();
let deps = deps
.iter()
.filter(|(dep, _)| *dep.state() == PullRequestStatus::Open)
.collect::<Vec<_>>();
let mut out = String::new();
@ -27,7 +25,9 @@ pub fn generate_rebase_script(deps: FlatDep) -> String {
out.push_str("# ------ THIS SCRIPT ASSUMES YOUR PR STACK IS A SINGLE CHAIN WITHOUT BRANCHING ----- #\n\n");
out.push_str("# It starts at the base of the stack, cherry-picking onto the new base and force-pushing as it goes.\n");
out.push_str("# We can't tell where the initial cherry-pick should stop (mainly because of our squash merge workflow),\n");
out.push_str("# so that initial stopping point for the first PR needs to be specified manually.\n\n");
out.push_str(
"# so that initial stopping point for the first PR needs to be specified manually.\n\n",
);
out.push_str("export PREBASE=\"<enter a marker to stop the initial cherry-pick at>\"\n");

View File

@ -1,14 +1,14 @@
use petgraph::visit::Bfs;
use petgraph::visit::EdgeRef;
use petgraph::{Direction, Graph};
use std::rc::Rc;
use std::collections::HashMap;
use std::rc::Rc;
use crate::api::search::PullRequest;
pub type FlatDep = Vec<(Rc<PullRequest>, Option<Rc<PullRequest>>)>;
pub fn build(prs: &Vec<Rc<PullRequest>>) -> Graph<Rc<PullRequest>, usize> {
pub fn build(prs: &[Rc<PullRequest>]) -> Graph<Rc<PullRequest>, usize> {
let mut tree = Graph::<Rc<PullRequest>, usize>::new();
let heads = prs.iter().map(|pr| pr.head());
let handles: Vec<_> = prs.iter().map(|pr| tree.add_node(pr.clone())).collect();
@ -25,7 +25,7 @@ pub fn build(prs: &Vec<Rc<PullRequest>>) -> Graph<Rc<PullRequest>, usize> {
}
/// Return a flattened list of graph nodes as tuples; each tuple is `(node, node's parent [if exists])`.
pub fn log(graph: &Graph<Rc<PullRequest>, usize>) -> FlatDep {
pub fn log(graph: &Graph<Rc<PullRequest>, usize>) -> FlatDep {
let roots: Vec<_> = graph.externals(Direction::Incoming).collect();
let mut out = Vec::new();

View File

@ -1,8 +1,8 @@
pub mod api;
pub mod git;
pub mod graph;
pub mod markdown;
pub mod persist;
pub mod git;
pub struct Credentials {
// Personal access token

View File

@ -1,13 +1,14 @@
use std::collections::HashMap;
use std::env;
use std::error::Error;
use std::process;
use std::io::{self, Write};
use std::rc::Rc;
use std::fs;
use std::io::{self, Write};
use std::process;
use std::rc::Rc;
use gh_stack::api::search::PullRequest;
use gh_stack::Credentials;
use gh_stack::{api, graph, markdown, persist, git};
use gh_stack::{api, git, graph, markdown, persist};
pub fn read_cli_input(message: &str) -> String {
print!("{}", message);
@ -51,7 +52,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
let credentials = Credentials::new(token);
let prs = api::search::fetch_pull_requests_matching(&pattern, &credentials).await?;
let prs = prs.into_iter().map(|pr| Rc::new(pr)).collect();
let prs = prs
.into_iter()
.map(Rc::new)
.collect::<Vec<Rc<PullRequest>>>();
let tree = graph::build(&prs);
match command {
@ -59,15 +63,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
let table = markdown::build_table(tree, pattern);
let output = match prelude {
Some(prelude) => build_final_output(prelude, &table),
None => table
Some(prelude) => build_final_output(prelude, &table),
None => table,
};
for pr in prs.iter() {
println!("{}: {}", pr.number(), pr.title());
}
let response = read_cli_input("Going to update these PRs ☝️ (y/n): ");
match &response[..] {
"y" => persist::persist(&prs, &output, &credentials).await?,
@ -88,12 +91,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
for (pr, maybe_parent) in log {
match maybe_parent {
Some(parent) => println!("{}{}", pr.head(), parent.head()),
None => println!("{} → N/A", pr.head())
None => println!("{} → N/A", pr.head()),
}
}
}
_ => { panic!("Invalid command!") }
_ => panic!("Invalid command!"),
};
Ok(())

View File

@ -32,7 +32,7 @@ pub fn build_table(graph: Graph<Rc<PullRequest>, usize>, title: &str) -> String
"|#{}|{}|#{}|\n",
node.number(),
node.title(),
graph[parent.source().clone()].number()
graph[parent.source()].number()
),
None => format!("|#{}|{}|**N/A**|\n", node.number(), node.title()),
};

View File

@ -29,7 +29,7 @@ fn safe_replace(body: &str, table: &str) -> String {
}
pub async fn persist(
prs: &Vec<Rc<PullRequest>>,
prs: &[Rc<PullRequest>],
table: &str,
c: &Credentials,
) -> Result<(), Box<dyn Error>> {