46021e7d23
PR state was written by two flows and the second one could not persist: the feedback fetch returned live PR data without saving it, and the browser patched its own store copy instead. Opening a PR's detail panel turned that tab purple while the kanban card and boot payload still read state=open, and a reload snapped it back. The backend is now the only writer — the feedback read reconciles through SyncTaskPR and publishes github.task_pr.updated, so every surface converges and the state survives a reload. SyncTaskPR also refuses to move a row out of merged, since GitHub cannot un-merge a PR.
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package github
|
|
|
|
import "context"
|
|
|
|
// ResolveGitHubAutomationClient returns the workspace-owned automation client
|
|
// for non-repository GitHub operations such as Gist-backed task sharing.
|
|
func (s *Service) ResolveGitHubAutomationClient(ctx context.Context, workspaceID string) (Client, error) {
|
|
resolved, err := s.resolveAutomationClient(ctx, workspaceID, "", "")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return resolved.Client, nil
|
|
}
|
|
|
|
func (s *Service) FindPRByBranchForWorkspace(
|
|
ctx context.Context,
|
|
workspaceID, owner, repo, branch string,
|
|
) (*PR, error) {
|
|
if err := s.ensureRepositoryInWorkspaceScope(ctx, workspaceID, owner, repo); err != nil {
|
|
return nil, err
|
|
}
|
|
resolved, err := s.resolveAutomationClient(ctx, workspaceID, owner, repo)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return resolved.Client.FindPRByBranch(ctx, owner, repo, branch)
|
|
}
|
|
|
|
func (s *Service) GetPRFeedbackForAutomation(
|
|
ctx context.Context,
|
|
workspaceID, owner, repo string,
|
|
number int,
|
|
) (*PRFeedback, error) {
|
|
if err := s.ensureRepositoryInWorkspaceScope(ctx, workspaceID, owner, repo); err != nil {
|
|
return nil, err
|
|
}
|
|
resolved, err := s.resolveAutomationClient(ctx, workspaceID, owner, repo)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return s.getPRFeedback(ctx, resolved.Client, resolved.CacheScope, workspaceID, owner, repo, number)
|
|
}
|
|
|
|
func (s *Service) MergePRForAutomation(
|
|
ctx context.Context,
|
|
workspaceID, owner, repo string,
|
|
number int,
|
|
mergeMethod string,
|
|
) error {
|
|
if err := s.ensureRepositoryInWorkspaceScope(ctx, workspaceID, owner, repo); err != nil {
|
|
return err
|
|
}
|
|
resolved, err := s.resolveAutomationClient(ctx, workspaceID, owner, repo)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := requireGitHubCapability(resolved, CapabilityPullRequestWrite); err != nil {
|
|
return err
|
|
}
|
|
return s.mergePRWithClient(
|
|
ctx, resolved.Client, resolved.CacheScope, owner, repo, number, mergeMethod,
|
|
)
|
|
}
|