Files
kandev/apps/backend/internal/gitlab/provider.go
T
2026-06-24 23:02:16 +01:00

47 lines
1.1 KiB
Go

package gitlab
import (
"context"
"fmt"
"github.com/kandev/kandev/internal/common/logger"
)
// Provide builds the GitLab service stack: discovers a host (via the
// optional HostStore, falling back to DefaultHost), resolves the best
// available client, and returns a *Service plus a cleanup function.
//
// secrets is required for PAT-fallback auth; passing nil disables it.
// hostStore is optional — when present, the persisted host is used
// instead of DefaultHost.
func Provide(
ctx context.Context,
secrets SecretProvider,
hostStore HostStore,
log *logger.Logger,
) (*Service, func() error, error) {
host := DefaultHost
if hostStore != nil {
persisted, err := hostStore.GetHost(ctx)
if err != nil {
return nil, nil, fmt.Errorf("load GitLab host: %w", err)
}
if persisted != "" {
host = persisted
}
}
client, authMethod, err := NewClient(ctx, host, secrets, log)
if err != nil {
log.Warn("GitLab client not available: " + err.Error())
}
svc := NewService(host, client, authMethod, secrets, log)
if hostStore != nil {
svc.SetHostStore(hostStore)
}
cleanup := func() error { return nil }
return svc, cleanup, nil
}