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

Add to comment instead of exchanging #449

Merged
merged 6 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/store/crud/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_get_analyses_by_status_started_at_and_comment(
existing_analysis: Analysis = analysis_store.get_query(table=Analysis).first()

# GIVEN a comment
analysis_store.update_analysis_comment(
analysis_store.update_latest_analysis_comment(
case_id=existing_analysis.case_id, comment="a new comment"
)

Expand All @@ -35,7 +35,7 @@ def test_get_analyses_by_status_started_at_and_comment_with_comment(analysis_sto
existing_analysis: Analysis = analysis_store.get_query(table=Analysis).first()

# GIVEN a comment
analysis_store.update_analysis_comment(
analysis_store.update_latest_analysis_comment(
case_id=existing_analysis.case_id, comment="a new comment"
)

Expand Down
6 changes: 3 additions & 3 deletions tests/store/crud/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def test_update_analysis_comment(analysis_store: MockStore, case_id: str):
comment: str = "test comment"

# WHEN adding a comment
analysis_store.update_analysis_comment(case_id=analysis.case_id, comment=comment)
analysis_store.update_latest_analysis_comment(case_id=analysis.case_id, comment=comment)

# THEN a comment should have been added
assert analysis.comment == comment
Expand All @@ -350,8 +350,8 @@ def test_update_analysis_comment_when_existing(analysis_store: MockStore, case_i
second_comment: str = "Second"

# WHEN adding a comment
analysis_store.update_analysis_comment(case_id=analysis.case_id, comment=first_comment)
analysis_store.update_analysis_comment(case_id=analysis.case_id, comment=second_comment)
analysis_store.update_latest_analysis_comment(case_id=analysis.case_id, comment=first_comment)
analysis_store.update_latest_analysis_comment(case_id=analysis.case_id, comment=second_comment)

# THEN comments should have been added
assert analysis.comment == f"{first_comment} {second_comment}"
Expand Down
2 changes: 1 addition & 1 deletion trailblazer/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def add_comment():
try:
case_id: str = put_request.get("case_id")
comment: str = put_request.get("comment")
store.update_analysis_comment(case_id=case_id, comment=comment)
store.update_latest_analysis_comment(case_id=case_id, comment=comment)
return jsonify("Success! Adding comment request sent"), HTTPStatus.CREATED
except Exception as error:
return jsonify(f"Exception: {error}"), HTTPStatus.CONFLICT
9 changes: 7 additions & 2 deletions trailblazer/store/crud/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,11 @@ def cancel_ongoing_analysis(
LOG.info(f"Case {analysis.case_id} - Analysis {analysis.id}: cancelled successfully!")
self.update_run_status(analysis_id=analysis_id, analysis_host=analysis_host)
analysis.status = TrailblazerStatus.CANCELLED
analysis.comment = (
new_comment: str = (
f"Analysis cancelled manually by user:"
f" {(self.get_user(email=email).name if self.get_user(email=email) else (email or 'Unknown'))}!"
islean marked this conversation as resolved.
Show resolved Hide resolved
)
self.update_analysis_comment(analysis=analysis, comment=new_comment)
session: Session = get_session()
session.commit()

Expand Down Expand Up @@ -226,8 +227,12 @@ def update_analysis_uploaded_at(self, case_id: str, uploaded_at: datetime) -> No
session: Session = get_session()
session.commit()

def update_analysis_comment(self, case_id: str, comment: str) -> None:
def update_latest_analysis_comment(self, case_id: str, comment: str) -> None:
analysis: Analysis | None = self.get_latest_analysis_for_case(case_id)
self.update_analysis_comment(analysis=analysis, comment=comment)

@staticmethod
def update_analysis_comment(analysis: Analysis, comment: str):
analysis.comment: str = (
" ".join([analysis.comment, comment]) if analysis.comment else comment
)
Expand Down
Loading