Skip to content

Commit 843b96e

Browse files
Atul9spastorino
authored andcommitted
Format code using 'cargo fmt'
1 parent c84ef54 commit 843b96e

File tree

5 files changed

+273
-146
lines changed

5 files changed

+273
-146
lines changed

src/git.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ fn get_repo() -> Result<Repository, Error> {
4747
let repo = Repository::open(path)?;
4848
{
4949
eprintln!("refreshing repository");
50-
let mut remote = repo.find_remote("origin")
50+
let mut remote = repo
51+
.find_remote("origin")
5152
.or_else(|_| repo.remote_anonymous("origin"))?;
5253
remote.fetch(&["master"], None, None)?;
5354
}

src/github.rs

Lines changed: 75 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,22 @@ use serde::{Deserialize, Serialize};
55
use crate::Commit;
66

77
#[derive(Serialize, Deserialize, Debug)]
8-
struct GithubCommitElem { commit: GithubCommit, sha: String }
8+
struct GithubCommitElem {
9+
commit: GithubCommit,
10+
sha: String,
11+
}
912
#[derive(Serialize, Deserialize, Debug)]
10-
struct GithubCommit { author: GithubAuthor, committer: GithubAuthor, message: String, }
13+
struct GithubCommit {
14+
author: GithubAuthor,
15+
committer: GithubAuthor,
16+
message: String,
17+
}
1118
#[derive(Serialize, Deserialize, Debug)]
12-
struct GithubAuthor { date: String, email: String, name: String }
19+
struct GithubAuthor {
20+
date: String,
21+
email: String,
22+
name: String,
23+
}
1324

1425
type GitDate = chrono::DateTime<chrono::Utc>;
1526

@@ -43,9 +54,7 @@ fn headers() -> Result<reqwest::header::HeaderMap, Error> {
4354

4455
pub(crate) fn get_commit(sha: &str) -> Result<Commit, Error> {
4556
let url = SingleCommitUrl { sha }.url();
46-
let client = Client::builder()
47-
.default_headers(headers()?)
48-
.build()?;
57+
let client = Client::builder().default_headers(headers()?).build()?;
4958
let response: Response = client.get(&url).send()?;
5059
let elem: GithubCommitElem = response.json()?;
5160
elem.git_commit()
@@ -71,26 +80,44 @@ const PER_PAGE: usize = 100;
7180
const OWNER: &'static str = "rust-lang";
7281
const REPO: &'static str = "rust";
7382

74-
75-
trait ToUrl { fn url(&self) -> String; }
76-
struct CommitsUrl<'a> { page: usize, author: &'a str, since: &'a str, sha: &'a str }
77-
struct SingleCommitUrl<'a> { sha: &'a str }
83+
trait ToUrl {
84+
fn url(&self) -> String;
85+
}
86+
struct CommitsUrl<'a> {
87+
page: usize,
88+
author: &'a str,
89+
since: &'a str,
90+
sha: &'a str,
91+
}
92+
struct SingleCommitUrl<'a> {
93+
sha: &'a str,
94+
}
7895

7996
impl<'a> ToUrl for CommitsUrl<'a> {
8097
fn url(&self) -> String {
81-
format!("https://api.github.com/repos/{OWNER}/{REPO}/commits\
98+
format!(
99+
"https://api.github.com/repos/{OWNER}/{REPO}/commits\
82100
?page={PAGE}&per_page={PER_PAGE}\
83101
&author={AUTHOR}&since={SINCE}&sha={SHA}",
84-
OWNER=OWNER, REPO=REPO,
85-
PAGE=self.page, PER_PAGE=PER_PAGE,
86-
AUTHOR=self.author, SINCE=self.since, SHA=self.sha)
102+
OWNER = OWNER,
103+
REPO = REPO,
104+
PAGE = self.page,
105+
PER_PAGE = PER_PAGE,
106+
AUTHOR = self.author,
107+
SINCE = self.since,
108+
SHA = self.sha
109+
)
87110
}
88111
}
89112

