bugbug 0.0.659__tar.gz → 0.0.660__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bugbug-0.0.659 → bugbug-0.0.660}/PKG-INFO +1 -1
- bugbug-0.0.660/VERSION +1 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/db.py +41 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/repository.py +158 -1
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/test_scheduling.py +47 -1
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/code_review/agent.py +12 -19
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/code_review/review_context.py +96 -15
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/code_review/review_context_schema.py +54 -4
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/commit_classifier.py +6 -2
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/commit_retriever.py +8 -3
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/generate_landings_risk_report.py +6 -1
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/shadow_scheduler_stats.py +8 -2
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/testing_policy_stats.py +6 -1
- bugbug-0.0.659/VERSION +0 -1
- {bugbug-0.0.659 → bugbug-0.0.660}/.gitignore +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/LICENSE +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/__init__.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/bug_features.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/bug_snapshot.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/bugzilla.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/build_platforms.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/code_search/__init__.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/code_search/function_search.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/code_search/mozilla.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/code_search/parser.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/code_search/searchfox_api.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/code_search/searchfox_data.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/code_search/searchfox_download.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/commit_features.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/feature_cleanup.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/github.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/issue_features.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/issue_snapshot.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/labels/annotateignore.csv +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/labels/bug_nobug.csv +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/labels/defect_enhancement_task.csv +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/labels/defect_enhancement_task_e.csv +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/labels/defect_enhancement_task_h.csv +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/labels/defect_enhancement_task_p.csv +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/labels/defect_enhancement_task_s.csv +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/labels/regression_bug_nobug.csv +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/labels/regressionrange.csv +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/labels/str.csv +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/labels/tracking.csv +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/labels.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/model.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/model_calibration.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/__init__.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/accessibility.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/annotate_ignore.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/assignee.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/backout.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/browsername.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/bugtype.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/component.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/component_specific.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/defect.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/defect_enhancement_task.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/devdocneeded.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/fenixcomponent.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/fixtime.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/invalid_compatibility_report.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/needsdiagnosis.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/perf_regression_predictor.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/performancebug.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/qaneeded.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/rcatype.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/regression.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/regressionrange.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/regressor.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/severity.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/spambug.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/stepstoreproduce.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/testconfigdimensions.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/testconfigselect.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/testfailure.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/testselect.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/tracking.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/uplift.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/models/worksforme.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/nlp.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/__init__.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/calibration.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/commit_risk.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/datasets.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/extraction.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/label_policy.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/push_status.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/regression_commits.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/regression_labeling.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/selection_pairs.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/simulation/__init__.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/simulation/capacity.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/simulation/detection.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/simulation/metrics.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/simulation/optimize.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/simulation/splits.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/simulation/stats.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/simulation/strategies.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/simulation/timeline.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/sql/__init__.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/sql/perf_alerts.sql +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/sql/perf_capacity_background.sql +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/sql/perf_capacity_builds.sql +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/sql/perf_capacity_eligible.sql +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/sql/perf_capacity_labels.sql +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/sql/perf_capacity_pools.sql +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/sql/perf_capacity_workers.sql +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/sql/perf_pushes.sql +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/sql/perf_task_costs.sql +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/sql/perf_task_filter.sql +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/task_costs.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/perf/task_labels.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/phabricator.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/redash.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/rust_code_analysis_server.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/sklearn_utils.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/swarm.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/test_scheduling_features.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/__init__.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/base.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/code_review/__init__.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/code_review/data_types.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/code_review/database.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/code_review/langchain_tools.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/code_review/prompts.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/code_review/protocols.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/code_review/scorer.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/code_review/utils.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/comment_matching/agent.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/comment_matching/prompts.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/comment_resolution/__init__.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/comment_resolution/agent.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/core/__init__.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/core/connection.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/core/data_types.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/core/exceptions.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/core/llms.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/core/platforms/__init__.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/core/platforms/base.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/core/platforms/bugzilla.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/core/platforms/patch_apply.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/core/platforms/phabricator.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/core/text.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/core/validators.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/patch_summarization/__init__.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/patch_summarization/agent.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/patch_summarization/prompts.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/suggestion_filtering/__init__.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/suggestion_filtering/agent.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/tools/suggestion_filtering/prompts.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/utils.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/bugbug/vectordb.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/pyproject.toml +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/__init__.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/analyze_training_metrics.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/backout_related_test_regressions.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/bug_classifier.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/bug_retriever.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/check.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/check_all_metrics.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/ci_failures_matching.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/comment_classifier.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/comment_level_labeler.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/comment_resolver_runner.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/compatibility_report_classifier.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/gcp_logs_retriever.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/generate_sheet.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/get_type_labels.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/get_untriaged.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/github_issue_classifier.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/github_issue_retriever.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/inline_comments_data_collection.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/integration_test.sh +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/maintenance_effectiveness_indicator.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/microannotate_generator.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/past_bugs_by_unit.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/perf_alerts_retriever.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/perf_commit_risk_scorer.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/perf_regression_predictor.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/perf_scheduling_simulator.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/redundant_failures.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/regressor_finder.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/retrieve_ci_failures.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/retrieve_training_metrics.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/retrieve_try_pushes.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/review_comments_retriever.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/revision_retriever.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/test_scheduling_history_retriever.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/trainer.py +0 -0
- {bugbug-0.0.659 → bugbug-0.0.660}/scripts/trainer_extract_args.py +0 -0
bugbug-0.0.660/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.0.660
|
|
@@ -22,6 +22,9 @@ DATABASES = {}
|
|
|
22
22
|
|
|
23
23
|
logger = logging.getLogger(__name__)
|
|
24
24
|
|
|
25
|
+
# The size of the blocks read from the end of a DB by read_last.
|
|
26
|
+
READ_LAST_BLOCK_SIZE = 1024 * 1024
|
|
27
|
+
|
|
25
28
|
|
|
26
29
|
class LastModifiedNotAvailable(Exception):
|
|
27
30
|
pass
|
|
@@ -239,6 +242,44 @@ def read(path):
|
|
|
239
242
|
yield from store.read()
|
|
240
243
|
|
|
241
244
|
|
|
245
|
+
def read_last_lines(path: str, count: int) -> list[bytes]:
|
|
246
|
+
"""Read the last `count` serialized elements of an uncompressed JSON DB, from the oldest.
|
|
247
|
+
|
|
248
|
+
Only the end of the file is read, so it is fast also with very large DBs. The elements aren't
|
|
249
|
+
deserialized, so that callers can skip some of them cheaply.
|
|
250
|
+
"""
|
|
251
|
+
assert path in DATABASES
|
|
252
|
+
assert str(path).endswith(".json"), "Only uncompressed JSON DBs are supported"
|
|
253
|
+
|
|
254
|
+
if not os.path.exists(path) or count <= 0:
|
|
255
|
+
return []
|
|
256
|
+
|
|
257
|
+
with open(path, "rb") as f:
|
|
258
|
+
pos = f.seek(0, os.SEEK_END)
|
|
259
|
+
blocks: list[bytes] = []
|
|
260
|
+
newlines = 0
|
|
261
|
+
# One more newline than elements is needed to be sure the oldest one is complete (unless
|
|
262
|
+
# the start of the file is reached).
|
|
263
|
+
while pos > 0 and newlines <= count:
|
|
264
|
+
read_size = min(READ_LAST_BLOCK_SIZE, pos)
|
|
265
|
+
pos -= read_size
|
|
266
|
+
f.seek(pos)
|
|
267
|
+
block = f.read(read_size)
|
|
268
|
+
blocks.append(block)
|
|
269
|
+
newlines += block.count(b"\n")
|
|
270
|
+
|
|
271
|
+
lines = b"".join(reversed(blocks)).splitlines()
|
|
272
|
+
if pos > 0:
|
|
273
|
+
# The first line can be partial.
|
|
274
|
+
lines = lines[1:]
|
|
275
|
+
return [line for line in lines[-count:] if line]
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def read_last(path: str, count: int) -> list:
|
|
279
|
+
"""Read the last `count` elements of an uncompressed JSON DB, from the oldest (see read_last_lines)."""
|
|
280
|
+
return [orjson.loads(line) for line in read_last_lines(path, count)]
|
|
281
|
+
|
|
282
|
+
|
|
242
283
|
def size(path):
|
|
243
284
|
assert path in DATABASES
|
|
244
285
|
|
|
@@ -17,6 +17,7 @@ import os
|
|
|
17
17
|
import pickle
|
|
18
18
|
import re
|
|
19
19
|
import shelve
|
|
20
|
+
import shutil
|
|
20
21
|
import subprocess
|
|
21
22
|
import sys
|
|
22
23
|
import threading
|
|
@@ -26,6 +27,7 @@ from typing import Collection, Iterable, Iterator, NamedTuple, NewType, Set, Uni
|
|
|
26
27
|
|
|
27
28
|
import hglib
|
|
28
29
|
import lmdb
|
|
30
|
+
import orjson
|
|
29
31
|
import requests
|
|
30
32
|
import rs_parsepatch
|
|
31
33
|
import tenacity
|
|
@@ -321,6 +323,132 @@ def get_commits(
|
|
|
321
323
|
)
|
|
322
324
|
|
|
323
325
|
|
|
326
|
+
# How many commits get_last_commit reads from the end of the commits DB before falling back to
|
|
327
|
+
# reading all of them.
|
|
328
|
+
LAST_COMMIT_RECENT_COMMITS = 256
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def get_last_commit(
|
|
332
|
+
include_no_bug: bool = False,
|
|
333
|
+
include_backouts: bool = False,
|
|
334
|
+
include_ignored: bool = False,
|
|
335
|
+
) -> CommitDict | None:
|
|
336
|
+
"""Return the last commit that get_commits would return, or None if it would return none.
|
|
337
|
+
|
|
338
|
+
Only the end of the commits DB is read, unless none of the last commits passes the filters.
|
|
339
|
+
"""
|
|
340
|
+
filters = {
|
|
341
|
+
"include_no_bug": include_no_bug,
|
|
342
|
+
"include_backouts": include_backouts,
|
|
343
|
+
"include_ignored": include_ignored,
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
recent_commits = db.read_last(COMMITS_DB, LAST_COMMIT_RECENT_COMMITS)
|
|
347
|
+
last_commit = collections.deque(filter_commits(recent_commits, **filters), maxlen=1)
|
|
348
|
+
# If fewer commits than requested were read, the whole DB was read.
|
|
349
|
+
if not last_commit and len(recent_commits) == LAST_COMMIT_RECENT_COMMITS:
|
|
350
|
+
logger.info("None of the last commits passes the filters, reading all commits")
|
|
351
|
+
last_commit = collections.deque(get_commits(**filters), maxlen=1)
|
|
352
|
+
|
|
353
|
+
return last_commit[0] if last_commit else None
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
# The offset of each commit in the commits DB, by node, to find them without reading the whole DB.
|
|
357
|
+
COMMITS_INDEX_DB = "data/commits_index.lmdb"
|
|
358
|
+
# The size of the part of the commits DB which is indexed.
|
|
359
|
+
COMMITS_INDEX_SIZE_KEY = b"$indexed_size$"
|
|
360
|
+
# The serialized commits start with their node (see Commit.to_dict).
|
|
361
|
+
COMMIT_LINE_PREFIX = b'{"node":"'
|
|
362
|
+
COMMITS_INDEX_BLOCK_SIZE = 16 * 1024 * 1024
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def _update_commits_index(index: LMDBDict) -> None:
|
|
366
|
+
# The offset in the DB of the start of `pending`, the part of the DB read but not indexed yet.
|
|
367
|
+
pos = int(bytes(index.get(COMMITS_INDEX_SIZE_KEY, b"0")))
|
|
368
|
+
pending = b""
|
|
369
|
+
|
|
370
|
+
with open(COMMITS_DB, "rb") as f:
|
|
371
|
+
f.seek(pos)
|
|
372
|
+
# The DB is read in blocks, as mapping it in memory would make it count as used memory.
|
|
373
|
+
while block := f.read(COMMITS_INDEX_BLOCK_SIZE):
|
|
374
|
+
pending += block
|
|
375
|
+
start = 0
|
|
376
|
+
# Only the complete lines are indexed, in case the DB is being written to.
|
|
377
|
+
while (end := pending.find(b"\n", start)) != -1:
|
|
378
|
+
node_start = start + len(COMMIT_LINE_PREFIX)
|
|
379
|
+
if pending.startswith(COMMIT_LINE_PREFIX, start):
|
|
380
|
+
node = pending[node_start : node_start + 40]
|
|
381
|
+
else:
|
|
382
|
+
node = orjson.loads(pending[start:end])["node"].encode("ascii")
|
|
383
|
+
index[node] = str(pos + start).encode("ascii")
|
|
384
|
+
start = end + 1
|
|
385
|
+
pending = pending[start:]
|
|
386
|
+
pos += start
|
|
387
|
+
|
|
388
|
+
index[COMMITS_INDEX_SIZE_KEY] = str(pos).encode("ascii")
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
def delete_commits_index() -> None:
|
|
392
|
+
"""Delete the index of the commits DB, which is wrong once the DB is rewritten."""
|
|
393
|
+
shutil.rmtree(COMMITS_INDEX_DB, ignore_errors=True)
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
def update_commits_index() -> None:
|
|
397
|
+
"""Index the commits added to the commits DB since the last update."""
|
|
398
|
+
index = LMDBDict(COMMITS_INDEX_DB)
|
|
399
|
+
try:
|
|
400
|
+
_update_commits_index(index)
|
|
401
|
+
finally:
|
|
402
|
+
index.close()
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
def _get_commits_offsets(nodes: Iterable[str]) -> dict[str, int]:
|
|
406
|
+
"""Return the offsets in the commits DB of the commits among `nodes` which are in it.
|
|
407
|
+
|
|
408
|
+
The index of the DB is updated first with the commits added to the DB since the last update.
|
|
409
|
+
"""
|
|
410
|
+
if not os.path.exists(COMMITS_DB):
|
|
411
|
+
return {}
|
|
412
|
+
|
|
413
|
+
index = LMDBDict(COMMITS_INDEX_DB)
|
|
414
|
+
try:
|
|
415
|
+
_update_commits_index(index)
|
|
416
|
+
return {
|
|
417
|
+
node: int(bytes(offset))
|
|
418
|
+
for node in nodes
|
|
419
|
+
if (offset := index.get(node.encode("ascii"))) is not None
|
|
420
|
+
}
|
|
421
|
+
finally:
|
|
422
|
+
index.close()
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
def get_nodes_in_db(nodes: Iterable[str]) -> set[str]:
|
|
426
|
+
"""Return the commits among `nodes` which are in the commits DB."""
|
|
427
|
+
return set(_get_commits_offsets(nodes))
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
def get_commits_from_db(nodes: Iterable[str]) -> dict[str, CommitDict]:
|
|
431
|
+
"""Return the commits among `nodes` which are already in the commits DB, by node.
|
|
432
|
+
|
|
433
|
+
These commits can't be mined again (with save=False), as their experience features would be
|
|
434
|
+
calculated after the ones of the commits pushed after them, which are in the experiences DB.
|
|
435
|
+
The commits are found through an index of the DB.
|
|
436
|
+
"""
|
|
437
|
+
offsets = _get_commits_offsets(nodes)
|
|
438
|
+
if not offsets:
|
|
439
|
+
return {}
|
|
440
|
+
|
|
441
|
+
commits: dict[str, CommitDict] = {}
|
|
442
|
+
with open(COMMITS_DB, "rb") as f:
|
|
443
|
+
for node, offset in offsets.items():
|
|
444
|
+
f.seek(offset)
|
|
445
|
+
commit = orjson.loads(f.readline())
|
|
446
|
+
assert commit["node"] == node, f"The commits index is wrong for {node}"
|
|
447
|
+
commits[node] = commit
|
|
448
|
+
|
|
449
|
+
return commits
|
|
450
|
+
|
|
451
|
+
|
|
324
452
|
def get_revision_id(commit: CommitDict) -> int | None:
|
|
325
453
|
match = PHABRICATOR_REVISION_REGEX.search(commit["desc"])
|
|
326
454
|
if not match:
|
|
@@ -1045,6 +1173,22 @@ def get_revs(hg, rev_start=0, rev_end="default"):
|
|
|
1045
1173
|
return x.splitlines()
|
|
1046
1174
|
|
|
1047
1175
|
|
|
1176
|
+
def get_new_revs(hg: hglib.client, base: str, head: str) -> list[bytes]:
|
|
1177
|
+
"""Get the non-merge commits on the default branch which are ancestors of `head`, but not of `base`.
|
|
1178
|
+
|
|
1179
|
+
Unlike the commits after `base` by revision number, these don't include the commits from other
|
|
1180
|
+
repositories pulled in the same clone (e.g. try).
|
|
1181
|
+
"""
|
|
1182
|
+
args = hglib.util.cmdbuilder(
|
|
1183
|
+
b"log",
|
|
1184
|
+
template="{node}\n",
|
|
1185
|
+
no_merges=True,
|
|
1186
|
+
branch="default",
|
|
1187
|
+
rev=f"::{head} - ::{base}",
|
|
1188
|
+
)
|
|
1189
|
+
return hg.rawcommand(args).splitlines()
|
|
1190
|
+
|
|
1191
|
+
|
|
1048
1192
|
class Experiences:
|
|
1049
1193
|
def __init__(self, save):
|
|
1050
1194
|
self.save = save
|
|
@@ -1501,7 +1645,11 @@ def download_commits(
|
|
|
1501
1645
|
# Fixing https://github.com/mozilla/bugbug/issues/3131
|
|
1502
1646
|
mp_context=mp.get_context("fork"),
|
|
1503
1647
|
) as executor:
|
|
1504
|
-
|
|
1648
|
+
# Large chunks reduce the overhead when mining many commits, but with few of them
|
|
1649
|
+
# (e.g. when updating the DB) they would leave most processes idle: give several
|
|
1650
|
+
# chunks to each process.
|
|
1651
|
+
chunksize = max(1, min(64, commits_num // ((cpu_count or 1) * 4)))
|
|
1652
|
+
commits_iter = executor.map(_transform, commits, chunksize=chunksize)
|
|
1505
1653
|
commits_iter = tqdm(commits_iter, total=commits_num)
|
|
1506
1654
|
commits = tuple(commits_iter)
|
|
1507
1655
|
else:
|
|
@@ -1653,6 +1801,7 @@ def update_commits(repo_dir: str | None = None) -> None:
|
|
|
1653
1801
|
refresh_backouts_and_ignored(repo_dir, commits)
|
|
1654
1802
|
|
|
1655
1803
|
db.write(COMMITS_DB, commits)
|
|
1804
|
+
delete_commits_index()
|
|
1656
1805
|
|
|
1657
1806
|
|
|
1658
1807
|
def clean(hg, repo_dir):
|
|
@@ -1702,6 +1851,10 @@ def clone(
|
|
|
1702
1851
|
if "abort: repository" not in str(e) and "not found" not in str(e):
|
|
1703
1852
|
raise
|
|
1704
1853
|
|
|
1854
|
+
# robustcheckout pulls twice: into the pooled store, and then into the share. mozext records
|
|
1855
|
+
# the pushes in the `changetracker.db` of each repository (not in the shared store), so it would
|
|
1856
|
+
# download the whole pushlog for both pulls, and the copy of the pooled store is never used. Its
|
|
1857
|
+
# database is disabled for the clone, and the pushes are retrieved once by pulling in the share.
|
|
1705
1858
|
cmd = _build_hg_cmd(
|
|
1706
1859
|
"robustcheckout",
|
|
1707
1860
|
url,
|
|
@@ -1711,9 +1864,13 @@ def clone(
|
|
|
1711
1864
|
networkattempts=7,
|
|
1712
1865
|
branch=b"default",
|
|
1713
1866
|
noupdate=not update,
|
|
1867
|
+
config=b"mozext.disable_local_database=true",
|
|
1714
1868
|
)
|
|
1715
1869
|
subprocess.run(cmd, check=True)
|
|
1716
1870
|
|
|
1871
|
+
with hglib.open(repo_dir) as hg:
|
|
1872
|
+
hg.pull(update=update)
|
|
1873
|
+
|
|
1717
1874
|
logger.info("%s cloned", repo_dir)
|
|
1718
1875
|
|
|
1719
1876
|
|
|
@@ -79,6 +79,12 @@ db.register(
|
|
|
79
79
|
TEST_GROUP_SCHEDULING_DB = "data/test_group_scheduling_history.pickle"
|
|
80
80
|
PAST_FAILURES_GROUP_DB = "past_failures_group.lmdb.tar.zst"
|
|
81
81
|
TOUCHED_TOGETHER_DB = "touched_together.lmdb.tar.zst"
|
|
82
|
+
# The number of commits at the end of the commits DB among which the last commit analyzed for the
|
|
83
|
+
# touched together DB is looked for, and how many of them before it are read too (see
|
|
84
|
+
# _get_commits_from). The window allows the DB to be updated quickly with up to about two weeks of
|
|
85
|
+
# commits.
|
|
86
|
+
TOUCHED_TOGETHER_RECENT_COMMITS = 10000
|
|
87
|
+
TOUCHED_TOGETHER_RECENT_MARGIN = 2000
|
|
82
88
|
db.register(
|
|
83
89
|
TEST_GROUP_SCHEDULING_DB,
|
|
84
90
|
"https://community-tc.services.mozilla.com/api/index/v1/task/project.bugbug.data_test_group_scheduling_history.latest/artifacts/public/test_group_scheduling_history.pickle.zst",
|
|
@@ -1079,6 +1085,45 @@ def get_cochange_pmi(source_dirs: Iterable[str], runnable_dirs: Iterable[str]) -
|
|
|
1079
1085
|
return best
|
|
1080
1086
|
|
|
1081
1087
|
|
|
1088
|
+
def _get_commits_from(
|
|
1089
|
+
last_analyzed: bytes | memoryview | None,
|
|
1090
|
+
) -> Iterable[repository.CommitDict]:
|
|
1091
|
+
"""The commits of the commits DB from where the touched together DB needs to be updated.
|
|
1092
|
+
|
|
1093
|
+
They are filtered like repository.get_commits does. When the last analyzed commit is among the last TOUCHED_TOGETHER_RECENT_COMMITS commits, the
|
|
1094
|
+
commits start TOUCHED_TOGETHER_RECENT_MARGIN commits before it, so that the revisions sent to
|
|
1095
|
+
update_touched_together which are slightly before it (as commits can be in a different order
|
|
1096
|
+
in mozilla-central and autoland) are found. Otherwise, all the commits are read, which is much
|
|
1097
|
+
slower as the commits DB is very large.
|
|
1098
|
+
"""
|
|
1099
|
+
if last_analyzed is not None:
|
|
1100
|
+
last_analyzed = bytes(last_analyzed)
|
|
1101
|
+
lines = db.read_last_lines(
|
|
1102
|
+
repository.COMMITS_DB, TOUCHED_TOGETHER_RECENT_COMMITS
|
|
1103
|
+
)
|
|
1104
|
+
# Only the commit with the node is deserialized (if the serialization changed, the commit
|
|
1105
|
+
# wouldn't be found, and all the commits would be read).
|
|
1106
|
+
needle = b'"node":"' + last_analyzed + b'"'
|
|
1107
|
+
position = next(
|
|
1108
|
+
(
|
|
1109
|
+
i
|
|
1110
|
+
for i, line in enumerate(lines)
|
|
1111
|
+
if needle in line
|
|
1112
|
+
and orjson.loads(line)["node"] == last_analyzed.decode()
|
|
1113
|
+
),
|
|
1114
|
+
None,
|
|
1115
|
+
)
|
|
1116
|
+
if position is not None and position >= TOUCHED_TOGETHER_RECENT_MARGIN:
|
|
1117
|
+
del lines[: position - TOUCHED_TOGETHER_RECENT_MARGIN]
|
|
1118
|
+
return repository.filter_commits(orjson.loads(line) for line in lines)
|
|
1119
|
+
|
|
1120
|
+
logger.info(
|
|
1121
|
+
"The last analyzed commit is not among the last commits, reading all commits"
|
|
1122
|
+
)
|
|
1123
|
+
|
|
1124
|
+
return repository.get_commits()
|
|
1125
|
+
|
|
1126
|
+
|
|
1082
1127
|
def update_touched_together(
|
|
1083
1128
|
runnable_dirs: Collection[str] = (),
|
|
1084
1129
|
) -> Generator[None, Revision | None, None]:
|
|
@@ -1098,7 +1143,8 @@ def update_touched_together(
|
|
|
1098
1143
|
|
|
1099
1144
|
end_revision = yield
|
|
1100
1145
|
|
|
1101
|
-
|
|
1146
|
+
commits = _get_commits_from(last_analyzed)
|
|
1147
|
+
for commit in commits:
|
|
1102
1148
|
seen.add(commit["node"])
|
|
1103
1149
|
|
|
1104
1150
|
if can_start:
|
|
@@ -226,26 +226,19 @@ class CodeReviewTool(GenerativeModelTool):
|
|
|
226
226
|
async def generate_review_comments(
|
|
227
227
|
self, patch: Patch, patch_summary: str
|
|
228
228
|
) -> tuple[AgentResponse, list[dict]]:
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
review_context_branch = self._review_context_branch
|
|
233
|
-
if review_context_repo is None:
|
|
234
|
-
repo_ref = await patch.github_repo_ref()
|
|
235
|
-
if repo_ref:
|
|
236
|
-
review_context_repo, review_context_branch = repo_ref
|
|
237
|
-
if review_context_repo:
|
|
238
|
-
from bugbug.tools.code_review.review_context import (
|
|
239
|
-
load_external_context_for_review,
|
|
240
|
-
)
|
|
229
|
+
from bugbug.tools.code_review.review_context import (
|
|
230
|
+
resolve_external_context_for_review,
|
|
231
|
+
)
|
|
241
232
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
233
|
+
external_context, manifest = await resolve_external_context_for_review(
|
|
234
|
+
patch,
|
|
235
|
+
self._review_context_repo,
|
|
236
|
+
review_context_branch=(
|
|
237
|
+
self._review_context_branch if self._review_context_repo else None
|
|
238
|
+
),
|
|
239
|
+
extra_context_toml=self._extra_context_toml,
|
|
240
|
+
content_overrides=self._content_overrides,
|
|
241
|
+
)
|
|
249
242
|
|
|
250
243
|
messages = [
|
|
251
244
|
HumanMessage(
|
|
@@ -15,6 +15,7 @@ import hashlib
|
|
|
15
15
|
import json
|
|
16
16
|
import re
|
|
17
17
|
import time
|
|
18
|
+
from collections.abc import Mapping
|
|
18
19
|
from dataclasses import dataclass
|
|
19
20
|
from logging import getLogger
|
|
20
21
|
from typing import Literal
|
|
@@ -34,6 +35,7 @@ from bugbug.tools.code_review.review_context_schema import (
|
|
|
34
35
|
AnyFilePredicate,
|
|
35
36
|
AnyPredicate,
|
|
36
37
|
BugzillaPredicate,
|
|
38
|
+
DiffSide,
|
|
37
39
|
FetchRevisionAction,
|
|
38
40
|
FilePredicate,
|
|
39
41
|
LoadFileAction,
|
|
@@ -138,20 +140,59 @@ def _action_to_dict(action: RuleAction) -> dict:
|
|
|
138
140
|
return {key: value for key, value in action.__dict__.items() if value is not None}
|
|
139
141
|
|
|
140
142
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
+
@dataclass(frozen=True)
|
|
144
|
+
class ChangedFile:
|
|
145
|
+
path: str
|
|
146
|
+
# Lines as they were before the patch (context and removed) and after it
|
|
147
|
+
# (context and added), without line endings. Empty when the diff could not
|
|
148
|
+
# be parsed.
|
|
149
|
+
old_lines: tuple[str, ...] = ()
|
|
150
|
+
new_lines: tuple[str, ...] = ()
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def parse_changed_files(diff: str) -> dict[str, ChangedFile]:
|
|
154
|
+
"""Return the files the diff touches, keyed by path.
|
|
155
|
+
|
|
156
|
+
Removed files are included with only their old lines.
|
|
157
|
+
"""
|
|
143
158
|
try:
|
|
144
|
-
|
|
159
|
+
patch = PatchSet.from_string(diff)
|
|
145
160
|
except Exception:
|
|
146
|
-
|
|
161
|
+
logger.warning("Could not parse diff; file contents will not match rules")
|
|
162
|
+
changed = {}
|
|
147
163
|
for line in diff.splitlines():
|
|
148
164
|
if line.startswith("+++ b/"):
|
|
149
|
-
|
|
150
|
-
|
|
165
|
+
path = line[6:].strip()
|
|
166
|
+
changed[path] = ChangedFile(path=path)
|
|
167
|
+
return changed
|
|
168
|
+
|
|
169
|
+
# Git can emit several entries for one path (e.g. a symlink replaced by a
|
|
170
|
+
# regular file: a deletion, then an addition), so lines are merged by path.
|
|
171
|
+
lines_by_path: dict[str, tuple[list[str], list[str]]] = {}
|
|
172
|
+
for patched_file in patch:
|
|
173
|
+
old_lines, new_lines = lines_by_path.setdefault(patched_file.path, ([], []))
|
|
174
|
+
for hunk in patched_file:
|
|
175
|
+
for line in hunk:
|
|
176
|
+
value = line.value.rstrip("\r\n")
|
|
177
|
+
if line.is_added:
|
|
178
|
+
new_lines.append(value)
|
|
179
|
+
elif line.is_removed:
|
|
180
|
+
old_lines.append(value)
|
|
181
|
+
elif line.is_context:
|
|
182
|
+
old_lines.append(value)
|
|
183
|
+
new_lines.append(value)
|
|
184
|
+
return {
|
|
185
|
+
path: ChangedFile(
|
|
186
|
+
path=path, old_lines=tuple(old_lines), new_lines=tuple(new_lines)
|
|
187
|
+
)
|
|
188
|
+
for path, (old_lines, new_lines) in lines_by_path.items()
|
|
189
|
+
}
|
|
151
190
|
|
|
152
191
|
|
|
153
192
|
def rule_matches(
|
|
154
|
-
rule: Rule,
|
|
193
|
+
rule: Rule,
|
|
194
|
+
changed_files: Mapping[str, ChangedFile],
|
|
195
|
+
bug_component: str | None = None,
|
|
155
196
|
) -> bool:
|
|
156
197
|
return predicate_matches(rule.when, changed_files, bug_component)
|
|
157
198
|
|
|
@@ -163,8 +204,20 @@ def _normalise_path(path: str) -> str:
|
|
|
163
204
|
return path
|
|
164
205
|
|
|
165
206
|
|
|
166
|
-
def
|
|
167
|
-
|
|
207
|
+
def _diff_matches(
|
|
208
|
+
pattern: re.Pattern[str], side: DiffSide | None, changed: ChangedFile
|
|
209
|
+
) -> bool:
|
|
210
|
+
if side == "old":
|
|
211
|
+
lines = changed.old_lines
|
|
212
|
+
elif side == "new":
|
|
213
|
+
lines = changed.new_lines
|
|
214
|
+
else:
|
|
215
|
+
lines = changed.old_lines + changed.new_lines
|
|
216
|
+
return any(pattern.search(line) for line in lines)
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def _file_matches(predicate: FilePredicate, changed: ChangedFile) -> bool:
|
|
220
|
+
path = _normalise_path(changed.path)
|
|
168
221
|
if predicate.include and not any(
|
|
169
222
|
fnmatch.fnmatchcase(path, pattern) for pattern in predicate.include
|
|
170
223
|
):
|
|
@@ -173,7 +226,11 @@ def _file_matches(predicate: FilePredicate, path: str) -> bool:
|
|
|
173
226
|
fnmatch.fnmatchcase(path, pattern) for pattern in predicate.exclude
|
|
174
227
|
):
|
|
175
228
|
return False
|
|
176
|
-
|
|
229
|
+
if predicate.ext and not any(path.endswith(ext) for ext in predicate.ext):
|
|
230
|
+
return False
|
|
231
|
+
if predicate.diff_regex is None:
|
|
232
|
+
return True
|
|
233
|
+
return _diff_matches(predicate.diff_regex, predicate.side, changed)
|
|
177
234
|
|
|
178
235
|
|
|
179
236
|
def _bugzilla_matches(
|
|
@@ -196,7 +253,7 @@ def _patch_matches(predicate: PatchPredicate) -> bool:
|
|
|
196
253
|
|
|
197
254
|
def predicate_matches(
|
|
198
255
|
predicate: Predicate,
|
|
199
|
-
changed_files:
|
|
256
|
+
changed_files: Mapping[str, ChangedFile],
|
|
200
257
|
bug_component: str | None = None,
|
|
201
258
|
) -> bool:
|
|
202
259
|
match predicate:
|
|
@@ -213,10 +270,10 @@ def predicate_matches(
|
|
|
213
270
|
case NotPredicate(child=child):
|
|
214
271
|
return not predicate_matches(child, changed_files, bug_component)
|
|
215
272
|
case AnyFilePredicate(predicate=file_predicate):
|
|
216
|
-
return any(_file_matches(file_predicate, f) for f in changed_files)
|
|
273
|
+
return any(_file_matches(file_predicate, f) for f in changed_files.values())
|
|
217
274
|
case AllFilesPredicate(predicate=file_predicate):
|
|
218
275
|
return bool(changed_files) and all(
|
|
219
|
-
_file_matches(file_predicate, f) for f in changed_files
|
|
276
|
+
_file_matches(file_predicate, f) for f in changed_files.values()
|
|
220
277
|
)
|
|
221
278
|
case BugzillaPredicate():
|
|
222
279
|
return _bugzilla_matches(predicate, bug_component)
|
|
@@ -373,11 +430,11 @@ def collect_actions(
|
|
|
373
430
|
rules=_merge_rules(config.rules, extra_context_toml),
|
|
374
431
|
)
|
|
375
432
|
|
|
376
|
-
changed_files =
|
|
433
|
+
changed_files = parse_changed_files(diff)
|
|
377
434
|
logger.debug(
|
|
378
435
|
"Matching rules against %d changed file(s): %s",
|
|
379
436
|
len(changed_files),
|
|
380
|
-
changed_files,
|
|
437
|
+
sorted(changed_files),
|
|
381
438
|
)
|
|
382
439
|
|
|
383
440
|
actions_by_key: dict[tuple, MatchedAction] = {}
|
|
@@ -569,6 +626,30 @@ def format_external_content(content_items: list[ExternalContentItem]) -> str:
|
|
|
569
626
|
)
|
|
570
627
|
|
|
571
628
|
|
|
629
|
+
async def resolve_external_context_for_review(
|
|
630
|
+
patch,
|
|
631
|
+
review_context_repo: str | None = None,
|
|
632
|
+
review_context_branch: str | None = None,
|
|
633
|
+
extra_context_toml: str | None = None,
|
|
634
|
+
content_overrides: dict[str, str] | None = None,
|
|
635
|
+
) -> tuple[str, list[dict]]:
|
|
636
|
+
"""Resolve the context repository and load matching review context."""
|
|
637
|
+
if review_context_repo is None:
|
|
638
|
+
repo_ref = await patch.github_repo_ref()
|
|
639
|
+
if repo_ref:
|
|
640
|
+
review_context_repo, inferred_branch = repo_ref
|
|
641
|
+
review_context_branch = review_context_branch or inferred_branch
|
|
642
|
+
if not review_context_repo:
|
|
643
|
+
return "", []
|
|
644
|
+
return await load_external_context_for_review(
|
|
645
|
+
patch,
|
|
646
|
+
review_context_repo,
|
|
647
|
+
review_context_branch=review_context_branch or "main",
|
|
648
|
+
extra_context_toml=extra_context_toml,
|
|
649
|
+
content_overrides=content_overrides,
|
|
650
|
+
)
|
|
651
|
+
|
|
652
|
+
|
|
572
653
|
async def load_external_context_for_review(
|
|
573
654
|
patch,
|
|
574
655
|
review_context_repo: str,
|
|
@@ -10,11 +10,12 @@ also be copied into target repositories and used from local tests.
|
|
|
10
10
|
"""
|
|
11
11
|
|
|
12
12
|
import argparse
|
|
13
|
+
import re
|
|
13
14
|
import sys
|
|
14
15
|
from collections.abc import Callable
|
|
15
16
|
from dataclasses import dataclass, field
|
|
16
17
|
from pathlib import Path
|
|
17
|
-
from typing import Literal, TypeAlias
|
|
18
|
+
from typing import Literal, TypeAlias, cast
|
|
18
19
|
|
|
19
20
|
try:
|
|
20
21
|
import tomllib
|
|
@@ -36,11 +37,19 @@ class Policy:
|
|
|
36
37
|
github: GithubPolicy = field(default_factory=GithubPolicy)
|
|
37
38
|
|
|
38
39
|
|
|
40
|
+
DiffSide: TypeAlias = Literal["old", "new", "any"]
|
|
41
|
+
|
|
42
|
+
|
|
39
43
|
@dataclass(frozen=True)
|
|
40
44
|
class FilePredicate:
|
|
41
45
|
include: list[str] = field(default_factory=list)
|
|
42
46
|
exclude: list[str] = field(default_factory=list)
|
|
43
47
|
ext: list[str] = field(default_factory=list)
|
|
48
|
+
# Matches lines of the file's diff on the given side: "old" is before the
|
|
49
|
+
# patch (context and removed lines), "new" after it (context and added
|
|
50
|
+
# lines), "any" either. Set together with diff_regex, never alone.
|
|
51
|
+
diff_regex: re.Pattern[str] | None = None
|
|
52
|
+
side: DiffSide | None = None
|
|
44
53
|
|
|
45
54
|
|
|
46
55
|
@dataclass(frozen=True)
|
|
@@ -230,22 +239,63 @@ def _parse_policy(value: object | None) -> Policy:
|
|
|
230
239
|
return Policy(github=_parse_github_policy(table.get("github", {}), "policy.github"))
|
|
231
240
|
|
|
232
241
|
|
|
242
|
+
_DIFF_SIDES: tuple[str, ...] = ("old", "new", "any")
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def _parse_diff_regex(
|
|
246
|
+
table: dict, path: str
|
|
247
|
+
) -> tuple[re.Pattern[str] | None, DiffSide | None]:
|
|
248
|
+
pattern_text = _optional_string(table.get("diff_regex"), f"{path}.diff_regex")
|
|
249
|
+
side = _optional_string(table.get("side"), f"{path}.side")
|
|
250
|
+
if pattern_text is None:
|
|
251
|
+
if side is not None:
|
|
252
|
+
raise ReviewContextValidationError(f"{path}.side: requires diff_regex")
|
|
253
|
+
return None, None
|
|
254
|
+
if side is None:
|
|
255
|
+
side = "any"
|
|
256
|
+
elif side not in _DIFF_SIDES:
|
|
257
|
+
raise ReviewContextValidationError(
|
|
258
|
+
f"{path}.side: expected one of {', '.join(_DIFF_SIDES)}, got {side!r}"
|
|
259
|
+
)
|
|
260
|
+
try:
|
|
261
|
+
pattern = re.compile(pattern_text)
|
|
262
|
+
except (re.error, OverflowError, RecursionError) as exc:
|
|
263
|
+
# re.compile raises OverflowError for huge repeat counts and
|
|
264
|
+
# RecursionError for deep nesting, not only re.error.
|
|
265
|
+
raise ReviewContextValidationError(
|
|
266
|
+
f"{path}.diff_regex: invalid regex {pattern_text!r}: {exc}"
|
|
267
|
+
) from None
|
|
268
|
+
return pattern, cast(DiffSide, side)
|
|
269
|
+
|
|
270
|
+
|
|
233
271
|
def _parse_file_predicate(value: object, path: str) -> FilePredicate:
|
|
234
272
|
table = _require_table(value, path)
|
|
235
|
-
_reject_unknown_keys(
|
|
273
|
+
_reject_unknown_keys(
|
|
274
|
+
path, table, {"include", "exclude", "ext", "diff_regex", "side", "ref"}
|
|
275
|
+
)
|
|
236
276
|
if "ref" in table:
|
|
237
277
|
if len(table) != 1:
|
|
238
278
|
raise ReviewContextValidationError(
|
|
239
279
|
f"{path}.ref: cannot combine with fields"
|
|
240
280
|
)
|
|
241
281
|
raise ReviewContextValidationError(f"{path}.ref: unresolved ref")
|
|
282
|
+
diff_regex, side = _parse_diff_regex(table, path)
|
|
242
283
|
predicate = FilePredicate(
|
|
243
284
|
include=_string_list(table.get("include"), f"{path}.include"),
|
|
244
285
|
exclude=_string_list(table.get("exclude"), f"{path}.exclude"),
|
|
245
286
|
ext=_string_list(table.get("ext"), f"{path}.ext"),
|
|
287
|
+
diff_regex=diff_regex,
|
|
288
|
+
side=side,
|
|
246
289
|
)
|
|
247
|
-
if
|
|
248
|
-
|
|
290
|
+
if (
|
|
291
|
+
not predicate.include
|
|
292
|
+
and not predicate.exclude
|
|
293
|
+
and not predicate.ext
|
|
294
|
+
and diff_regex is None
|
|
295
|
+
):
|
|
296
|
+
raise ReviewContextValidationError(
|
|
297
|
+
f"{path}: expected include, exclude, ext, or diff_regex"
|
|
298
|
+
)
|
|
249
299
|
return predicate
|
|
250
300
|
|
|
251
301
|
|