-
Notifications
You must be signed in to change notification settings - Fork 9
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
Review page feature #140
Merged
Review page feature #140
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
COPR_BUILD_URL, | ||
KOJI_BUILD_URL, | ||
FEEDBACK_DIR, | ||
REVIEWS_DIR, | ||
BuildIdTitleEnum, | ||
ProvidersEnum, | ||
) | ||
|
@@ -34,9 +35,10 @@ | |
ContributeResponseSchema, | ||
FeedbackInputSchema, | ||
FeedbackSchema, | ||
FeedbackLogSchema, | ||
schema_inp_to_out, | ||
) | ||
from src.spells import make_tar, get_temporary_dir | ||
from src.spells import make_tar, get_temporary_dir, find_file_by_name | ||
from src.store import Storator3000 | ||
|
||
logger = logging.getLogger(__name__) | ||
|
@@ -259,26 +261,73 @@ def contribute_review_container_logs( | |
|
||
|
||
@app.get("/frontend/review/random") | ||
def frontend_review_random() -> FeedbackSchema: | ||
if os.environ.get("ENV") == "production": | ||
raise NotImplementedError("Reviewing is not ready yet") | ||
|
||
def frontend_review_random(): | ||
random_feedback_file = Storator3000.get_random() | ||
with open(random_feedback_file) as random_file: | ||
content = json.loads(random_file.read()) | ||
return FeedbackSchema(**content) | ||
return FeedbackSchema(**content).dict() | {"id": random_feedback_file.name.rstrip(".json")} | ||
|
||
|
||
def _get_text_from_feedback(item: dict) -> str: | ||
if item["vote"] != 1: | ||
return "" | ||
|
||
return item["text"] | ||
|
||
@app.get("/frontend/review/latest") | ||
def frontend_review_latest() -> FeedbackSchema: | ||
if os.environ.get("ENV") == "production": | ||
raise NotImplementedError("Reviewing is not ready yet") | ||
|
||
feedback_file = Storator3000.get_latest() | ||
def _parse_logs(logs_orig: dict[str, FeedbackLogSchema], review_snippets: list[dict]) -> None: | ||
for name, item in logs_orig.items(): | ||
item.snippets = [] | ||
for snippet in review_snippets: | ||
if snippet["file"] == name and snippet["vote"] == 1: | ||
# mypy can't see this far and hinting to it is messy | ||
item.snippets.append(snippet) # type: ignore[arg-type] | ||
|
||
with open(feedback_file) as file: | ||
content = json.loads(file.read()) | ||
return FeedbackSchema(**content) | ||
|
||
def _parse_feedback(review_d: dict, origin_id: int) -> FeedbackSchema: | ||
original_file_path = find_file_by_name(f"{origin_id}.json", Path(FEEDBACK_DIR)) | ||
if original_file_path is None: | ||
raise HTTPException( | ||
status_code=HTTPStatus.NOT_FOUND, | ||
detail=f"Original feedback file for ID {origin_id} not found", | ||
) | ||
|
||
with open(original_file_path, encoding="utf-8") as fp: | ||
original_content = json.load(fp) | ||
schema = FeedbackSchema(**original_content) | ||
# no reason to store username | ||
schema.username = None | ||
schema.fail_reason = _get_text_from_feedback(review_d["fail_reason"]) | ||
schema.how_to_fix = _get_text_from_feedback(review_d["how_to_fix"]) | ||
_parse_logs(schema.logs, review_d["snippets"]) | ||
return schema.dict(exclude_unset=True) | ||
|
||
|
||
@app.post("/frontend/review") | ||
async def store_random_review(feedback_input: Request) -> OkResponse: | ||
""" | ||
Store review from frontend. | ||
""" | ||
# TODO: temporary silly solution until database is created | ||
# (missing provider but we can dig it from original feedback file) | ||
Comment on lines
+311
to
+312
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. I was confused about that directory structure, now I understand :) 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. |
||
reviews_dir = Path(REVIEWS_DIR) | ||
parsed_reviews_dir = reviews_dir / "parsed" | ||
parsed_reviews_dir.mkdir(parents=True, exist_ok=True) | ||
content = await feedback_input.json() | ||
original_file_id = content.pop("id") | ||
# avoid duplicates - same ID can be reviewed multiple times | ||
file_name = f"{original_file_id}-{int(datetime.now().timestamp())}" | ||
with open(reviews_dir / f"{file_name}.json", "w", encoding="utf-8") as fp: | ||
json.dump(content | {"id": original_file_id}, fp, indent=4) | ||
|
||
with open(parsed_reviews_dir / f"{file_name}.json", "w", encoding="utf-8") as fp: | ||
json.dump( | ||
_parse_feedback(content, original_file_id) | {"id": original_file_id}, | ||
fp, | ||
indent=4 | ||
) | ||
|
||
return OkResponse() | ||
|
||
|
||
def _make_tpm_tar_file_from_results() -> Iterator[Path]: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
STORAGE_DIR=/persistent | ||
FEEDBACK_DIR=/persistent/results | ||
REVIEWS_DIR=/persistent/reviews |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 type?
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.
The response structure is checked at the return statement with feedback schema - there's just added
id
for the reference and I didn't want to add another unicorn schema toschema.py
since this will disappear with database creation and simply the structure is parsed - just theid
is added at the end.