Skip to content
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
1 change: 1 addition & 0 deletions changelog.d/fixed-disabled-repos-exact-match.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Contribute `hub.disabled_repos` now matches a plain entry against the exact repository name (full or bare, case-insensitive), so disabling `owner/dakota` no longer also disables `owner/dakota-iso`; `*` globs and `/regex/` entries work as before, and the **Repos for contribute** toggles in the dashboard follow the same rule.
33 changes: 33 additions & 0 deletions src/pkg/config/filters.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package config

import "strings"

// MatchesAny returns true if text matches any pattern in the list.
func MatchesAny(text string, patterns []string) bool {
for _, p := range patterns {
Expand All @@ -10,6 +12,37 @@ func MatchesAny(text string, patterns []string) bool {
return false
}

// RepoMatchesAny reports whether a repository, given as its full owner/name
// and its bare name, matches any hub.disabled_repos style pattern. Unlike
// MatchesAny, a plain entry (no "*", not wrapped in /…/) must equal one of
// the two forms exactly, case-insensitively, so disabling "owner/dakota"
// does not also disable "owner/dakota-iso". Globs and /regex/ entries keep
// the WildcardMatch semantics against both forms. Empty entries never match.
//
// One deliberate divergence from WildcardMatch: a lone "/" is NOT treated as
// an empty regex (which would match every repo) but as a plain entry, which
// can never equal a repo name. A stray "/" in disabled_repos must not silently
// disable everything.
func RepoMatchesAny(full, name string, patterns []string) bool {
for _, p := range patterns {
p = strings.TrimSpace(p)
if p == "" {
continue
}
isRegex := len(p) > 1 && strings.HasPrefix(p, "/") && strings.HasSuffix(p, "/")
if isRegex || strings.Contains(p, "*") {
if WildcardMatch(full, p) || WildcardMatch(name, p) {
return true
}
continue
}
if strings.EqualFold(full, p) || strings.EqualFold(name, p) {
return true
}
}
return false
}

// Contribute filter modes for title/author/label gating.
const (
// FilterModeDeny (the default) skips items that MATCH the list; everything
Expand Down
47 changes: 47 additions & 0 deletions src/pkg/config/repo_matches_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package config

import "testing"

func TestRepoMatchesAny(t *testing.T) {
cases := []struct {
name string
full string
bare string
patterns []string
want bool
}{
{"exact full name", "projectbluefin/dakota", "dakota", []string{"projectbluefin/dakota"}, true},
{"exact bare name", "projectbluefin/dakota", "dakota", []string{"dakota"}, true},
{"full entry is a prefix of another repo", "projectbluefin/dakota-iso", "dakota-iso", []string{"projectbluefin/dakota"}, false},
{"bare entry is a prefix of another repo", "projectbluefin/dakota-iso", "dakota-iso", []string{"dakota"}, false},
{"bare entry is a substring of the owner", "projectbluefin/common", "common", []string{"bluefin"}, false},
{"glob matches the prefixed repo", "projectbluefin/dakota-iso", "dakota-iso", []string{"projectbluefin/dakota*"}, true},
{"glob matches the repo itself", "projectbluefin/dakota", "dakota", []string{"projectbluefin/dakota*"}, true},
{"anchored regex matches exactly", "projectbluefin/dakota", "dakota", []string{`/^projectbluefin\/dakota$/`}, true},
{"anchored regex skips the prefixed repo", "projectbluefin/dakota-iso", "dakota-iso", []string{`/^projectbluefin\/dakota$/`}, false},
{"regex against the bare name", "projectbluefin/dakota-iso", "dakota-iso", []string{`/^dakota-/`}, true},
{"invalid regex never matches", "projectbluefin/dakota", "dakota", []string{`/dakota(/`}, false},
{"case-insensitive full name", "projectbluefin/dakota", "dakota", []string{"ProjectBluefin/Dakota"}, true},
{"case-insensitive bare name", "projectbluefin/dakota", "dakota", []string{"DAKOTA"}, true},
{"surrounding whitespace is ignored", "projectbluefin/dakota", "dakota", []string{" projectbluefin/dakota "}, true},
{"empty entry never matches", "projectbluefin/dakota", "dakota", []string{"", " "}, false},
{"lone slash is not an empty regex", "projectbluefin/dakota", "dakota", []string{"/"}, false},
{"later entry matches", "projectbluefin/dakota", "dakota", []string{"other/repo", "dakota"}, true},
{"no patterns", "projectbluefin/dakota", "dakota", nil, false},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := RepoMatchesAny(tc.full, tc.bare, tc.patterns); got != tc.want {
t.Errorf("RepoMatchesAny(%q, %q, %q) = %v, want %v", tc.full, tc.bare, tc.patterns, got, tc.want)
}
})
}
}

// The title, label and author filters keep substring semantics for plain
// entries: only repository matching became exact.
func TestMatchesAnyKeepsSubstringSemantics(t *testing.T) {
if !MatchesAny("projectbluefin/dakota-iso", []string{"projectbluefin/dakota"}) {
t.Error("MatchesAny must keep matching a plain entry as a substring")
}
}
4 changes: 2 additions & 2 deletions src/pkg/dashboard/api_contribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ type contributeRepository struct {

// contributeEligibleRepositories lists the repositories contributors may be
// offered work from: the hub's monitored repositories minus hub.disabled_repos,
// matched with the same MatchesAny rule selectTask applies. The monitored set
// matched with the same RepoMatchesAny rule selectTask applies. The monitored set
// is the status snapshot selection reads; before the first snapshot it is the
// configured project repos, qualified with the org exactly as buildRepos does.
func (s *Server) contributeEligibleRepositories() []contributeRepository {
Expand Down Expand Up @@ -718,7 +718,7 @@ func (s *Server) contributeEligibleRepositories() []contributeRepository {
if full == "" || !strings.Contains(full, "/") {
continue
}
if config.MatchesAny(r.full, disabled) || config.MatchesAny(r.name, disabled) {
if config.RepoMatchesAny(r.full, r.name, disabled) {
continue
}
id := repoScopeID(repoScopeDefaultForge, host, full)
Expand Down
1 change: 1 addition & 0 deletions src/pkg/dashboard/contribute_bugs_rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ func TestGovernorHubReposUseCanonicalDisabledRepoMatching(t *testing.T) {
for _, want := range []string{
"function contribRepoDisabledEntryMatches(repoFull, entry)",
"text = String(text || '').toLowerCase();",
"return full.toLowerCase() === entry || short.toLowerCase() === entry;",
"const enabled = contribRepoMatchingDisabledEntries(r, disabledRepos).length === 0;",
`data-action="toggleContribRepo" data-arg1="' + esc(r.full) + '"`,
"Raw disabled_repos:",
Expand Down
155 changes: 155 additions & 0 deletions src/pkg/dashboard/contribute_disabled_repo_prefix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package dashboard

import (
"os/exec"
"strings"
"testing"
)

// #14707: a disabled_repos entry that is a prefix of another tracked repo's
// name disables only the named repo. dakota-iso keeps serving work while
// dakota is withheld with disabled_repo.
func TestReadyQueue_DisabledRepoPrefixDoesNotDisableLongerName(t *testing.T) {
for _, entry := range []string{"projectbluefin/dakota", "dakota", "ProjectBluefin/Dakota"} {
t.Run(entry, func(t *testing.T) {
hub, s := withheldHub(t, nil)
s.statusMu.Lock()
s.status.Repos = append(s.status.Repos, FrontendRepo{
Name: "dakota-iso",
Full: "projectbluefin/dakota-iso",
ActionableIssues: []any{map[string]any{
"number": float64(800),
"title": "iso work",
"url": "https://github.com/projectbluefin/dakota-iso/issues/800",
"author": "someone",
}},
})
s.statusMu.Unlock()
s.deps.Config.Hub.DisabledRepos = []string{entry}

assertQueue(t, hub, 800)
assertAssigns(t, hub, 800)

snap := hub.admissionQueueSnapshot(readyQueueDefaultLimit, withheldAll)
for _, key := range []string{"projectbluefin/dakota#601", "projectbluefin/dakota#700"} {
item, ok := findWithheld(snap.withheld, key)
if !ok {
t.Fatalf("%s is disabled but unexplained; collected %v", key, snap.withheld)
}
if item.Reason != withheldReasonDisabledRepo {
t.Errorf("%s reason = %q, want %q", key, item.Reason, withheldReasonDisabledRepo)
}
}
if item, ok := findWithheld(snap.withheld, "projectbluefin/dakota-iso#800"); ok {
t.Errorf("dakota-iso#800 must not be withheld, got reason %q", item.Reason)
}
})
}
}

// Execute the shipped Repos-for-contribute matcher and toggle: prefix-sharing
// names get their own state, a regex entry is honoured, and turning dakota-iso
// on keeps the projectbluefin/dakota entry in place.
func TestContribRepoToggleKeepsPrefixSharingEntries(t *testing.T) {
node, err := exec.LookPath("node")
if err != nil {
t.Skip("node unavailable: contribute repo toggle was not executed")
}
html := indexHTML(t)
var source strings.Builder
source.WriteString(`const assert = require('node:assert/strict');
let toasts = [];
let dirty = [];
function showToast(msg) { toasts.push(msg); }
function markDirty(section, key, val) { dirty.push([section, key, val]); }
function renderConfigTab() {}
const _configState = { data: { hub: {} } };
function onEl() { return { classList: { contains: (c) => c === 'on' } }; }
function offEl() { return { classList: { contains: () => false } }; }
`)
for _, name := range []string{
"contribRepoShortName",
"contribRepoWildcardMatch",
"contribRepoIsRegexEntry",
"contribRepoDisabledEntryMatches",
"contribRepoMatchingDisabledEntries",
"toggleContribRepo",
} {
source.WriteString(jsFunc(t, html, name))
source.WriteByte('\n')
}
source.WriteString(`const m = contribRepoDisabledEntryMatches;
assert.equal(m('projectbluefin/dakota', 'projectbluefin/dakota'), true);
assert.equal(m('projectbluefin/dakota-iso', 'projectbluefin/dakota'), false);
assert.equal(m('projectbluefin/dakota', 'dakota'), true);
assert.equal(m('projectbluefin/dakota-iso', 'dakota'), false);
assert.equal(m('projectbluefin/dakota', 'ProjectBluefin/Dakota'), true);
assert.equal(m('projectbluefin/dakota-iso', 'projectbluefin/dakota*'), true);
assert.equal(m('projectbluefin/dakota', '/^projectbluefin\\/dakota$/'), true);
assert.equal(m('projectbluefin/dakota-iso', '/^projectbluefin\\/dakota$/'), false);
assert.equal(m('projectbluefin/dakota', '/dakota(/'), false);
assert.equal(m('projectbluefin/dakota', ''), false);

// Turning dakota-iso on leaves the dakota entry alone.
_configState.data.hub.disabled_repos = ['projectbluefin/dakota', 'projectbluefin/dakota-iso'];
toggleContribRepo(offEl(), 'projectbluefin/dakota-iso');
assert.deepEqual(_configState.data.hub.disabled_repos, ['projectbluefin/dakota']);

// Turning dakota-iso off adds its own entry even though dakota is disabled.
toggleContribRepo(onEl(), 'projectbluefin/dakota-iso');
assert.deepEqual(_configState.data.hub.disabled_repos, ['projectbluefin/dakota', 'projectbluefin/dakota-iso']);

// A regex blocker is reported, not deleted.
_configState.data.hub.disabled_repos = ['/^projectbluefin\\/dakota$/'];
toasts = [];
toggleContribRepo(offEl(), 'projectbluefin/dakota');
assert.deepEqual(_configState.data.hub.disabled_repos, ['/^projectbluefin\\/dakota$/']);
assert.equal(toasts.length, 1);
assert.match(toasts[0], /regex/);
`)
if out, err := exec.Command(node, "-e", source.String()).CombinedOutput(); err != nil {
t.Fatalf("contribute repo toggle failed: %v\n%s", err, out)
}
}

// TestAdminRepoDisabledEntryMatchesExactPlainEntries pins the Contribute
// landing admin page to the same rule as config.RepoMatchesAny, so its
// "Repos for Contribute" toggles cannot disagree with the hub or strip a
// prefix-sharing entry when another repo is enabled.
func TestAdminRepoDisabledEntryMatchesExactPlainEntries(t *testing.T) {
node, err := exec.LookPath("node")
if err != nil {
t.Skip("node unavailable: admin repo matcher was not executed")
}
body := renderContributePage(t)
var source strings.Builder
source.WriteString("const assert = require('node:assert/strict');\n")
for _, name := range []string{
"adminRepoShortName",
"adminRepoWildcardMatch",
"adminRepoIsRegexEntry",
"adminRepoDisabledEntryMatches",
"adminRepoMatchingDisabledEntries",
} {
source.WriteString(jsFunc(t, body, name))
source.WriteByte('\n')
}
source.WriteString(`const m = adminRepoDisabledEntryMatches;
assert.equal(m('projectbluefin/dakota', 'projectbluefin/dakota'), true);
assert.equal(m('projectbluefin/dakota-iso', 'projectbluefin/dakota'), false);
assert.equal(m('projectbluefin/dakota', 'dakota'), true);
assert.equal(m('projectbluefin/dakota-iso', 'dakota'), false);
assert.equal(m('projectbluefin/dakota', 'ProjectBluefin/Dakota'), true);
assert.equal(m('projectbluefin/dakota-iso', 'projectbluefin/dakota*'), true);
assert.equal(m('projectbluefin/dakota', '/^projectbluefin\\/dakota$/'), true);
assert.equal(m('projectbluefin/dakota-iso', '/^projectbluefin\\/dakota$/'), false);
assert.equal(m('projectbluefin/dakota', '/dakota(/'), false);
assert.equal(m('projectbluefin/dakota', ''), false);
assert.deepEqual(
adminRepoMatchingDisabledEntries('projectbluefin/dakota-iso', ['projectbluefin/dakota', 'projectbluefin/dakota-iso']),
['projectbluefin/dakota-iso']);
`)
if out, err := exec.Command(node, "-e", source.String()).CombinedOutput(); err != nil {
t.Fatalf("admin repo matcher failed: %v\n%s", err, out)
}
}
18 changes: 15 additions & 3 deletions src/pkg/dashboard/contribute_landing.go
Original file line number Diff line number Diff line change
Expand Up @@ -4689,11 +4689,23 @@ function adminRepoWildcardMatch(text,pattern){
if(pattern.charAt(pattern.length-1)!=='*'&&last&&text.slice(-last.length)!==last)return false;
return true;
}
function adminRepoIsRegexEntry(entry){
entry=String(entry||'').trim();
return entry.length>1&&entry.charAt(0)==='/'&&entry.charAt(entry.length-1)==='/';
}
// Mirrors config.RepoMatchesAny: a plain entry must equal the full or bare
// name (case-insensitive); * globs and /regex/ entries match either form.
function adminRepoDisabledEntryMatches(repoFull,entry){
var full=String(repoFull||''),short=adminRepoShortName(full);
entry=String(entry||'').trim();
if(!entry)return false;
return adminRepoWildcardMatch(full,entry)||adminRepoWildcardMatch(short,entry);
if(adminRepoIsRegexEntry(entry)){
var re;try{re=new RegExp(entry.slice(1,-1),'i');}catch(e){return false;}
return re.test(full)||re.test(short);
}
if(entry.indexOf('*')>=0)return adminRepoWildcardMatch(full,entry)||adminRepoWildcardMatch(short,entry);
entry=entry.toLowerCase();
return full.toLowerCase()===entry||short.toLowerCase()===entry;
}
function adminRepoMatchingDisabledEntries(repoFull,disabled){
return (disabled||[]).filter(function(entry){return adminRepoDisabledEntryMatches(repoFull,entry);});
Expand Down Expand Up @@ -4944,8 +4956,8 @@ onEl('ops-admin','click',function(e){
var dr=(adminHub.disabled_repos||[]).slice();
var matches=adminRepoMatchingDisabledEntries(repo,dr);
if(matches.length){
var wild=matches.filter(function(r){return String(r||'').indexOf('*')>=0;});
if(wild.length){toast('This repo is disabled by wildcard disabled_repos entry: '+wild.join(', '),false);renderAdminControls();return;}
var wild=matches.filter(function(r){return String(r||'').indexOf('*')>=0||adminRepoIsRegexEntry(r);});
if(wild.length){toast('This repo is disabled by wildcard or regex disabled_repos entry: '+wild.join(', '),false);renderAdminControls();return;}
dr=dr.filter(function(r){return !adminRepoDisabledEntryMatches(repo,r);});
}else{
dr.push(repo);
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/dashboard/contribute_opportunistic.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (h *ContributeWSHub) actionableAgeMinutes() map[string]int {
disabledRepos = h.server.deps.Config.Hub.DisabledRepos
}
for _, repo := range status.Repos {
if config.MatchesAny(repo.Full, disabledRepos) || config.MatchesAny(repo.Name, disabledRepos) {
if config.RepoMatchesAny(repo.Full, repo.Name, disabledRepos) {
continue
}
for _, raw := range repo.ActionableIssues {
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/dashboard/contribute_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ func (h *ContributeWSHub) selectTaskPass(c *ContributorConnection, skippedUnmint
if len(repo.ActionableIssues) == 0 {
continue
}
if config.MatchesAny(repo.Full, disabledRepos) || config.MatchesAny(repo.Name, disabledRepos) {
if config.RepoMatchesAny(repo.Full, repo.Name, disabledRepos) {
continue
}
if !repoScope.allows(repoScopeID(repoScopeDefaultForge, scopeHost, repo.Full)) {
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/dashboard/contribute_sse.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (h *ContributeWSHub) admissionQueueSnapshot(limit int, scope withheldScope)
if len(repo.ActionableIssues) == 0 {
continue
}
if config.MatchesAny(repo.Full, disabledRepos) || config.MatchesAny(repo.Name, disabledRepos) {
if config.RepoMatchesAny(repo.Full, repo.Name, disabledRepos) {
// #6902: a disabled repository refuses all its candidates before
// the per-issue ladder, so explain them here. Skip decoding when
// diagnostics are not being collected.
Expand Down
20 changes: 17 additions & 3 deletions src/pkg/dashboard/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47321,12 +47321,26 @@ <h3>Advisory stats</h3>
return true;
}

function contribRepoIsRegexEntry(entry) {
entry = String(entry || '').trim();
return entry.length > 1 && entry.charAt(0) === '/' && entry.charAt(entry.length - 1) === '/';
}

// Mirrors config.RepoMatchesAny: a plain entry must equal the full or bare
// name (case-insensitive); * globs and /regex/ entries match either form.
function contribRepoDisabledEntryMatches(repoFull, entry) {
const full = String(repoFull || '');
const short = contribRepoShortName(full);
entry = String(entry || '').trim();
if (!entry) return false;
return contribRepoWildcardMatch(full, entry) || contribRepoWildcardMatch(short, entry);
if (contribRepoIsRegexEntry(entry)) {
var re;
try { re = new RegExp(entry.slice(1, -1), 'i'); } catch (e) { return false; }
return re.test(full) || re.test(short);
}
if (entry.indexOf('*') >= 0) return contribRepoWildcardMatch(full, entry) || contribRepoWildcardMatch(short, entry);
entry = entry.toLowerCase();
return full.toLowerCase() === entry || short.toLowerCase() === entry;
}

function contribRepoMatchingDisabledEntries(repoFull, disabled) {
Expand Down Expand Up @@ -47978,9 +47992,9 @@ <h4 class="settings-subsection-title">Hub settings</h4>
if (contribRepoMatchingDisabledEntries(repoFull, disabled).length === 0) disabled.push(repoFull);
} else {
var blockers = contribRepoMatchingDisabledEntries(repoFull, disabled);
var wildcardBlockers = blockers.filter(function(r) { return String(r || '').indexOf('*') >= 0; });
var wildcardBlockers = blockers.filter(function(r) { return String(r || '').indexOf('*') >= 0 || contribRepoIsRegexEntry(r); });
if (wildcardBlockers.length) {
showToast('This repo is disabled by wildcard disabled_repos entry: ' + wildcardBlockers.join(', '), 'error');
showToast('This repo is disabled by wildcard or regex disabled_repos entry: ' + wildcardBlockers.join(', '), 'error');
renderConfigTab('Hub');
return;
}
Expand Down
Loading