Files
archie/internal/forge/forge.go
T
sam edd05aea6b feat: add Gitea forge support alongside GitHub
Implements the Forge interface for Gitea instances (tested against
git.catlow.cloud, Gitea v1.26.4). The forge.New factory now dispatches
on forge type, and config validation accepts 'gitea'.

Changes:
- internal/forge/gitea.go — GiteaClient implementing all 11 Forge
  methods: issue polling (assigned + label), comments, PR creation,
  PR state reconciliation, issue closure, reactions, state labels,
  push verification. Handles edge cases: not-found PRs return
  'closed', GetUserByName errors from the Gitea SDK are mapped to
  user-friendly messages.
- internal/forge/forge.go — New() factory dispatching on forge type
  (github/gitea). GitHub constructor renamed to NewGitHub.
- internal/forge/github_test.go — updated to use New() signature
- internal/config/config.go — forge.type accepts 'gitea', BotEmail
  defaults change per forge type (gitea uses @gitea.local)
- cmd/archied/main.go — passes cfg.Forge.Type to forge.New()

Dependencies: added code.gitea.io/sdk/gitea v0.25.1

End-to-end verified against live Gitea instance: daemon starts clean,
registry built (5 workflows), web UI listening, no errors or warnings.
2026-07-22 05:15:09 +10:00

72 lines
2.7 KiB
Go

// Package forge defines the interface archie uses to interact with a git
// host — polling issues, managing labels, opening PRs, and reacting to
// comments. GitHub and Gitea are the supported implementations.
package forge
import (
"context"
"fmt"
"log/slog"
)
// New creates a Forge implementation for the given type.
func New(forgeType, token, host string, log *slog.Logger) (Forge, error) {
switch forgeType {
case "github":
return NewGitHub(token, host, log)
case "gitea":
return NewGitea(token, host, log)
default:
return nil, fmt.Errorf("unsupported forge type %q (want github or gitea)", forgeType)
}
}
// Issue is a forge-neutral representation of an issue (not a PR).
type Issue struct {
Number int
Title string
Body string
Labels []string
}
// Forge is the interface for interacting with a git host.
type Forge interface {
// AcceptInvitations auto-accepts pending repository invitations.
AcceptInvitations(ctx context.Context) error
// AssignedIssues returns open issues assigned to the given user,
// excluding PRs.
AssignedIssues(ctx context.Context, owner, repo, assignee string) ([]Issue, error)
// IssuesWithLabel returns open issues matching the given label,
// excluding PRs. Used when Dispatch.Trigger is "label" or "either".
IssuesWithLabel(ctx context.Context, owner, repo, label string) ([]Issue, error)
// Comment posts an issue (or PR) comment and returns its id.
Comment(ctx context.Context, owner, repo string, number int, body string) (int64, error)
// RepliesAfter returns comments on the issue with id > afterID that
// were not written by exclude.
RepliesAfter(ctx context.Context, owner, repo string, number int, afterID int64, exclude string) ([]Reply, error)
// CreatePR opens a pull request and returns its number.
CreatePR(ctx context.Context, owner, repo, title, head, base, body string) (int, error)
// PRState returns "open", "merged", or "closed" for a PR.
PRState(ctx context.Context, owner, repo string, number int) (string, error)
// CloseIssue closes an issue with an optional final comment.
CloseIssue(ctx context.Context, owner, repo string, number int, comment string) error
// React adds an emoji reaction to an issue.
React(ctx context.Context, owner, repo string, number int, reaction string) error
// SetStateLabel makes label the issue's only state label, removing any
// other label that appears in knownLabels first. An empty label clears
// all state labels (terminal states).
SetStateLabel(ctx context.Context, owner, repo string, number int, label string, knownLabels []string)
// VerifyPush confirms the token can push to the repo.
VerifyPush(ctx context.Context, owner, repo string) error
}