2a1f7c2edf
* feat: sync workflows from a configured github repo Per-workspace setting pointing at a GitHub repo directory of portable workflow export files. A background poller fetches it on an interval and creates, updates, or deletes the matching workflows; a force-sync endpoint bypasses the content-hash check. Synced workflows carry source/source_path provenance and coexist with manual ones; changes that cannot be applied safely (steps or workflows that still hold tasks, ambiguous step names, unparseable files) surface as warnings in the new settings section. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(web): fill workflow sync form from a pasted github link A new Repository link field parses plain repo URLs, SSH remotes, and tree/blob links (which also carry branch and directory) into the structured owner/repo/branch/path fields. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(web): simplify workflow sync form to link, branch, and interval The repository link is now the only repo input: owner, repo, and directory resolve from the pasted URL (echoed as a summary under the field), and a stored config renders back into a canonical tree link via buildGitHubRepoUrl. Branch and poll interval stay individually editable. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(web): collapse workflow sync into a button, dialog, and status card The Workflows settings page now shows only a GitHub Sync button by default; the link/branch/interval form lives in a dialog that closes on successful save or removal. Once configured, a compact status card (mirroring the GitHub connection-status card) shows the synced repo, branch, directory, last result, warnings, and a Sync now action. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(web): move github sync button into the workflows page header The GitHub Sync trigger now stacks under the Workspace settings button on the top right, and the extra separator around the sync area is gone — unconfigured workspaces show no sync chrome at all, configured ones show just the status card above the workflow list. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(web): move github sync button next to the workflow actions GitHub Sync now sits in the Workflows section toolbar alongside Export All, Import, and Add Workflow; the status card renders inside the section above the workflow list. The toolbar moved to its own component to keep the page under the file-size limit. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(web): separate sync status card from the workflow list Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(web): align sync status card with the workflow list gutter Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix: repair local edits to synced workflows on periodic sync Periodic syncs previously skipped applying when the repo content hash was unchanged, so local UI edits to a synced workflow were only reverted by a manual Sync now. Every sync now reconciles against the repo; the applier compares each step against its definition and only writes (and broadcasts) actual differences, so a no-drift sync stays silent. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat: make github-synced workflows read-only Workflows with source=github reject UI mutations: workflow rename, description, agent-profile, and delete return 409 from the task-domain handlers; step create/update/delete/reorder and template application are guarded in the workflow controller. The sync applier writes through the service/repo layer and stays exempt. The frontend disables the card's inputs, save/delete, and the step pipeline editor for synced workflows, with a tooltip pointing at the synced repository. Drift repair on sync remains as the backstop. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat: optional workflow sync polling and repo-derived branch picker A per-workspace auto-sync toggle (poll_enabled, default on) controls the background polling loop; when off the workspace only syncs via Sync now. The dialog's branch field becomes a select fed by the repository's actual branches (same loader the task-create dialog uses), falling back to free text until branches load. Existing dev databases gain the new column via an idempotent ALTER. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat: release synced workflows when the sync config is removed Deleting a workspace's workflow sync configuration converts its GitHub-sourced workflows back to manual ownership (source=manual), so they become editable instead of being stranded read-only. Release runs before the config row is deleted so a failure keeps the config for retry. The settings page reloads after removal (and after syncs that changed workflows) so cards unlock without a manual refresh. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(web): drop branch selector and compact the auto-sync row The pasted link already carries the branch (main by default), so the dialog no longer needs a branch field — the resolved summary echoes it. The auto-sync toggle is now one compact row with the interval inline and a single short helper line. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix: address PR review feedback Backend: fail-open read-only guard on workflow lookup errors (fixes MCP step handler CI failures); poller Stop holds its mutex through drain; per-workspace lock serializes syncs against config delete/replace; rollback workflow creation when provenance stamping fails; idiomatic duplicate-column migration via db.IsDuplicateColumnError; branch-name validation and a 30-day interval cap; generic 500s with logged detail; WS read-only rejections use CONFLICT with the real reason; e2e reset aborts when sync-config cleanup fails; test hygiene (t.Cleanup, SetMaxOpenConns). Frontend: malformed percent escapes parse as invalid instead of throwing; save disabled during initial load and for invalid intervals; Remove disabled while saving; stale async config responses discarded; delete-dialog confirms re-check read-only; focusable Synced badge; explicit button types; failed polls labeled 'last attempt'; unique warning list keys; test cleanup via afterEach. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix: guard workflow sync test fake against concurrent poller access The poller invokes the fake applier from its own goroutine while the synctest test asserts on call counts; -race caught the unguarded reads. Also documents that the per-workspace lock is deliberately held across the GitHub fetch. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Kandev Agent <agent@kandev.dev> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
127 lines
6.5 KiB
Go
127 lines
6.5 KiB
Go
package github
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// Client defines the interface for interacting with the GitHub API.
|
|
type Client interface {
|
|
// IsAuthenticated checks if the client is authenticated with GitHub.
|
|
IsAuthenticated(ctx context.Context) (bool, error)
|
|
|
|
// GetAuthenticatedUser returns the username of the authenticated user.
|
|
GetAuthenticatedUser(ctx context.Context) (string, error)
|
|
|
|
// GetPR retrieves a single pull request by number.
|
|
GetPR(ctx context.Context, owner, repo string, number int) (*PR, error)
|
|
|
|
// GetIssue retrieves a single GitHub issue by number.
|
|
GetIssue(ctx context.Context, owner, repo string, number int) (*Issue, error)
|
|
|
|
// FindPRByBranch finds an open PR for the given head branch.
|
|
FindPRByBranch(ctx context.Context, owner, repo, branch string) (*PR, error)
|
|
|
|
// ListAuthoredPRs lists open PRs authored by the authenticated user for a repo.
|
|
ListAuthoredPRs(ctx context.Context, owner, repo string) ([]*PR, error)
|
|
|
|
// ListReviewRequestedPRs lists open PRs where the user's review is requested.
|
|
// scope controls the search qualifier: ReviewScopeUser uses user-review-requested:@me,
|
|
// ReviewScopeUserAndTeams (or empty) uses review-requested:@me.
|
|
// filter is an optional additional search qualifier (e.g. "repo:owner/name" or "org:myorg").
|
|
// customQuery, when non-empty, replaces the entire generated query.
|
|
ListReviewRequestedPRs(ctx context.Context, scope, filter, customQuery string) ([]*PR, error)
|
|
|
|
// ListUserOrgs returns the GitHub organizations the authenticated user belongs to.
|
|
ListUserOrgs(ctx context.Context) ([]GitHubOrg, error)
|
|
|
|
// SearchOrgRepos searches repositories in an organization, optionally filtered by a query string.
|
|
SearchOrgRepos(ctx context.Context, org, query string, limit int) ([]GitHubRepo, error)
|
|
|
|
// ListUserRepos lists repositories the authenticated user has access to,
|
|
// optionally filtered by a query string. limit is a per-page upper bound
|
|
// (clamped to GitHub's 100 max by implementations).
|
|
ListUserRepos(ctx context.Context, query string, limit int) ([]GitHubRepo, error)
|
|
|
|
// ListAccessibleRepos lists every repo the authenticated user can access —
|
|
// their own repos plus collaborator and org-member repos — in a single
|
|
// GET /user/repos call on the core REST quota (no per-org search fan-out).
|
|
// query is applied as a case-insensitive substring filter on full_name
|
|
// after fetching; limit bounds the page size (clamped to GitHub's 100 max).
|
|
ListAccessibleRepos(ctx context.Context, query string, limit int) ([]GitHubRepo, error)
|
|
|
|
// ListPRReviews lists reviews on a pull request.
|
|
ListPRReviews(ctx context.Context, owner, repo string, number int) ([]PRReview, error)
|
|
|
|
// ListPRComments lists review comments on a pull request.
|
|
// If since is non-nil, only comments updated after that time are returned.
|
|
ListPRComments(ctx context.Context, owner, repo string, number int, since *time.Time) ([]PRComment, error)
|
|
|
|
// ListCheckRuns lists CI check runs for a given git ref (branch or SHA).
|
|
ListCheckRuns(ctx context.Context, owner, repo, ref string) ([]CheckRun, error)
|
|
|
|
// GetPRFeedback fetches aggregated feedback (reviews, comments, checks) for a PR.
|
|
GetPRFeedback(ctx context.Context, owner, repo string, number int) (*PRFeedback, error)
|
|
|
|
// GetPRStatus fetches lightweight PR status (state, review summary, checks summary).
|
|
// Unlike GetPRFeedback, it skips comments for efficiency.
|
|
GetPRStatus(ctx context.Context, owner, repo string, number int) (*PRStatus, error)
|
|
|
|
// ListPRFiles lists files changed in a pull request.
|
|
ListPRFiles(ctx context.Context, owner, repo string, number int) ([]PRFile, error)
|
|
|
|
// ListPRCommits lists commits in a pull request.
|
|
ListPRCommits(ctx context.Context, owner, repo string, number int) ([]PRCommitInfo, error)
|
|
|
|
// SubmitReview submits a review on a pull request.
|
|
// event is one of "APPROVE", "COMMENT", "REQUEST_CHANGES".
|
|
SubmitReview(ctx context.Context, owner, repo string, number int, event, body string) error
|
|
|
|
// MergePR merges a pull request. mergeMethod is one of "merge", "squash", "rebase".
|
|
MergePR(ctx context.Context, owner, repo string, number int, mergeMethod string) error
|
|
|
|
// ListRepoBranches lists branches for a repository.
|
|
ListRepoBranches(ctx context.Context, owner, repo string) ([]RepoBranch, error)
|
|
|
|
// GetRepoMergeMethods reports which merge methods a repository allows.
|
|
GetRepoMergeMethods(ctx context.Context, owner, repo string) (RepoMergeMethods, error)
|
|
|
|
// ListIssues searches for open issues (not PRs) matching the given query.
|
|
// filter is an optional additional search qualifier (e.g. "repo:owner/name" or "label:bug").
|
|
// customQuery, when non-empty, replaces the entire generated query.
|
|
ListIssues(ctx context.Context, filter, customQuery string) ([]*Issue, error)
|
|
|
|
// SearchPRs searches for PRs matching the given query.
|
|
// filter is an optional additional search qualifier (e.g. "author:@me" or "repo:owner/name").
|
|
// customQuery, when non-empty, replaces the entire generated query.
|
|
SearchPRs(ctx context.Context, filter, customQuery string) ([]*PR, error)
|
|
|
|
// SearchPRsPaged is the paginated variant of SearchPRs. page is 1-indexed;
|
|
// perPage is clamped to GitHub's 1..100 range by the implementation.
|
|
SearchPRsPaged(ctx context.Context, filter, customQuery string, page, perPage int) (*PRSearchPage, error)
|
|
|
|
// ListIssuesPaged is the paginated variant of ListIssues.
|
|
ListIssuesPaged(ctx context.Context, filter, customQuery string, page, perPage int) (*IssueSearchPage, error)
|
|
|
|
// GetIssueState returns the state of a single issue ("open" or "closed").
|
|
GetIssueState(ctx context.Context, owner, repo string, number int) (string, error)
|
|
|
|
// CreateGist creates a new gist on the authenticated user's account.
|
|
// Set Public=false to create a secret (unlisted) gist.
|
|
CreateGist(ctx context.Context, in CreateGistInput) (*GistResponse, error)
|
|
|
|
// DeleteGist deletes a gist by ID. A 404 is wrapped in *GitHubAPIError
|
|
// so callers can distinguish "already gone" from transport failures.
|
|
DeleteGist(ctx context.Context, gistID string) error
|
|
|
|
// ListRepoDirectory lists the entries of a directory in a repository at the
|
|
// given ref (branch, tag, or SHA). dir may be "" or "." for the repo root.
|
|
// A missing directory returns a *GitHubAPIError with status 404.
|
|
ListRepoDirectory(ctx context.Context, owner, repo, dir, ref string) ([]RepoContentEntry, error)
|
|
|
|
// GetRepoFileContent fetches the raw decoded content of a single file in a
|
|
// repository at the given ref. A missing file returns a *GitHubAPIError with
|
|
// status 404.
|
|
GetRepoFileContent(ctx context.Context, owner, repo, path, ref string) ([]byte, error)
|
|
}
|