Skip to content
Closed
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
13 changes: 7 additions & 6 deletions gittensor/validator/oss_contributions/mirror/scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@ def check_merged_branch_eligibility(
issue discovery so both reject the same non-acceptable-branch merges.

Returns ``(skip, reason)``. Missing ``default_branch`` falls back to
``main``; missing ``head_ref``/``head_repo_full_name`` skips the head_ref
check rather than false-positive-blocking on older data.
``main``; missing ``base_ref``/``head_ref``/``head_repo_full_name`` skip
their respective checks rather than false-positive-blocking on older data.
"""
additional = repo_config.additional_acceptable_branches or []
acceptable = [default_branch or 'main'] + additional

# base_ref check.
if not branch_matches_pattern(base_ref or '', acceptable):
# base_ref check — skip when absent (pre-backfill mirror data).
if base_ref is not None and not branch_matches_pattern(base_ref, acceptable):
return True, (f'PR #{pr_number} merged to {base_ref!r} not in acceptable branches={acceptable}')

# head_ref check — block PRs whose source branch is itself an acceptable
Expand Down Expand Up @@ -251,8 +251,9 @@ def _should_skip_merged_mirror_pr(scored: ScoredPR, repo_config: RepositoryConfi

When the mirror response is missing a field (older data predating the
schema additions), some checks fall through rather than false-positive-
blocking. Concretely: missing ``head_ref`` or ``head_repo_full_name`` skips
the head_ref check. Missing ``default_branch`` falls back to ``main``.
blocking. Concretely: missing ``base_ref`` skips the base_ref check;
missing ``head_ref`` or ``head_repo_full_name`` skips the head_ref check.
Missing ``default_branch`` falls back to ``main``.
"""
pr = scored.pr

Expand Down
19 changes: 18 additions & 1 deletion tests/validator/oss_contributions/mirror/test_scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _pr(
author_login: str = 'bittoby',
merged_by_login: str | None = 'anderdc',
author_association: str = 'CONTRIBUTOR',
base_ref: str = 'main',
base_ref: str | None = 'main',
head_ref: str | None = 'feature/foo',
head_repo_full_name: str | None = 'entrius/gittensor-ui',
default_branch: str | None = 'main',
Expand Down Expand Up @@ -276,6 +276,23 @@ def test_null_head_ref_skips_check(self):
)
assert skip is False

def test_null_base_ref_skips_check(self):
# Pre-backfill mirror rows omit base_ref; parity with issue discovery.
scored = ScoredPR(
pr=_pr(
base_ref=None,
default_branch='main',
head_ref='feature/foo',
head_repo_full_name='entrius/gittensor-ui',
)
)
skip, reason = _should_skip_merged_mirror_pr(
scored,
_config(additional_branches=['test', 'staging']),
)
assert skip is False
assert reason is None

def test_null_head_repo_full_name_skips_check(self):
# Pre-schema mirror rows may have NULL head_repo_full_name — we can't
# distinguish same-repo from fork, so fall through conservatively.
Expand Down