Skip to content
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

refactor: code cleanup #2

Merged
merged 22 commits into from
Mar 5, 2025
Merged

refactor: code cleanup #2

merged 22 commits into from
Mar 5, 2025

Conversation

DavSanchez
Copy link
Contributor

@DavSanchez DavSanchez commented Feb 27, 2025

PR performs several things:

  • Most importantly, it rewrites the code. Moves the logic to modules and operates on custom types instead of serde_json::Value allowing us to pre-process the data and control the values sent to the template.
  • The template for this repo's own THIRD_PARTY_NOTICES.md now performs less operations (some were delegated to the code) and results on cleaner markdown output.
  • Modifies the action code so the check made with git is more robust.
  • The repo now performs its own third party notices check with its own action.
  • Removes unneeded files such as the Makefile and old template directories.

@DavSanchez DavSanchez requested a review from a team as a code owner February 27, 2025 18:45
@DavSanchez DavSanchez requested review from a team and removed request for a team February 27, 2025 18:46
@DavSanchez DavSanchez marked this pull request as draft February 28, 2025 09:47
@DavSanchez DavSanchez force-pushed the refactor/code-cleanup branch 2 times, most recently from b2200b3 to 3359d63 Compare February 28, 2025 21:07
@DavSanchez DavSanchez force-pushed the refactor/review-code branch 2 times, most recently from 95caf40 to d2865a6 Compare February 28, 2025 21:28
@DavSanchez DavSanchez force-pushed the refactor/code-cleanup branch 3 times, most recently from a0f0083 to 0843d92 Compare March 1, 2025 01:08
@DavSanchez DavSanchez marked this pull request as ready for review March 1, 2025 05:08
let key_split = key.split_whitespace().collect::<Vec<_>>();

match key_split[..] {
[crate_name, _crate_version, url] => Ok(NameAndUrl(format!(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This drops the crate version from the input so it's not usable elsewhere in the code. Reduces complexity for the templates, but performs the changes via code logic so it's less flexible. Let me know what you prefer.

Comment on lines +126 to +136
fn process_name_with_url(dep_name: &str, url_str: &str) -> String {
match url_str {
// crates.io
"registry+https://github.com/rust-lang/crates.io-index" => {
format!("https://crates.io/crates/{}", dep_name)
}
// remove any prefix for other registries, up until the + symbol
s if s.starts_with("git+") => remove_source_prefix(s).trim_end_matches(".git").to_string(),
s => remove_source_prefix(s),
}
}
Copy link
Contributor Author

@DavSanchez DavSanchez Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was originally done in the template itself though only for crates.io references (not git repos). It reduces complexity for the templates (as I find them harder to test), but performs the changes via code logic so it's less flexible for other use cases. Let me know what you prefer.

Comment on lines +148 to +152
fn remove_source_prefix(url_str: &str) -> String {
// Is there a registry indicator? We know it's a registry if it has a + symbol at the end.
let sum_symbol_index = url_str.find('+').map(|i| i + 1).unwrap_or(0);
url_str.chars().skip(sum_symbol_index).collect::<String>()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was originally done in the template itself though only for crates.io references (not git repos). It reduces complexity for the templates (as I find them harder to test), but performs the changes via code logic so it's less flexible for other use cases. Let me know what you prefer.

sigilioso
sigilioso previously approved these changes Mar 5, 2025
Copy link
Contributor

@sigilioso sigilioso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines 16 to 19
- uses: newrelic/rust-licenses-noticer@refactor/code-cleanup
with:
template-file: "./THIRD_PARTY_NOTICES.md.tmpl"
rust-licenses-noticer-branch: "refactor/code-cleanup"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Using the refactor/code-cleanup branch is a workaround to make it work from here now, right? We'll need to update it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yupp, as soon as it's merged to main I'll fix all references

@sigilioso sigilioso requested a review from a team March 5, 2025 13:12
@DavSanchez DavSanchez changed the base branch from refactor/review-code to main March 5, 2025 15:53
@DavSanchez DavSanchez dismissed sigilioso’s stale review March 5, 2025 15:53

The base branch was changed.

@DavSanchez DavSanchez force-pushed the refactor/code-cleanup branch from 4e328bf to fc010e8 Compare March 5, 2025 15:56
@DavSanchez DavSanchez merged commit 948bff3 into main Mar 5, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants