Skip to content

Commit ea56f47

Browse files
authored
Add a method for extracting status at a SHA (#1143)
Signed-off-by: Matt Moore <[email protected]>
1 parent d5f8e22 commit ea56f47

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pkg/githubreconciler/statusmanager/statusmanager.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,36 @@ func (s *Session[T]) ObservedState(ctx context.Context) (*Status[T], error) {
163163
return nil, nil // No status found
164164
}
165165

166+
// ObservedStateAtSHA retrieves the status for a specific commit SHA without creating a session.
167+
// This is useful for gathering historical status across multiple commits in a PR.
168+
func (sm *StatusManager[T]) ObservedStateAtSHA(
169+
ctx context.Context,
170+
client *github.Client,
171+
pr *github.PullRequest,
172+
sha string,
173+
) (*Status[T], error) {
174+
owner := pr.GetBase().GetRepo().GetOwner().GetLogin()
175+
repo := pr.GetBase().GetRepo().GetName()
176+
177+
checkRuns, _, err := client.Checks.ListCheckRunsForRef(
178+
ctx, owner, repo, sha,
179+
&github.ListCheckRunsOptions{
180+
CheckName: github.Ptr(sm.identity),
181+
})
182+
183+
if err != nil {
184+
return nil, fmt.Errorf("listing check runs: %w", err)
185+
}
186+
187+
for _, run := range checkRuns.CheckRuns {
188+
if run.GetName() == sm.identity {
189+
return extractStatusFromOutput[T](sm.identity, run.Output)
190+
}
191+
}
192+
193+
return nil, nil
194+
}
195+
166196
// SetActualState updates the state for the current SHA
167197
func (s *Session[T]) SetActualState(ctx context.Context, title string, status *Status[T]) error {
168198
// Ensure ObservedGeneration is set to current SHA

0 commit comments

Comments
 (0)