Source Control
import { github, gitlab } from "@swenyai/providers/source-control";Interface
Section titled “Interface”interface SourceControlProvider { verifyAccess(): Promise<void>; configureBotIdentity(): Promise<void>; createBranch(name: string): Promise<void>; pushBranch(name: string): Promise<void>; hasChanges(): Promise<boolean>; hasNewCommits(): Promise<boolean>; getChangedFiles(): Promise<string[]>; resetPaths(paths: string[]): Promise<void>; stageAndCommit(message: string): Promise<void>; createPullRequest(opts: PrCreateOptions): Promise<PullRequest>; findExistingPr(searchTerm: string): Promise<PullRequest | null>; dispatchWorkflow(opts: DispatchWorkflowOptions): Promise<void>;}GitHub
Section titled “GitHub”const sc = github({ token: process.env.GITHUB_TOKEN!, owner: "your-org", repo: "your-repo", baseBranch: "main", // optional, defaults to "main" logger: myLogger,});Zero external dependencies. Uses child_process.execFile("git", ...) for local git operations and native fetch for the GitHub API.
Typical triage flow
Section titled “Typical triage flow”// Create a branch for the fixawait sc.createBranch("sweny/fix-webhook-null-pointer-1234");
// ... the agent writes the fix ...
// Check if anything was changedif (await sc.hasChanges()) { await sc.stageAndCommit("fix: add null check for refund webhook payload"); await sc.pushBranch("sweny/fix-webhook-null-pointer-1234");
const pr = await sc.createPullRequest({ title: "Fix null pointer in WebhookHandler for refund webhooks", body: "Closes ENG-456. Adds guard clause for undefined metadata on refund events.", head: "sweny/fix-webhook-null-pointer-1234", base: "main", }); // pr.url → "https://github.com/org/repo/pull/89"}Cross-repo dispatch
Section titled “Cross-repo dispatch”Trigger a workflow in another repository (requires a bot-token with repo and actions scopes):
await sc.dispatchWorkflow({ owner: "your-org", repo: "target-repo", workflow: "sweny-triage.yml", ref: "main", inputs: { service: "payment-api" },});GitLab
Section titled “GitLab”const sc = gitlab({ token: process.env.GITLAB_TOKEN!, projectId: "my-group/my-project", baseUrl: "https://gitlab.com", // optional baseBranch: "main", // optional logger: myLogger,});Uses the GitLab REST API v4. Native fetch only.