Skip to content

Commit a04f2d6

Browse files
authored
Merge pull request #139 from nikomatsakis/progress-bars
Progress bars
2 parents 9ceef1e + fba3e53 commit a04f2d6

File tree

16 files changed

+442
-88
lines changed

16 files changed

+442
-88
lines changed

.github/workflows/check.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ jobs:
1616

1717
steps:
1818
- uses: actions/checkout@v4
19-
- name: Build
20-
run: cargo build --verbose
21-
- name: Check for consistency
22-
run: cargo run -- check
19+
- uses: extractions/setup-just@v2
20+
- name: Build and check
21+
run: just check

.github/workflows/mdbook.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@ jobs:
4141
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf -y | sh
4242
rustup update
4343
cargo install --version ${MDBOOK_VERSION} mdbook
44+
- uses: extractions/setup-just@v2
4445
- name: Setup Pages
4546
id: pages
4647
uses: actions/configure-pages@v5
47-
- name: Build with mdBook
48-
run: mdbook build
49-
- name: Generate JSON data
50-
run: cargo run -- json 2024h2 --json-path book/html/api/2024h2.json
48+
- name: Build
49+
run: just build
5150
env:
5251
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5352
- name: Upload artifact

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
book
22
target
33
.cache
4+
src/api

book.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ command = "cargo run -p mdbook-goals --"
2727
git-repository-url = "https://github.com/rust-lang/rust-project-goals"
2828
edit-url-template = "https://github.com/rust-lang/rust-project-goals/edit/main/{path}"
2929
site-url = "/rust-project-goals/"
30+
additional-js = ["src/update-progress-bars.js"]
3031

3132
[output.html.fold]
3233
enable = true

justfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
api:
2+
cargo run -- json 2024h2 --json-path src/api/2024h2.json
3+
4+
serve: api
5+
mdbook serve
6+
7+
build: api
8+
mdbook build
9+
10+
check:
11+
cargo build
12+
cargo run -- check
13+

mdbook-goals/src/gh/issue_id.rs

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,62 @@
1-
use crate::re::TRACKING_ISSUE;
1+
use crate::re::{REPOSITORY, TRACKING_ISSUE};
22
use std::fmt::Display;
33

4+
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Debug)]
5+
pub struct Repository {
6+
/// Something like `rust-lang`
7+
pub org: String,
8+
9+
/// Something like `rust-project-goals`
10+
pub repo: String,
11+
}
12+
13+
impl Repository {
14+
pub fn new(org: &(impl Display + ?Sized), repo: &(impl Display + ?Sized)) -> Self {
15+
Self {
16+
org: org.to_string(),
17+
repo: repo.to_string(),
18+
}
19+
}
20+
}
21+
22+
impl std::fmt::Display for Repository {
23+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24+
let Repository { org, repo } = self;
25+
write!(f, "{org}/{repo}")
26+
}
27+
}
28+
29+
impl std::str::FromStr for Repository {
30+
type Err = anyhow::Error;
31+
32+
fn from_str(s: &str) -> Result<Self, Self::Err> {
33+
let Some(c) = REPOSITORY.captures(s) else {
34+
anyhow::bail!("invalid repository `{s}`")
35+
};
36+
37+
Ok(Repository::new(&c[1], &c[2]))
38+
}
39+
}
40+
441
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone)]
542
pub struct IssueId {
6-
/// Something like `rust-lang/rust-project-goals`
7-
pub repository: String,
43+
pub repository: Repository,
844

945
/// Something like `22`
1046
pub number: u64,
1147
}
1248

1349
impl IssueId {
14-
pub fn new(repository: &(impl Display + ?Sized), number: u64) -> Self {
15-
Self {
16-
repository: repository.to_string(),
50+
pub fn new(repository: Repository, number: u64) -> Self {
51+
Self { repository, number }
52+
}
53+
54+
pub fn url(&self) -> String {
55+
let IssueId {
56+
repository: Repository { org, repo },
1757
number,
18-
}
58+
} = self;
59+
format!("https://github.com/{org}/{repo}/issues/{number}")
1960
}
2061
}
2162

@@ -27,12 +68,11 @@ impl std::fmt::Debug for IssueId {
2768

2869
impl std::fmt::Display for IssueId {
2970
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30-
write!(
31-
f,
32-
"[{repository}#{number}]",
33-
repository = self.repository,
34-
number = self.number,
35-
)
71+
let IssueId {
72+
repository: Repository { org, repo },
73+
number,
74+
} = self;
75+
write!(f, "[{org}/{repo}#{number}]")
3676
}
3777
}
3878

@@ -44,6 +84,6 @@ impl std::str::FromStr for IssueId {
4484
anyhow::bail!("invalid issue-id")
4585
};
4686

47-
Ok(IssueId::new(&c[1], c[2].parse()?))
87+
Ok(IssueId::new(Repository::new(&c[1], &c[2]), c[3].parse()?))
4888
}
4989
}

mdbook-goals/src/gh/issues.rs

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
88

99
use crate::util::comma;
1010

11-
use super::labels::GhLabel;
11+
use super::{issue_id::Repository, labels::GhLabel};
1212

1313
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
1414
pub struct ExistingGithubIssue {
@@ -77,13 +77,54 @@ impl std::fmt::Display for ExistingIssueState {
7777
}
7878
}
7979

80+
pub struct CountIssues {
81+
pub open: u32,
82+
pub closed: u32,
83+
}
84+
85+
pub fn count_issues_matching_search(
86+
repository: &Repository,
87+
search: &str,
88+
) -> anyhow::Result<CountIssues> {
89+
#[derive(Deserialize)]
90+
struct JustState {
91+
state: ExistingIssueState,
92+
}
93+
94+
let output = Command::new("gh")
95+
.arg("-R")
96+
.arg(&repository.to_string())
97+
.arg("issue")
98+
.arg("list")
99+
.arg("-S")
100+
.arg(search)
101+
.arg("-s")
102+
.arg("all")
103+
.arg("--json")
104+
.arg("state")
105+
.output()?;
106+
107+
let existing_issues: Vec<JustState> = serde_json::from_slice(&output.stdout)?;
108+
109+
let mut count_issues = CountIssues { open: 0, closed: 0 };
110+
111+
for issue in &existing_issues {
112+
match issue.state {
113+
ExistingIssueState::Open => count_issues.open += 1,
114+
ExistingIssueState::Closed => count_issues.closed += 1,
115+
}
116+
}
117+
118+
Ok(count_issues)
119+
}
120+
80121
pub fn list_issue_titles_in_milestone(
81-
repository: &str,
122+
repository: &Repository,
82123
timeframe: &str,
83124
) -> anyhow::Result<BTreeMap<String, ExistingGithubIssue>> {
84125
let output = Command::new("gh")
85126
.arg("-R")
86-
.arg(repository)
127+
.arg(&repository.to_string())
87128
.arg("issue")
88129
.arg("list")
89130
.arg("-m")
@@ -124,7 +165,7 @@ pub fn list_issue_titles_in_milestone(
124165
}
125166

126167
pub fn create_issue(
127-
repository: &str,
168+
repository: &Repository,
128169
body: &str,
129170
title: &str,
130171
labels: &[String],
@@ -133,7 +174,7 @@ pub fn create_issue(
133174
) -> anyhow::Result<()> {
134175
let output = Command::new("gh")
135176
.arg("-R")
136-
.arg(&repository)
177+
.arg(&repository.to_string())
137178
.arg("issue")
138179
.arg("create")
139180
.arg("-b")
@@ -160,15 +201,15 @@ pub fn create_issue(
160201
}
161202

162203
pub fn sync_assignees(
163-
repository: &str,
204+
repository: &Repository,
164205
number: u64,
165206
remove_owners: &BTreeSet<String>,
166207
add_owners: &BTreeSet<String>,
167208
) -> anyhow::Result<()> {
168209
let mut command = Command::new("gh");
169210
command
170211
.arg("-R")
171-
.arg(&repository)
212+
.arg(&repository.to_string())
172213
.arg("issue")
173214
.arg("edit")
174215
.arg(number.to_string());
@@ -203,10 +244,10 @@ impl ExistingGithubIssue {
203244
}
204245
}
205246

206-
pub fn lock_issue(repository: &str, number: u64) -> anyhow::Result<()> {
247+
pub fn lock_issue(repository: &Repository, number: u64) -> anyhow::Result<()> {
207248
let output = Command::new("gh")
208249
.arg("-R")
209-
.arg(repository)
250+
.arg(&repository.to_string())
210251
.arg("issue")
211252
.arg("lock")
212253
.arg(number.to_string())
@@ -225,7 +266,7 @@ pub fn lock_issue(repository: &str, number: u64) -> anyhow::Result<()> {
225266
// Leave a comment explaining what is going on.
226267
let output = Command::new("gh")
227268
.arg("-R")
228-
.arg(repository)
269+
.arg(&repository.to_string())
229270
.arg("issue")
230271
.arg("comment")
231272
.arg(number.to_string())

mdbook-goals/src/gh/labels.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ use std::process::Command;
22

33
use serde::{Deserialize, Serialize};
44

5+
use super::issue_id::Repository;
6+
57
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
68
pub struct GhLabel {
79
pub name: String,
810
pub color: String,
911
}
1012

1113
impl GhLabel {
12-
pub fn list(repository: &str) -> anyhow::Result<Vec<GhLabel>> {
14+
pub fn list(repository: &Repository) -> anyhow::Result<Vec<GhLabel>> {
1315
let output = Command::new("gh")
1416
.arg("-R")
15-
.arg(repository)
17+
.arg(&repository.to_string())
1618
.arg("label")
1719
.arg("list")
1820
.arg("--json")
@@ -24,10 +26,10 @@ impl GhLabel {
2426
Ok(labels)
2527
}
2628

27-
pub fn create(&self, repository: &str) -> anyhow::Result<()> {
29+
pub fn create(&self, repository: &Repository) -> anyhow::Result<()> {
2830
let output = Command::new("gh")
2931
.arg("-R")
30-
.arg(repository)
32+
.arg(&repository.to_string())
3133
.arg("label")
3234
.arg("create")
3335
.arg(&self.name)

0 commit comments

Comments
 (0)