Skip to content

Commit 01cb573

Browse files
rxgrantparasyte
andauthored
feat(vet): add cargo vet and remove time crate (#395)
Add `cargo vet`, and remove `time`, which `cargo deny` identified as vulnerable under [RUSTSEC-2026-0009](/rustsec/advisory-db/blob/main/crates/time/RUSTSEC-2026-0009.md). It also had maintenance issues, and has way too many unsafe blocks. In order to fully excise `time`, we replaced `bat` and `octocrab`, which necessitated the creation of `jp_github`. Cargo binstall was also rebuilding itself every run, without proper caching ("Cache save failed."), so it was removed. --------- Co-authored-by: Jay Oster <jay@blipjoy.com>
1 parent 76444fa commit 01cb573

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+8055
-982
lines changed

.config/jp/tools/Cargo.toml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,7 @@ grep-regex = { workspace = true }
2828
grep-searcher = { workspace = true }
2929
ignore = { workspace = true }
3030
indoc = { workspace = true }
31-
octocrab = { workspace = true, features = [
32-
"default-client",
33-
"follow-redirect",
34-
"retry",
35-
"rustls",
36-
"rustls-ring",
37-
"timeout",
38-
] }
31+
jp_github = { workspace = true }
3932
quick-xml = { workspace = true, features = ["encoding", "serialize"] }
4033
reqwest = { workspace = true, features = [
4134
"charset",
@@ -48,7 +41,7 @@ serde = { workspace = true, features = ["std", "derive", "alloc"] }
4841
serde_json = { workspace = true, features = ["std", "preserve_order", "alloc"] }
4942
similar = { workspace = true, features = ["text", "unicode", "inline"] }
5043
strip-ansi-escapes = { workspace = true }
51-
time = { workspace = true, features = ["serde-human-readable"] }
44+
chrono = { workspace = true }
5245
tokio = { workspace = true, features = ["full"] }
5346
url = { workspace = true, features = ["serde", "std"] }
5447

.config/jp/tools/src/github.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ async fn auth() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>
8282
"unable to get auth token. Set `JP_GITHUB_TOKEN` or `GITHUB_TOKEN` to a valid token."
8383
})?;
8484

85-
let octocrab = octocrab::Octocrab::builder()
85+
let octocrab = jp_github::Octocrab::builder()
8686
.personal_token(token)
8787
.build()
8888
.map_err(|err| format!("unable to create github client: {err:#}"))?;
8989

90-
octocrab::initialise(octocrab);
90+
jp_github::initialise(octocrab);
9191

92-
if octocrab::instance().current().user().await.is_err() {
92+
if jp_github::instance().current().user().await.is_err() {
9393
return Err(
9494
"Unable to authenticate with github. This might be because the token is expired. \
9595
Either set `JP_GITHUB_TOKEN` or `GITHUB_TOKEN` to a valid token."
@@ -100,9 +100,9 @@ async fn auth() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>
100100
Ok(())
101101
}
102102

103-
fn handle_404(error: octocrab::Error, msg: impl Into<String>) -> Error {
103+
fn handle_404(error: jp_github::Error, msg: impl Into<String>) -> Error {
104104
match error {
105-
octocrab::Error::GitHub { source, .. } if source.status_code.as_u16() == 404 => {
105+
jp_github::Error::GitHub { source, .. } if source.status_code.as_u16() == 404 => {
106106
msg.into().into()
107107
}
108108
_ => Box::new(error) as Error,

.config/jp/tools/src/github/create_issue_bug.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::{
99
util::OneOrMany,
1010
};
1111

12+
#[allow(clippy::too_many_arguments)]
1213
pub(crate) async fn github_create_issue_bug(
1314
title: String,
1415
description: String,
@@ -94,7 +95,7 @@ pub(crate) async fn github_create_issue_bug(
9495
_ => return Err("Invalid complexity, must be one of `low`, `medium`, or `high`.".into()),
9596
}
9697

97-
let issue = octocrab::instance()
98+
let issue = jp_github::instance()
9899
.issues(ORG, REPO)
99100
.create(&title)
100101
.body(&body)
@@ -109,13 +110,13 @@ pub(crate) async fn github_create_issue_bug(
109110
}
110111

111112
async fn check_labels(as_ref: Option<&[String]>) -> Result<()> {
112-
let page = octocrab::instance()
113+
let page = jp_github::instance()
113114
.issues(ORG, REPO)
114115
.list_labels_for_repo()
115116
.send()
116117
.await?;
117118

118-
let labels = octocrab::instance().all_pages(page).await?;
119+
let labels = jp_github::instance().all_pages(page).await?;
119120

120121
let mut invalid_labels = vec![];
121122
for label in as_ref.into_iter().flatten() {
@@ -161,13 +162,13 @@ async fn check_labels(as_ref: Option<&[String]>) -> Result<()> {
161162
}
162163

163164
async fn check_assignees(assignees: Option<&[String]>) -> Result<()> {
164-
let page = octocrab::instance()
165+
let page = jp_github::instance()
165166
.repos(ORG, REPO)
166167
.list_collaborators()
167168
.send()
168169
.await?;
169170

170-
let collaborators = octocrab::instance().all_pages(page).await?;
171+
let collaborators = jp_github::instance().all_pages(page).await?;
171172

172173
let mut invalid_assignees = vec![];
173174
for assignee in assignees.into_iter().flatten() {

.config/jp/tools/src/github/create_issue_enhancement.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub(crate) async fn github_create_issue_enhancement(
8989
_ => return Err("Invalid complexity, must be one of `low`, `medium`, or `high`.".into()),
9090
}
9191

92-
let issue = octocrab::instance()
92+
let issue = jp_github::instance()
9393
.issues(ORG, REPO)
9494
.create(&title)
9595
.body(&body)
@@ -104,13 +104,13 @@ pub(crate) async fn github_create_issue_enhancement(
104104
}
105105

106106
async fn check_labels(as_ref: Option<&[String]>) -> Result<()> {
107-
let page = octocrab::instance()
107+
let page = jp_github::instance()
108108
.issues(ORG, REPO)
109109
.list_labels_for_repo()
110110
.send()
111111
.await?;
112112

113-
let labels = octocrab::instance().all_pages(page).await?;
113+
let labels = jp_github::instance().all_pages(page).await?;
114114

115115
let mut invalid_labels = vec![];
116116
for label in as_ref.into_iter().flatten() {
@@ -156,13 +156,13 @@ async fn check_labels(as_ref: Option<&[String]>) -> Result<()> {
156156
}
157157

158158
async fn check_assignees(assignees: Option<&[String]>) -> Result<()> {
159-
let page = octocrab::instance()
159+
let page = jp_github::instance()
160160
.repos(ORG, REPO)
161161
.list_collaborators()
162162
.send()
163163
.await?;
164164

165-
let collaborators = octocrab::instance().all_pages(page).await?;
165+
let collaborators = jp_github::instance().all_pages(page).await?;
166166

167167
let mut invalid_assignees = vec![];
168168
for assignee in assignees.into_iter().flatten() {

.config/jp/tools/src/github/issues.rs

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use time::OffsetDateTime;
1+
use chrono::{DateTime, Utc};
22
use url::Url;
33

44
use super::auth;
@@ -26,14 +26,12 @@ async fn get_issue(number: u64) -> Result<String> {
2626
url: Url,
2727
labels: Vec<String>,
2828
author: String,
29-
#[serde(with = "time::serde::rfc3339")]
30-
created_at: OffsetDateTime,
31-
#[serde(with = "time::serde::rfc3339::option")]
32-
closed_at: Option<OffsetDateTime>,
29+
created_at: DateTime<Utc>,
30+
closed_at: Option<DateTime<Utc>>,
3331
linked_pull_request: Option<Url>,
3432
}
3533

36-
let issue = octocrab::instance()
34+
let issue = jp_github::instance()
3735
.issues(ORG, REPO)
3836
.get(number)
3937
.await
@@ -46,11 +44,8 @@ async fn get_issue(number: u64) -> Result<String> {
4644
url: issue.html_url,
4745
labels: issue.labels.into_iter().map(|label| label.name).collect(),
4846
author: issue.user.login,
49-
created_at: OffsetDateTime::from_unix_timestamp(issue.created_at.timestamp())?,
50-
closed_at: issue
51-
.closed_at
52-
.map(|t| OffsetDateTime::from_unix_timestamp(t.timestamp()))
53-
.transpose()?,
47+
created_at: issue.created_at,
48+
closed_at: issue.closed_at,
5449
linked_pull_request: issue.pull_request.map(|pr| pr.html_url),
5550
})
5651
}
@@ -68,40 +63,33 @@ async fn get_issues() -> Result<String> {
6863
url: Url,
6964
labels: Vec<String>,
7065
author: String,
71-
#[serde(with = "time::serde::rfc3339")]
72-
created_at: OffsetDateTime,
73-
#[serde(with = "time::serde::rfc3339::option")]
74-
closed_at: Option<OffsetDateTime>,
66+
created_at: DateTime<Utc>,
67+
closed_at: Option<DateTime<Utc>>,
7568
linked_pull_request: Option<Url>,
7669
}
7770

78-
let page = octocrab::instance()
71+
let page = jp_github::instance()
7972
.issues(ORG, REPO)
8073
.list()
8174
.per_page(100)
8275
.send()
8376
.await?;
8477

85-
let issue = octocrab::instance()
78+
let issue = jp_github::instance()
8679
.all_pages(page)
8780
.await?
8881
.into_iter()
89-
.map(|issue| {
90-
Ok(Issue {
91-
number: issue.number,
92-
title: issue.title,
93-
url: issue.html_url,
94-
labels: issue.labels.into_iter().map(|label| label.name).collect(),
95-
author: issue.user.login,
96-
created_at: OffsetDateTime::from_unix_timestamp(issue.created_at.timestamp())?,
97-
closed_at: issue
98-
.closed_at
99-
.map(|t| OffsetDateTime::from_unix_timestamp(t.timestamp()))
100-
.transpose()?,
101-
linked_pull_request: issue.pull_request.map(|pr| pr.html_url),
102-
})
82+
.map(|issue| Issue {
83+
number: issue.number,
84+
title: issue.title,
85+
url: issue.html_url,
86+
labels: issue.labels.into_iter().map(|label| label.name).collect(),
87+
author: issue.user.login,
88+
created_at: issue.created_at,
89+
closed_at: issue.closed_at,
90+
linked_pull_request: issue.pull_request.map(|pr| pr.html_url),
10391
})
104-
.collect::<Result<_>>()?;
92+
.collect();
10593

10694
to_xml(Issues { issue })
10795
}

0 commit comments

Comments
 (0)