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

feat: add shield badges in README.md #96

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Angel-Dijoux
Copy link
Contributor

feat: implement shield badge

feat: inject score badge in readme after test

chore: fix generated badge md

@Angel-Dijoux Angel-Dijoux self-assigned this Nov 4, 2024
@Angel-Dijoux Angel-Dijoux force-pushed the angel/add_git_default_template branch from 41fcb6f to abd287e Compare November 4, 2024 17:19
Copy link
Contributor

@jpopesculian jpopesculian left a 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

@@ -0,0 +1,20 @@
use git2::{Error, Repository, RepositoryInitOptions};
Copy link
Contributor

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

@@ -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");
Copy link
Contributor

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

let mut contents = String::new();
file.read_to_string(&mut contents).await?;
file.seek(SeekFrom::Start(0)).await?;
file.write_all(
Copy link
Contributor

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

Copy link
Contributor Author

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:

  1. A default use-case badge, which redirects to the Aqora use case.
  2. A score badge that displays the user’s score!

Copy link
Contributor Author

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!

Copy link
Contributor

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 ?

Copy link
Contributor Author

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!

template/assets/use_case/README.md.hbs Show resolved Hide resolved
@Angel-Dijoux Angel-Dijoux changed the title feat: init a repo for default use_case template feat: add shield badges in README.md Nov 5, 2024
@Angel-Dijoux Angel-Dijoux force-pushed the angel/add_git_default_template branch 2 times, most recently from 2f3d59d to a2ff781 Compare November 5, 2024 18:44
Copy link
Contributor

@jpopesculian jpopesculian left a 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

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 {
Copy link
Contributor

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"]}
Copy link
Contributor

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

let mut contents = String::new();
file.read_to_string(&mut contents).await?;
let updated_content = regex_replace_all!(
r"(?:<!--- score_badge -->)|(!\[Aqora Score Badge\]\([^\)]+\))",
Copy link
Contributor

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*-->

@@ -325,6 +387,7 @@ pub async fn run_submission_tests(
})
.collect::<Result<Vec<_>>>()?;

let competition = modified_use_case.clone().competition.unwrap_or_default();
Copy link
Contributor

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

@@ -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(|| {
Copy link
Contributor

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

"See : https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#readme",
)
})?);
update_score_badge_in_file(path, &competition, &score, global.aqora_url().unwrap())
Copy link
Contributor

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 ?

.and_then(|readme| match readme {
aqora_config::ReadMe::RelativePath(path) => Some(path),
aqora_config::ReadMe::Table { file, .. } => file.as_ref(),
});
Copy link
Contributor

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

template/assets/use_case/template/README.md.hbs Outdated Show resolved Hide resolved
@Angel-Dijoux Angel-Dijoux force-pushed the angel/add_git_default_template branch from 4b1ec44 to 8e2d5f2 Compare November 15, 2024 18:07
Copy link
Contributor

@jpopesculian jpopesculian left a 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));
Copy link
Contributor

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;
Copy link
Contributor

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]

&score,
global.aqora_url()?,
)
.await?;
Copy link
Contributor

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

project.project.as_ref().and_then(|p| p.readme.as_ref()),
)
.await
.map_err(|err| {
Copy link
Contributor

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

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\]\([^\)]+\))",
Copy link
Contributor

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?

Copy link
Contributor Author

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!

@Angel-Dijoux Angel-Dijoux force-pushed the angel/add_git_default_template branch from a244436 to c011131 Compare November 26, 2024 21:24
@Angel-Dijoux Angel-Dijoux force-pushed the angel/add_git_default_template branch from c011131 to a37dbfa Compare November 27, 2024 07:55
@Angel-Dijoux Angel-Dijoux marked this pull request as draft December 6, 2024 18:41
auto-merge was automatically disabled December 6, 2024 18:41

Pull request was converted to draft

@stubbi
Copy link
Contributor

stubbi commented Dec 17, 2024

@Angel-Dijoux what's the state of this one?

@Angel-Dijoux
Copy link
Contributor Author

@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)

@volgar1x
Copy link
Contributor

@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?

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.

4 participants