Files
kandev/apps/backend/internal/github/provider.go
T
José Almeida 375472cc02 fix(github): stop PR polling for archived tasks (#643)
* fix(github): stop PR polling for archived tasks

The PR watcher kept making GitHub API calls for tasks the user had
archived, wasting rate limit and surfacing stale checks. Hide archived
and orphaned watches from the poller via an INNER JOIN on tasks, and
proactively prune watches when task.updated (archived_at set) or
task.deleted events fire. Closes #989.

* fix(github): address review comments on PR watch pruning

- Detect archived_at from a non-empty string value instead of key
  presence, so a future null/zero archived_at in the task event payload
  doesn't silently prune watches on non-archive updates.
- Track task-event subscriptions on the Service and release them in the
  provider cleanup so handlers don't accumulate if the service is torn
  down and re-created while the event bus persists.
- Propagate RowsAffected errors from DeletePRWatchesByTaskID instead of
  silently discarding them.
2026-04-19 21:49:05 +01:00

41 lines
970 B
Go

package github
import (
"context"
"github.com/jmoiron/sqlx"
"github.com/kandev/kandev/internal/common/logger"
"github.com/kandev/kandev/internal/events/bus"
)
// Provide creates the full GitHub integration stack: store, client, and service.
// Returns the service, a cleanup function, and any error.
func Provide(
writer, reader *sqlx.DB,
secrets SecretProvider,
eventBus bus.EventBus,
log *logger.Logger,
) (*Service, func() error, error) {
store, err := NewStore(writer, reader)
if err != nil {
return nil, nil, err
}
ctx := context.Background()
client, authMethod, err := NewClient(ctx, secrets, log)
if err != nil {
// Not fatal — service works with nil client (unauthenticated).
log.Warn("GitHub client not available: " + err.Error())
}
svc := NewService(client, authMethod, secrets, store, eventBus, log)
svc.subscribeTaskEvents()
cleanup := func() error {
svc.unsubscribeTaskEvents()
return nil
}
return svc, cleanup, nil
}