-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(WIP) Less GitHub dependence #111
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
use color_eyre::eyre::{eyre, WrapErr}; | ||
use std::{collections::HashSet, path::Path}; | ||
use std::path::Path; | ||
|
||
use crate::{ | ||
github::graphql::{GithubGraphqlDataResult, MAX_LABEL_LENGTH, MAX_NUM_TOTAL_LABELS}, | ||
Visibility, | ||
}; | ||
use crate::Visibility; | ||
|
||
const README_FILENAME_LOWERCASE: &str = "readme.md"; | ||
|
||
|
@@ -90,92 +87,63 @@ impl ReleaseMetadata { | |
subdir = %subdir.display(), | ||
description = tracing::field::Empty, | ||
readme_path = tracing::field::Empty, | ||
revision = tracing::field::Empty, | ||
revision_count = tracing::field::Empty, | ||
commit_count = tracing::field::Empty, | ||
%revision, | ||
%commit_count, | ||
spdx_identifier = tracing::field::Empty, | ||
visibility = ?visibility, | ||
%project_id, | ||
%owner_id | ||
))] | ||
pub(crate) async fn build( | ||
flake_store_path: &Path, | ||
subdir: &Path, | ||
revision_info: RevisionInfo, | ||
revision: String, | ||
commit_count: i64, | ||
flake_metadata: serde_json::Value, | ||
flake_outputs: serde_json::Value, | ||
upload_name: String, | ||
mirror: bool, | ||
visibility: Visibility, | ||
github_graphql_data_result: GithubGraphqlDataResult, | ||
extra_labels: Vec<String>, | ||
spdx_expression: Option<spdx::Expression>, | ||
labels: Vec<String>, | ||
spdx_identifier: Option<spdx::Expression>, | ||
project_id: i64, | ||
owner_id: i64, | ||
) -> color_eyre::Result<ReleaseMetadata> { | ||
let span = tracing::Span::current(); | ||
|
||
span.record("revision_string", &revision_info.revision); | ||
if let Some(spdx_identifier) = &spdx_identifier { | ||
span.record("spdx_identifier", tracing::field::display(spdx_identifier)); | ||
} | ||
|
||
assert!(subdir.is_relative()); | ||
|
||
let revision_count = match revision_info.local_revision_count { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code was effectively dead, we'd not actually use |
||
Some(n) => n as i64, | ||
None => { | ||
tracing::debug!( | ||
"Getting revision count locally failed, using data from github instead" | ||
); | ||
github_graphql_data_result.rev_count | ||
} | ||
}; | ||
span.record("revision_count", revision_count); | ||
|
||
let description = if let Some(description) = flake_metadata.get("description") { | ||
Some(description | ||
let description_value = description | ||
.as_str() | ||
.ok_or_else(|| { | ||
eyre!("`nix flake metadata --json` does not have a string `description` field") | ||
})? | ||
.to_string()) | ||
.to_string(); | ||
span.record("description", tracing::field::display(&description_value)); | ||
Some(description_value) | ||
} else { | ||
None | ||
}; | ||
|
||
let readme = get_readme(flake_store_path).await?; | ||
|
||
let spdx_identifier = if spdx_expression.is_some() { | ||
spdx_expression | ||
} else if let Some(spdx_string) = github_graphql_data_result.spdx_identifier { | ||
let parsed = spdx::Expression::parse(&spdx_string) | ||
.wrap_err("Invalid SPDX license identifier reported from the GitHub API, either you are using a non-standard license or GitHub has returned a value that cannot be validated")?; | ||
span.record("spdx_identifier", tracing::field::display(&parsed)); | ||
Some(parsed) | ||
} else { | ||
None | ||
}; | ||
let readme_path = get_readme(flake_store_path).await?; | ||
if let Some(readme_path) = &readme_path { | ||
span.record("readme_path", tracing::field::display(readme_path)); | ||
} | ||
|
||
tracing::trace!("Collected ReleaseMetadata information"); | ||
|
||
// Here we merge explicitly user-supplied labels and the labels ("topics") | ||
// associated with the repo. Duplicates are excluded and all | ||
// are converted to lower case. | ||
let labels: Vec<String> = extra_labels | ||
.into_iter() | ||
.chain(github_graphql_data_result.topics.into_iter()) | ||
.collect::<HashSet<String>>() | ||
.into_iter() | ||
.take(MAX_NUM_TOTAL_LABELS) | ||
.map(|s| s.trim().to_lowercase()) | ||
.filter(|t: &String| { | ||
!t.is_empty() | ||
&& t.len() <= MAX_LABEL_LENGTH | ||
&& t.chars().all(|c| c.is_alphanumeric() || c == '-') | ||
}) | ||
.collect(); | ||
|
||
Ok(ReleaseMetadata { | ||
description, | ||
repo: upload_name.to_string(), | ||
raw_flake_metadata: flake_metadata.clone(), | ||
readme, | ||
revision: revision_info.revision, | ||
commit_count: github_graphql_data_result.rev_count, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notice how this matches with the apparent logic change above. |
||
readme: readme_path, | ||
revision, | ||
commit_count, | ||
visibility, | ||
outputs: flake_outputs, | ||
source_subdirectory: Some( | ||
|
@@ -186,8 +154,8 @@ impl ReleaseMetadata { | |
), | ||
mirrored: mirror, | ||
spdx_identifier, | ||
project_id: github_graphql_data_result.project_id, | ||
owner_id: github_graphql_data_result.owner_id, | ||
project_id, | ||
owner_id, | ||
labels, | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.