Skip to content

Commit aa1c215

Browse files
lauraschauercopernico
authored andcommitted
send one request to update security relevance of a batch of commits (instead of sending a request for each individual commit)
1 parent 51bf343 commit aa1c215

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

prospector/core/prospector.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from git.version_to_tag import get_possible_tags
2020
from llm.llm_service import LLMService
2121
from log.logger import get_level, logger, pretty_log
22-
from rules.rules import RULES_PHASE_1, apply_rules
22+
from rules.rules import NUM_COMMITS_PHASE_2, RULES_PHASE_1, apply_rules
2323
from stats.execution import (
2424
Counter,
2525
ExecutionTimer,
@@ -242,14 +242,18 @@ def prospector( # noqa: C901
242242
and use_backend != USE_BACKEND_NEVER
243243
and len(missing) > 0
244244
):
245-
save_preprocessed_commits(backend_address, payload)
245+
save_or_update_processed_commits(backend_address, payload)
246246
else:
247247
logger.warning("Preprocessed commits are not being sent to backend")
248248

249249
ranked_candidates = evaluate_commits(
250250
preprocessed_commits, advisory_record, backend_address, enabled_rules
251251
)
252252

253+
# Save outcome of security relevance to DB (Phase 2 Rule)
254+
payload = [c.to_dict() for c in ranked_candidates[:NUM_COMMITS_PHASE_2]]
255+
save_or_update_processed_commits(backend_address, payload)
256+
253257
# ConsoleWriter.print("Commit ranking and aggregation...")
254258
ranked_candidates = remove_twins(ranked_candidates)
255259
# ranked_candidates = tag_and_aggregate_commits(ranked_candidates, next_tag)
@@ -398,7 +402,7 @@ def retrieve_preprocessed_commits(
398402
return (missing, commits)
399403

400404

401-
def save_preprocessed_commits(backend_address, payload):
405+
def save_or_update_processed_commits(backend_address, payload):
402406
with ExecutionTimer(
403407
core_statistics.sub_collection(name="save commits to backend")
404408
):

prospector/rules/rules.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
Counter,
1313
ExecutionTimer,
1414
execution_statistics,
15-
measure_execution_time,
1615
)
1716
from util.lsh import build_lsh_index, decode_minhash
1817

@@ -459,12 +458,7 @@ def apply(
459458
candidate.diff, candidate.repository, candidate.message
460459
)
461460

462-
update_response = requests.post(
463-
backend_address + "/commits/",
464-
json=[candidate.to_dict()],
465-
headers={"content-type": "application/json"},
466-
)
467-
update_response.raise_for_status()
461+
return candidate.security_relevant
468462

469463
except requests.exceptions.RequestException as e:
470464
error_type = type(e).__name__

0 commit comments

Comments
 (0)