Skip to content

Commit

Permalink
send one request to update security relevance of a batch of commits (…
Browse files Browse the repository at this point in the history
…instead of sending a request for each individual commit)
  • Loading branch information
lauraschauer authored and copernico committed Aug 16, 2024
1 parent 51bf343 commit aa1c215
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
10 changes: 7 additions & 3 deletions prospector/core/prospector.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from git.version_to_tag import get_possible_tags
from llm.llm_service import LLMService
from log.logger import get_level, logger, pretty_log
from rules.rules import RULES_PHASE_1, apply_rules
from rules.rules import NUM_COMMITS_PHASE_2, RULES_PHASE_1, apply_rules
from stats.execution import (
Counter,
ExecutionTimer,
Expand Down Expand Up @@ -242,14 +242,18 @@ def prospector( # noqa: C901
and use_backend != USE_BACKEND_NEVER
and len(missing) > 0
):
save_preprocessed_commits(backend_address, payload)
save_or_update_processed_commits(backend_address, payload)
else:
logger.warning("Preprocessed commits are not being sent to backend")

ranked_candidates = evaluate_commits(
preprocessed_commits, advisory_record, backend_address, enabled_rules
)

# Save outcome of security relevance to DB (Phase 2 Rule)
payload = [c.to_dict() for c in ranked_candidates[:NUM_COMMITS_PHASE_2]]
save_or_update_processed_commits(backend_address, payload)

# ConsoleWriter.print("Commit ranking and aggregation...")
ranked_candidates = remove_twins(ranked_candidates)
# ranked_candidates = tag_and_aggregate_commits(ranked_candidates, next_tag)
Expand Down Expand Up @@ -398,7 +402,7 @@ def retrieve_preprocessed_commits(
return (missing, commits)


def save_preprocessed_commits(backend_address, payload):
def save_or_update_processed_commits(backend_address, payload):
with ExecutionTimer(
core_statistics.sub_collection(name="save commits to backend")
):
Expand Down
8 changes: 1 addition & 7 deletions prospector/rules/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
Counter,
ExecutionTimer,
execution_statistics,
measure_execution_time,
)
from util.lsh import build_lsh_index, decode_minhash

Expand Down Expand Up @@ -459,12 +458,7 @@ def apply(
candidate.diff, candidate.repository, candidate.message
)

update_response = requests.post(
backend_address + "/commits/",
json=[candidate.to_dict()],
headers={"content-type": "application/json"},
)
update_response.raise_for_status()
return candidate.security_relevant

except requests.exceptions.RequestException as e:
error_type = type(e).__name__
Expand Down

0 comments on commit aa1c215

Please sign in to comment.