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-16235-matrix-observation-full-repo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The sentinel's patch observation now names the repository as `owner/name` instead of the configured slug (a bare name once config loading strips the org), so `dashboard.matrix.repos` entries match and the Matrix view receives pushed lines instead of waiting forever; the repo privacy fallback lookup uses the same owner/name ([#16235](https://github.com/hivecommons/hive/issues/16235)).
19 changes: 19 additions & 0 deletions src/pkg/github/sentinel_patch_observer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ func TestSentinelPatchObserverReceivesFetchedFiles(t *testing.T) {
}
}

// Config loading strips the org off every repos entry, so the configured slug
// is a bare name; the observation must still name the repo owner/name, or the
// Matrix allowlist (owner/name entries) never matches (#16235).
func TestSentinelPatchObserverQualifiesBareRepoSlug(t *testing.T) {
f := observerFixture("alice", false)
srv := newSentinelServer(t, f)
defer srv.Close()
c := newTestClient(t, srv, "o", []string{"r"})
var obs observations
opts := defaultSentinelOpts(nil)
opts.PatchObserver = obs.add
if _, err := c.SweepSentinel(context.Background(), opts); err != nil || len(obs.got) != 1 {
t.Fatalf("err=%v obs=%+v", err, obs.got)
}
if o := obs.got[0]; o.Repo != "o/r" || o.Private {
t.Fatalf("observation=%+v, want repo o/r and public", o)
}
}

func TestSentinelPatchObserverPublicRepoNotPrivate(t *testing.T) {
f := observerFixture("alice", false)
srv := newSentinelServer(t, f)
Expand Down
24 changes: 14 additions & 10 deletions src/pkg/github/sentinel_sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,30 +96,34 @@ var sentinelPatchObserverTimeout = 2 * time.Second
// sentinelRepoPrivate reports whether the PR's repository is private. The PR
// payload's base.repo can be absent, which would read as public, so a missing
// one is resolved from the repository record; if that fails, assume private.
func (c *Client) sentinelRepoPrivate(ctx context.Context, displayRepo string, pr *gh.PullRequest) bool {
func (c *Client) sentinelRepoPrivate(ctx context.Context, owner, name string, pr *gh.PullRequest) bool {
if repo := pr.GetBase().GetRepo(); repo != nil && repo.Private != nil {
return repo.GetPrivate()
}
owner, name, ok := strings.Cut(displayRepo, "/")
if !ok || c.client == nil {
if owner == "" || name == "" || c.client == nil {
return true
}
r, _, err := c.client.Repositories.Get(ctx, owner, name)
if err != nil || r == nil || r.Private == nil {
c.logger.Warn("sentinel repo privacy lookup failed; treating as private", "repo", displayRepo)
c.logger.Warn("sentinel repo privacy lookup failed; treating as private", "repo", owner+"/"+name)
return true
}
return r.GetPrivate()
}

func (c *Client) observeSentinelPatch(ctx context.Context, displayRepo string, pr *gh.PullRequest, files []sentinel.File, observe func(SentinelPatchObservation)) {
// observeSentinelPatch hands the fetched patch to the observer. The
// observation names the repository as owner/name, never the configured slug:
// the slug is a bare name once config loading strips the org, and the
// observer's allowlist (dashboard.matrix.repos) holds owner/name entries.
func (c *Client) observeSentinelPatch(ctx context.Context, owner, name string, pr *gh.PullRequest, files []sentinel.File, observe func(SentinelPatchObservation)) {
fullRepo := owner + "/" + name
obs := SentinelPatchObservation{
Repo: displayRepo,
Repo: fullRepo,
Number: pr.GetNumber(),
HeadSHA: pr.GetHead().GetSHA(),
Author: pr.GetUser().GetLogin(),
HiveIdentified: c.knowsOwnAccounts() && c.isHiveAccount(pr.GetUser()),
Private: c.sentinelRepoPrivate(ctx, displayRepo, pr),
Private: c.sentinelRepoPrivate(ctx, owner, name, pr),
Files: append([]sentinel.File(nil), files...),
At: time.Now(),
}
Expand All @@ -128,7 +132,7 @@ func (c *Client) observeSentinelPatch(ctx context.Context, displayRepo string, p
defer close(done)
defer func() {
if r := recover(); r != nil {
c.logger.Warn("sentinel patch observer panicked", "repo", displayRepo, "number", obs.Number, "panic", fmt.Sprint(r))
c.logger.Warn("sentinel patch observer panicked", "repo", fullRepo, "number", obs.Number, "panic", fmt.Sprint(r))
}
}()
observe(obs)
Expand All @@ -138,7 +142,7 @@ func (c *Client) observeSentinelPatch(ctx context.Context, displayRepo string, p
select {
case <-done:
case <-timer.C:
c.logger.Warn("sentinel patch observer exceeded its time bound", "repo", displayRepo, "number", obs.Number)
c.logger.Warn("sentinel patch observer exceeded its time bound", "repo", fullRepo, "number", obs.Number)
}
}

Expand Down Expand Up @@ -502,7 +506,7 @@ func (c *Client) trySentinelPR(ctx context.Context, displayRepo, owner, repo str
return SentinelSweepEvent{}, false, err
}
if opts.PatchObserver != nil {
c.observeSentinelPatch(ctx, displayRepo, pr, files, opts.PatchObserver)
c.observeSentinelPatch(ctx, owner, repo, pr, files, opts.PatchObserver)
}
findings := sentinel.Evaluate(sentinel.PR{Author: author, Title: pr.GetTitle(), Files: files}, opts.Evaluator)
if len(findings) == 0 {
Expand Down
Loading