-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: add shield badges in README.md #96
base: main
Are you sure you want to change the base?
Conversation
41fcb6f
to
abd287e
Compare
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.
Looking good! Generally, I would split features up into separate stories, even if they're small. These two features aren't related at all to each other so they shouldn't be dependent on each other
src/commands/new/git.rs
Outdated
@@ -0,0 +1,20 @@ | |||
use git2::{Error, Repository, RepositoryInitOptions}; |
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.
this shouldn't be in commands/new/git. otherwise we would expect there to be aqora new git
. Just put it in the src
for now. At some point when things get too messy we'll do a little reorganization. But also this should apply to aqora template
as well as aqora new
src/commands/test.rs
Outdated
@@ -345,6 +366,35 @@ pub async fn run_submission_tests( | |||
"Score".if_supports_color(OwoStream::Stdout, |text| { text.bold() }), | |||
score | |||
)); | |||
let path = global.project.join("README.md"); |
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.
I think you'll have to locate the readme based on the pyproject. see https://docs.rs/pyproject-toml/latest/pyproject_toml/struct.Project.html#structfield.readme
src/commands/test.rs
Outdated
let mut contents = String::new(); | ||
file.read_to_string(&mut contents).await?; | ||
file.seek(SeekFrom::Start(0)).await?; | ||
file.write_all( |
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.
I'm not sure I understand how this would replace an existing badge? I think you'd have to wrap it in some comments or parse the markdown to find the existing badge
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.
No! I want to inject a new badge each time with the latest score the user achieved! So basically, we have two types of badges:
- A default use-case badge, which redirects to the Aqora use case.
- A score badge that displays the user’s score!
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.
Maybe it’s not ideal to keep all badges? I thought they could display either progression or regression, but users can always edit the markdown themselves at the end if they want to remove some of them!
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.
I would say we should only have one badge generated at a time. thoughts @stubbi ?
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.
Oh no, I didn't express myself clearly. There is only one generated badge. However, in the markdown before any test, there is already a badge that refers to Aqora. Then, when you run a test, a new badge with a score is generated, and each test adds a new score badge!
2f3d59d
to
a2ff781
Compare
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.
looking good! just a few things
src/commands/new/use_case.rs
Outdated
pb.finish_with_message(format!( | ||
"Created use case in directory '{}'", | ||
dest.display() | ||
)); | ||
Ok(()) | ||
} | ||
|
||
fn format_permission_error(action: &str, dest: &Path, error: &impl std::fmt::Display) -> Error { |
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.
its kind of strange to create a function for this kind of thing, if you're only going to use it once
Cargo.toml
Outdated
@@ -46,7 +46,7 @@ mime = "0.3" | |||
open = "5.0" | |||
owo-colors = { version = "4.0", features = ["supports-colors"] } | |||
passterm = "2.0" | |||
pyo3 = { version = "0.20", features = ["serde"] } | |||
pyo3 = { version = "0.20", features = ["serde"]} |
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.
haha this is the ultimate nitpick but this really bugs me
src/commands/test.rs
Outdated
let mut contents = String::new(); | ||
file.read_to_string(&mut contents).await?; | ||
let updated_content = regex_replace_all!( | ||
r"(?:<!--- score_badge -->)|(!\[Aqora Score Badge\]\([^\)]+\))", |
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.
this would probably but i think its usually clearer to start and end tags on things, and also to properly format your comments e.g.
<!--\s*aqora:score:start\s*-->.*<!--\s*aqora:score:end\s*-->
src/commands/test.rs
Outdated
@@ -325,6 +387,7 @@ pub async fn run_submission_tests( | |||
}) | |||
.collect::<Result<Vec<_>>>()?; | |||
|
|||
let competition = modified_use_case.clone().competition.unwrap_or_default(); |
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.
nitpick: can you move this either towards the top where we do all of the parsing or closer to where you use it? also i'm not sure if an empty string is the best way to handle None
. I think the badge function would probably decide whether to send them to the aqora
homepage or to the competition
src/commands/test.rs
Outdated
@@ -345,6 +408,14 @@ pub async fn run_submission_tests( | |||
"Score".if_supports_color(OwoStream::Stdout, |text| { text.bold() }), | |||
score | |||
)); | |||
let path = global.project.join(project_readme_path.ok_or_else(|| { |
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.
i don't think the README
should be required. I would just skip the badge function if it doesn't exist
src/commands/test.rs
Outdated
"See : https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#readme", | ||
) | ||
})?); | ||
update_score_badge_in_file(path, &competition, &score, global.aqora_url().unwrap()) |
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.
I would avoid using unwrap
if its not necessary. should be able to just do ?
src/commands/test.rs
Outdated
.and_then(|readme| match readme { | ||
aqora_config::ReadMe::RelativePath(path) => Some(path), | ||
aqora_config::ReadMe::Table { file, .. } => file.as_ref(), | ||
}); |
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.
check crate::readme
for how we look for the readme. maybe you can break up that function to providing the path and reading it
4b1ec44
to
8e2d5f2
Compare
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.
Looking better!!!
src/readme.rs
Outdated
break; | ||
|
||
if let Some(path) = path { | ||
return Ok(Some(path)); |
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.
This path is relative so it has to be joined to the project_dir
@@ -1,82 +1,85 @@ | |||
use aqora_config::ReadMe; |
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.
I'm not sure if these updates are 100% correct. You can pass a README inline directly into the pyproject.toml. If you want to explicitly not allow those types of README, you have to throw a relevant error because its not very transparent here. I think for 100% correctness, we would have 2 functions. One for reading the README like we had before, and one for writing the README, where we either get the path and write to the file or we use toml_edit
to write to [readme.text]
src/commands/test.rs
Outdated
&score, | ||
global.aqora_url()?, | ||
) | ||
.await?; |
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.
I would maybe just emit a warning here if we can't write to the README as it would be
a shame to throw an error for something that's decorative and make people feel like they need to rerun their tests
src/commands/test.rs
Outdated
project.project.as_ref().and_then(|p| p.readme.as_ref()), | ||
) | ||
.await | ||
.map_err(|err| { |
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.
I'd throw a warning here as its just decorative / a nice to have
src/commands/test.rs
Outdated
let mut contents = String::new(); | ||
file.read_to_string(&mut contents).await?; | ||
let updated_content = regex_replace_all!( | ||
r"(?:<!--\s*aqora:score:start\s*-->.*?<!--\s*aqora:score:end\s*-->)|(!\[Aqora Score Badge\]\([^\)]+\))", |
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.
Would this replace <!-- aqora:score:start -->![Aqora Score Badge](...)<!-- aqora:score:end -->
with ![Aqora Score Badge](...)
or am I reading this wrong? Shouldn't it wrap the the replaced section in comments as well?
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.
Nope! This is going to replace <!-- aqora:score:start --><!-- aqora:score:end -->
or ![Aqora Score Badge](...)
with the generated badge. The thing is, we have to either comment out or replace an existing badge that we don’t want to keep!
feat: implement shield badge feat: inject score badge in readme after test chore: fix generated badge md
a244436
to
c011131
Compare
c011131
to
a37dbfa
Compare
Pull request was converted to draft
@Angel-Dijoux what's the state of this one? |
Waiting for @volgar1x with the badge renderer server (https://github.com/aqora-io/deno-badge-renderer) |
I wasn't aware you were blocked sorry! Have you updated this pr to work with this new server? |
feat: implement shield badge
feat: inject score badge in readme after test
chore: fix generated badge md