Skip to content

Commit

Permalink
topic-manifest: add draft status
Browse files Browse the repository at this point in the history
  • Loading branch information
eatradish committed Nov 8, 2024
1 parent dca8c71 commit 41d1260
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 7 additions & 3 deletions topic-manifest/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct GitHubPullRequest {
number: u64,

Check warning on line 16 in topic-manifest/src/network.rs

View workflow job for this annotation

GitHub Actions / build

field `number` is never read

Check warning on line 16 in topic-manifest/src/network.rs

View workflow job for this annotation

GitHub Actions / build

field `number` is never read

Check warning on line 16 in topic-manifest/src/network.rs

View workflow job for this annotation

GitHub Actions / build

field `number` is never read

Check warning on line 16 in topic-manifest/src/network.rs

View workflow job for this annotation

GitHub Actions / build

field `number` is never read
title: String,
head: GitHubBranch,
draft: bool,
}

fn fetch_description(request: RequestBuilder, page: usize) -> Result<Vec<GitHubPullRequest>> {
Expand Down Expand Up @@ -51,17 +52,20 @@ fn create_request(repo: &str) -> Result<RequestBuilder> {
Ok(request)
}

pub fn fetch_descriptions(repo: &str) -> Result<HashMap<String, String>> {
pub fn fetch_descriptions(repo: &str) -> Result<HashMap<String, (String, bool)>> {
let repo_name = repo.split('/').next();
repo_name.ok_or_else(|| anyhow!("Invalid repo name: {}", repo))?;
let mut results: HashMap<String, String> = HashMap::new();
let mut results = HashMap::new();
let mut page = 1usize;
loop {
let request = create_request(repo)?;
let this_page = fetch_description(request, page)?;
let no_next_page = this_page.len() < 100;
for entry in this_page {
results.insert(entry.head.name, entry.title.trim().to_string());
results.insert(
entry.head.name,
(entry.title.trim().to_string(), entry.draft),
);
}
if no_next_page {
break;
Expand Down
6 changes: 5 additions & 1 deletion topic-manifest/src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct TopicManifest {
update_date: u64,
arch: Vec<String>,
packages: Vec<String>,
draft: bool,
}

#[inline]
Expand Down Expand Up @@ -89,6 +90,8 @@ fn scan_topic(topic_path: DirEntry) -> Result<TopicManifest> {
update_date: updated,
arch: all_arch,
packages: all_names.into_iter().collect::<Vec<String>>(),
// Set topic status as true by default
draft: true,
})
}

Expand All @@ -115,8 +118,9 @@ pub fn collect_topics(repo: &str, path: &Path) -> Result<Vec<TopicManifest>> {
continue;
}
let mut manifest = manifest.unwrap();
if let Some(desc) = descriptions.get(&manifest.name) {
if let Some((desc, draft)) = descriptions.get(&manifest.name) {
manifest.description = Some(desc.clone());
manifest.draft = *draft;
} else {
warn!("{}: No description available.", manifest.name);
}
Expand Down

0 comments on commit 41d1260

Please sign in to comment.