90113
impl<'a> ToUrl for SingleCommitUrl<'a> {
91114
fn url(&self) -> String {
92-
format!("https://api.github.com/repos/{OWNER}/{REPO}/commits/{REF}",
93-
OWNER=OWNER, REPO=REPO, REF=self.sha)
115+
format!(
116+
"https://api.github.com/repos/{OWNER}/{REPO}/commits/{REF}",
117+
OWNER = OWNER,
118+
REPO = REPO,
119+
REF = self.sha
120+
)
94121
}
95122
}
96123

@@ -102,11 +129,15 @@ fn get_commits(q: CommitsQuery) -> Result<Vec<Commit>, Error> {
102129
// focus on Pull Request merges, all authored and committed by bors.
103130
let author = "bors";
104131

105-
let client = Client::builder()
106-
.default_headers(headers()?)
107-
.build()?;
132+
let client = Client::builder().default_headers(headers()?).build()?;
108133
for page in 1.. {
109-
let url = CommitsUrl { page, author, since: q.since_date, sha: q.most_recent_sha }.url();
134+
let url = CommitsUrl {
135+
page,
136+
author,
137+
since: q.since_date,
138+
sha: q.most_recent_sha,
139+
}
140+
.url();
110141

111142
let response: Response = client.get(&url).send()?;
112143

@@ -121,35 +152,49 @@ fn get_commits(q: CommitsQuery) -> Result<Vec<Commit>, Error> {
121152
commits.push(commit);
122153

123154
if elem.sha == q.earliest_sha {
124-
eprintln!("ending github query because we found starting sha: {}", elem.sha);
155+
eprintln!(
156+
"ending github query because we found starting sha: {}",
157+
elem.sha
158+
);
125159
return Loop::Break;
126160
}
127161

128162
Loop::Next
129163
})?;
130164

131-
if let Loop::Break = action { break; }
165+
if let Loop::Break = action {
166+
break;
167+
}
132168
}
133169

134-
eprintln!("get_commits_between returning commits, len: {}", commits.len());
170+
eprintln!(
171+
"get_commits_between returning commits, len: {}",
172+
commits.len()
173+
);
135174

136175
// reverse to obtain chronological order
137176
commits.reverse();
138177
Ok(commits)
139178
}
140179

141-
enum Loop<E> { Break, Next, Err(E) }
142-
enum Void { }
180+
enum Loop<E> {
181+
Break,
182+
Next,
183+
Err(E),
184+
}
185+
enum Void {}
143186

144-
fn parse_paged_elems<Elem: for<'a> serde::Deserialize<'a>>(response: Response,
145-
mut k: impl FnMut(Elem) -> Loop<Error>)
146-
-> Result<Loop<Void>, Error>
147-
{
187+
fn parse_paged_elems<Elem: for<'a> serde::Deserialize<'a>>(
188+
response: Response,
189+
mut k: impl FnMut(Elem) -> Loop<Error>,
190+
) -> Result<Loop<Void>, Error> {
148191
// parse the JSON into an array of the expected Elem type
149192
let elems: Vec<Elem> = response.json()?;
150193

151194
// if `elems` is empty, then we've run out of useful pages to lookup.
152-
if elems.len() == 0 { return Ok(Loop::Break); }
195+
if elems.len() == 0 {
196+
return Ok(Loop::Break);
197+
}
153198

154199
for elem in elems.into_iter() {
155200
let act = k(elem);

src/least_satisfying.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ mod tests {
101101
#[test]
102102
fn least_satisfying_1() {
103103
assert_eq!(
104-
least_satisfying(&[No, Unknown, Unknown, No, Yes],|i| *i),
104+
least_satisfying(&[No, Unknown, Unknown, No, Yes], |i| *i),
105105
4
106106
);
107107
}
@@ -145,7 +145,7 @@ mod tests {
145145
#[test]
146146
fn least_satisfying_8() {
147147
assert_eq!(
148-
least_satisfying(&[No, Unknown, No, No, Unknown, Yes, Yes],|i| *i),
148+
least_satisfying(&[No, Unknown, No, No, Unknown, Yes, Yes], |i| *i),
149149
5
150150
);
151151
}

0 commit comments

Comments
 (0)