gitpay icon indicating copy to clipboard operation
gitpay copied to clipboard

Design an agnostic issue-import & claim-verification architecture (GitLab, Codeberg, KDE Bugzilla, Bitbucket)

Open alexanmtz opened this issue 2 months ago • 6 comments

Why

Three PRs are open adding new issue-import providers: GitLab (#1552, closes #1097), Codeberg (#1551, closes #1150), and KDE Bugzilla (#1553, closes #1098). Each is a solid, focused first step — a src/client/provider/<name>.ts connector, URL parsing, and a taskBuilds.ts/taskFetch.ts case that imports the issue and keeps title/status in sync on fetch.

Reviewing them surfaced two things that block them from being usable end-to-end, plus a structural concern that's about to compound with every new provider we add.

1. Claiming is hardcoded to GitHub only

src/modules/tasks/taskClaim.ts (verifyIssueAndClaim):

if (task.provider !== 'github' || user.provider !== task.provider) {
  throw new Error('invalid_provider')
}
if (task.metadata.issue.user.login !== user.provider_username) {
  throw new Error('user_is_not_the_owner')
}

Any task whose provider isn't 'github' is rejected outright. This already blocks Bitbucket tasks today too — it isn't new to these PRs — but it means a bounty imported from GitLab/Codeberg/KDE can be created and funded, but never claimed or paid out, unless this is fixed. This needs a provider dispatch here, not just in the import path.

2. No identity/connector model exists for these providers

user.provider / provider_id / provider_username are plain scalar columns on Users (src/models/user.ts) — a single active external identity per account, populated reliably only by the GitHub OAuth strategy (src/client/auth/github-strategy.ts). (Bitbucket/Google/Facebook strategies already write to an inconsistent social_id field instead — a pre-existing gap worth folding into this too.)

To verify "the person claiming this bounty is the same person the issue is assigned to on [provider]" for a new provider, we need to stop treating provider/provider_id/provider_username as one slot on Users and instead give each linked external identity its own row:

Proposed structure: a ProviderConnections table

ProviderConnections
  id              PK
  userId          FK -> Users.id
  provider        'github' | 'gitlab' | 'codeberg' | 'kde' | 'bitbucket' | ...
  provider_id     the provider's stable numeric/string user id
  provider_username
  provider_email
  access_token    (nullable — only providers with OAuth have one; encrypted at rest)
  refresh_token   (nullable)
  metadata        jsonb, provider-specific extras (e.g. KDE's Bugzilla login/API key, if that ends up being the only mechanism it supports)
  createdAt / updatedAt
  unique (userId, provider)
  unique (provider, provider_id)

One Users row can then hold many ProviderConnections rows, and — rather than running two parallel systems (the old scalar columns for "the provider I logged in with" plus a new table for "providers I've additionally linked") — login itself should go through the same table. Users holds only the core account (email, name, local password if any); every external identity, including whichever provider a user originally signed up with, is a ProviderConnections row. Concretely:

  • github-strategy.ts (and any future gitlab-strategy.ts, etc.) look up ProviderConnections by (provider, provider_id) to find the userId to log in as, creating both a Users row and the ProviderConnections row on first sign-in — instead of writing provider/provider_id/provider_username directly onto Users the way every strategy does today.
  • A user who first signed up via GitHub can later link GitLab/Codeberg/KDE the same way — just another row in the same table, no "primary provider" flag needed, since session lookup is always by Users.id once resolved.
  • taskClaim.ts's check becomes: look up ProviderConnections for (user.id, task.provider) and compare provider_username against task.metadata.issue.user.login — one code path for every provider, including the one a user logged in with.
  • Users.provider/provider_id/provider_username/provider_email become redundant and can be backfilled into ProviderConnections rows and dropped, rather than kept around as a permanent second system.

This is a real migration for the existing GitHub-login path (every strategy in src/client/auth/ changes how it resolves/creates a User), not just an additive table — worth calling out explicitly as bigger scope, but it avoids building two identity systems that drift apart.

Data migration plan

Existing rows aren't disposable — every current GitHub login (and whatever Bitbucket/Google/Facebook have in social_id) has to keep working through this change. Proposed phasing:

  1. Additive migration: create ProviderConnections (empty), no changes to Users or any strategy yet. Zero risk, fully reversible.
  2. Backfill migration: one-time script that, for every Users row with a non-null provider, inserts a ProviderConnections row from provider/provider_id/provider_username/provider_email. For Bitbucket/Google/Facebook rows (which used social_id instead of these columns), the same script normalizes social_id into the new shape — this is the one place the pre-existing inconsistency has to be resolved, since after this point ProviderConnections is the single source of truth and can't have a second inconsistent shape underneath it. Users columns are untouched (read-only reference, not deleted) so this is trivially re-runnable/verifiable before anything depends on it.
  3. Cut over reads: update each strategy in src/client/auth/ and taskClaim.ts to resolve/verify through ProviderConnections instead of Users.provider*/social_id. Users columns are no longer written by any strategy from this point, but stay in the schema — nothing reads them either, so this step is also reversible by reverting the code change alone (no data was destroyed).
  4. Soak period: run in production with both old columns (frozen, unused) and the new table (live) for a release or two, so any missed read path surfaces as a bug against stale-but-present data rather than a hard failure.
  5. Drop migration: once confident nothing reads the old columns (grep + a production log/metric check for any remaining access), a follow-up migration drops provider/provider_id/provider_username/provider_email/social_id from Users. This is the only step that's actually destructive, and it's deliberately last and separate from the rest.

Each step ships as its own PR/migration, in that order — no step depends on a later one being done, so this can land incrementally rather than as one big-bang change.

This also gives each provider a natural home for whatever non-OAuth verification it ends up needing (e.g. if KDE Bugzilla turns out to only support an API-key-based proof rather than OAuth, that key lives in this same table's metadata/token columns instead of inventing a one-off User column for it).

Whether OAuth (vs. some other identity proof) is even available depends on what each provider's auth model actually supports:

  • GitLab: has standard OAuth2 applications (same shape as GitHub) — a gitlab-strategy.ts should be straightforward.
  • Codeberg: runs Forgejo, which (like Gitea) supports registering OAuth2 applications — likely the same shape as GitHub too, but needs confirming against Codeberg's actual instance config (some Forgejo/Gitea instances restrict third-party OAuth app registration).
  • bugs.kde.org: this is a plain Bugzilla instance. Bugzilla doesn't have a standard third-party OAuth flow the way GitHub/GitLab do — KDE identity is normally handled via KDE Identity (identity.kde.org) SSO for KDE's own properties, and Bugzilla accounts are otherwise keyed by email/API key. It's not yet confirmed whether there's any mechanism a third party like Gitpay could register against to verify "this Gitpay user is this bugs.kde.org reporter/assignee." This needs verification — see the ask in #1098.
  • Bitbucket (already supported for import, not for claim): Bitbucket Cloud does support OAuth2 consumers, so this is likely fixable the same way as GitHub once the dispatch in taskClaim.ts is generalized.

3. The import path itself duplicates ~100-150 lines per provider

taskBuilds.ts and taskFetch.ts are each a single large function with a switch (provider). Every provider (github, bitbucket inlined, and now gitlab/codeberg/kde in the open PRs) adds another near-identical case: fetch issue → sync title/description → (sometimes) sync languages → build/update task → on fetch, diff and write back title/status. src/client/provider/ similarly has no shared interface — each provider ships its own ad hoc XConnect({ uri }) plus one-off URI-builder and state-mapper functions.

None of this is wrong, but every future provider (and any bugfix to the shared logic) touches N copies. Before merging more providers, we'd like to land a shared shape — something like a per-provider registry entry:

{ parseUrl, connector, fetchIssue, mapState, buildMetadata, verifyClaimant }

...that taskBuilds/taskFetch/taskClaim dispatch through by provider key, with GitHub (and Bitbucket, retrofitted) moved onto the same shape. That's what "agnostic" means here: adding a provider becomes "write one registry entry conforming to the interface," not "add a new case to three growing switch statements."

What we're asking for here

Before continuing implementation on #1551 / #1552 / #1553, we'd like to:

  1. Agree on the provider-registry shape above (or an alternative) so all three (four, with a Bitbucket retrofit) land on the same seam instead of three more copy-pasted switch cases.
  2. Get clarity, per provider, on what identity/OAuth mechanism actually exists — GitLab and Codeberg look straightforward, KDE Bugzilla is the open question. If a provider turns out to have no verifiable identity mechanism, import-only (no claim) may be the honest scope for that provider, and that should be explicit rather than silently broken.
  3. Decide the schema approach for multi-provider identity, including the data migration plan above for existing GitHub/Bitbucket/Google/Facebook logins.

4. A second GitHub-only gate: solution/payout verification (TaskSolution)

While scoping this, a related gap surfaced that's separate from taskClaim.ts and not covered above: src/modules/tasks/taskSolutionFetchData.ts / taskSolutionCreate.ts / taskSolutionUpdate.ts. This is the flow where a contributor submits a PR URL, the system verifies (via a direct call to https://api.github.com/repos/.../pulls/{id}) that they authored a merged PR referencing the issue, and — if so — auto-creates the assignment and triggers payout (transferBuilds). It has no provider branching at all; validateGitHubParams hard-enforces GitHub-shaped params.

This is a different check from claiming:

  • Claim (taskClaim.ts) verifies identity ("is this the issue's assignee/reporter?") — no PR required.
  • TaskSolution verifies delivered work via a merged PR/MR — this is the piece that actually depends on a provider having a PR/MR concept at all.

Not every provider has one. GitLab and Codeberg (Forgejo) do, so a real verifySolution could eventually call their merge-request APIs the same way. KDE Bugzilla is a bug tracker with no PR/MR concept — self-service "prove it with a merged PR" can't apply there, full stop.

Rather than hand-listing a required/optional/unsupported value per check for every individual provider — fragile, since e.g. github and gitlab should always require the same checks as each other, but nothing would stop their configs from silently drifting apart — link the checks to a small, reusable verification strategy type instead. Each provider just declares which strategy it implements; the strategy (defined once) owns the actual required-check list:

type VerificationStrategy = 'pull-request' | 'status-only'

const VERIFICATION_STRATEGY_CHECKS: Record<VerificationStrategy, Array<keyof SolutionChecks>> = {
  // any provider with a real PR/MR model: prove it with a merged, referencing PR
  'pull-request': ['isConnectedToProvider', 'isAuthorOfPR', 'isPRMerged', 'isIssueClosed', 'hasIssueReference'],
  // issue-tracker-only providers (no PR/MR concept): the synced issue status is the only signal available
  'status-only': ['isIssueClosed'],
}

interface ProviderConfig {
  provider: string
  verificationStrategy: VerificationStrategy
}

const providerConfigs: ProviderConfig[] = [
  { provider: 'github', verificationStrategy: 'pull-request' },
  { provider: 'gitlab', verificationStrategy: 'pull-request' },
  { provider: 'codeberg', verificationStrategy: 'pull-request' },
  { provider: 'kde', verificationStrategy: 'status-only' },
]

A single generic verifySolution(providerConfig, checkResults) then replaces the hardcoded 5-boolean AND in taskSolutionCreate.ts:24-30: look up the provider's strategy, pull the required-check list from VERIFICATION_STRATEGY_CHECKS, and approve once every check in that list passes. Adding a new provider becomes "pick an existing strategy" (one line) — or, only if it's genuinely a new shape of provider, define one new strategy that every future provider of that shape then reuses — never re-deriving a bespoke per-field matrix by hand. Approval stays fully automatic and config-driven for every provider; the existing funder-triggered manual transfer (src/app/controllers/transfer.ts) remains available as a general override, unchanged, but isn't the load-bearing answer for "how does this work without PRs" anymore.

Extend the registry entry shape proposed above accordingly:

{ parseUrl, connector, fetchIssue, mapState, buildMetadata, verifyClaimant, verificationStrategy? }

Related: #1097 (GitLab), #1098 (KDE Bugzilla), #1150 (Codeberg), #1551, #1552, #1553.

alexanmtz avatar Sep 08 '26 12:09 alexanmtz

I reviewed this against d2c44115e2c65e83886b4b4693c803a5d51b395d. I can take a scoped first milestone, starting with the design agreement you requested.

Three details worth settling before implementation:

  • taskClaim.ts currently compares metadata.issue.user.login and changes the task's userId: this is reporter-based task ownership, not assignee/solver verification. I would model those roles separately so the refactor preserves the intended authorization.
  • Bitbucket supplies social_id, but I could not find that field in the checked-in User model or migration definitions. The backfill needs a read-only schema/data inventory and an explicit missing-ID/relink policy, rather than assuming all historical identities are recoverable.
  • After new identities/signups exist only in ProviderConnections, frozen legacy columns do not make a code-only rollback safe. The cutover needs a compatibility/rollback plan covering writes made after migration.

My proposed first milestone is an agreed provider contract and migration RFC, followed by a GitHub/Bitbucket import-adapter refactor with offline regression tests for URL validation, normalized responses, error behavior, and existing import/fetch compatibility. Database effects and notifications would remain in the task services. This would provide a common interface for the existing provider PRs; new OAuth flows and the live identity migration would be separate work.

Would you fund this first milestone at US$200, payable via PayPal to a contributor in Germany after acceptance and merge? If useful, please confirm the scope and acceptance criteria before I start the implementation.

This is OpenAI Codex assisting @Gohro with authorization; AI assistance and the checks actually run will be disclosed. I have completed source review and a local design draft, but have not implemented the refactor or run its tests. This is a proposal, not a bounty claim.

Gohro avatar Sep 08 '26 14:09 Gohro

For section 4, I recommend keeping issue closure separate from proof of who delivered the work.

I traced this at d2c44115:

  • taskSolutionCreate and taskSolutionUpdate use the five checks before selecting/creating the submitter's assignment and invoking the transfer service.
  • taskSolutionFetchData derives isIssueClosed from synchronized task status. That field does not identify an author or accepted solver.
  • transferBuildsService derives its destination from the assignment and relies on the solution service's prior verification for internal calls.

Replacing the predicate with ['isIssueClosed'] would therefore remove the evidence connecting the submitting user to the work. A duplicate/wontfix closure is another example of closure without an earned reward. This is a concern with the proposed future strategy, not a claim that I demonstrated an unauthorized payment in the deployed app.

Here is the policy prototype I tested:

const pullRequestChecks = Object.freeze([
  'isConnectedToProvider',
  'isAuthorOfPR',
  'isPRMerged',
  'isIssueClosed',
  'hasIssueReference'
])

export function evaluateSolution(strategy, checks) {
  if (strategy === 'import-only') {
    return { status: 'unsupported', reason: 'No automatic solution proof' }
  }
  if (strategy === 'status-only') {
    return { status: 'requires-review', reason: 'Closure does not identify the payee' }
  }
  if (strategy !== 'pull-request') {
    return { status: 'unsupported', reason: 'Unknown verification strategy' }
  }
  const missing = pullRequestChecks.filter((name) => checks?.[name] !== true)
  return missing.length
    ? { status: 'rejected', missing }
    : { status: 'eligible' }
}

Only server-derived evidence belongs in checks. An eligible decision must still be bound to the authenticated user, provider instance and stable user ID, canonical task/work reference, and verification revision before settlement. If fully automatic tracker-only payout is required, it needs an additional verifiable acceptance/recipient signal; closure alone cannot provide that signal.

Also, TaskSolution currently requires pullRequestURL and stores GitHub-specific flags. An import-only/review decision should not fabricate a PR URL just to satisfy that schema.

Validation: 12 standalone Node tests passed for the prototype: a valid PR, each missing proof, an unmerged PR, truthy string evidence, closure-only evidence, import-only, unknown strategy, and absent evidence. These are policy tests; I have not run Gitpay's integration suite or exercised any live payment.

I can take a US$50 PayPal milestone to integrate the shared PR policy into both create/update paths and add the project's regression tests, if this direction is useful. Proposed acceptance: preserve current GitHub success behavior; incomplete evidence produces no new assignment or transfer; both entry points use the same decision; the focused Mocha suite and lint pass. Tracker identity, database migrations, and settlement changes would need their own agreed scope. Please confirm the milestone and reward before implementation.

Prepared with OpenAI Codex assistance for @PlayerBC. No bounty has been agreed or claimed.

PlayerBC avatar Sep 08 '26 14:09 PlayerBC

Hi @alexanmtz, is there budget for a separate regression-test milestone here?

I've read the proposals from @Gohro and @PlayerBC, plus the descriptions of #1551, #1552 and #1553. I don't want to duplicate their implementation work.

Would a US$250 test-only milestone for the new provider connectors be useful once you agree on their interface? The proposed checks would cover URL parsing, issue-state normalization, and malformed/API-error responses using offline fixtures. Registry design, identity migration, and claim/payment policy would stay outside this milestone.

Before starting, could you confirm:

  • Whether this scope is needed and unassigned, with the exact acceptance checks you want.
  • Whether US$250 is funded, who would pay it, and when payment follows acceptance.
  • Whether payment can use PayPal or bank transfer rather than Upwork, including any deductions from the reward.

I'm Aaron, a US-based contributor using an AI coding assistant for investigation, implementation and testing. Please confirm that this disclosed workflow is eligible. I haven't reproduced anything or written code for this milestone, and this inquiry doesn't claim an award.

If the existing contributors already cover these tests, I'll leave that work with them.

cryptiklemur avatar Sep 08 '26 19:09 cryptiklemur

Thanks for digging into this so thoroughly, @Gohro, @PlayerBC, and @cryptiklemur — this is exactly the kind of design scrutiny this issue was asking for, and the depth here (tracing the actual call paths, writing tested prototypes, flagging the reporter-vs-assignee and closure-vs-proof-of-delivery gaps) is genuinely useful regardless of how funding shakes out.

One thing to clear up on payment: Gitpay doesn't arrange or send direct payments (PayPal or otherwise) to contributors outside the platform. Gitpay is a bounty platform — rewards get attached to issues/tasks, and payout happens through Gitpay itself once a bounty is funded and a solution is accepted. To be eligible to receive a payout, you'd create a Gitpay account and activate it for payments; once activated, you can set up PayPal, bank transfer, or crypto as your payout method, and any bounty you're awarded here (or on other projects using Gitpay) pays out through that account rather than as a manually-negotiated side payment.

On the proposals themselves:

  • @Gohro — the provider-contract-and-migration-RFC-first approach matches what this issue is actually asking for in points 1 and 3: agree on the registry shape and the ProviderConnections migration plan before more provider PRs land. The identity-role distinction you raised (taskClaim.ts compares reporter, not assignee/solver) and the "no code-only rollback once new signups only exist in ProviderConnections" point are both real risks worth resolving in the RFC rather than during implementation.
  • @PlayerBC — this is a direct, correct catch on point 4: collapsing the check list to ['isIssueClosed'] would delete the only link between a submitter and the work actually done, and a duplicate/wontfix close would become indistinguishable from a legitimate merge. The VerificationStrategy-driven evaluateSolution shape (with pull-request vs status-only) is close to what the issue sketched, and having it as a shared function both create/update paths call removes the drift risk of two hand-maintained boolean checks.
  • @cryptiklemur — sequencing the regression-test milestone behind the other two makes sense so it tests an agreed interface instead of a moving target; once @Gohro's registry/RFC and @PlayerBC's verification policy are settled, this closes the loop on offline coverage for the new connectors.

Given the sequencing, it looks like the RFC/registry-and-migration piece is the one that unblocks the other two — is anyone here interested in taking that on first, with the PR-verification policy and connector regression tests following once the interface is agreed? Happy to confirm scope/acceptance criteria before anyone starts.

To be upfront: there's no bounty currently attached to #1563 — this is a design/architecture issue, not a funded task. If you're interested in contributing here without a bounty for now, and want to be set up for bounty-funded work in the future (on this or other projects on Gitpay), go ahead and activate your account and payout method — that way you're ready as soon as a bounty is attached here or on future issues.

alexanmtz avatar Sep 17 '26 19:09 alexanmtz

@Charlie-glitch83 to be clear: Gitpay doesn't arrange or send payment outside the platform — that's not an exception we make on a case-by-case basis, it's the core of how Gitpay works. Bounties are funded and paid out through Gitpay itself, so a side arrangement through GitHub alone wouldn't just be against how we operate, it also wouldn't make sense from your side — you'd have no guarantee of payment without the platform actually holding and releasing the funds.

The way it's designed to work: a bounty gets funded on Gitpay against an issue, you do the work and get your PR merged, and then you claim the bounty through your Gitpay account and get paid. That claim-on-merge flow is the guarantee — it's why we don't do it any other way.

We're also building out more ways for contributors to get paid for their contributions beyond the classic bounty-claim flow, so there's more than one path to getting rewarded here over time.

So the path here is to create/activate a Gitpay account at gitpay.me and set up a payout method (we support several — PayPal, bank transfer, crypto, and more). As noted above, there's no bounty currently funded on #1563 itself, but once you're set up you'll be ready for this one if it gets funded, or for other bounties already open on this and other projects on the platform. You'd be very welcome to join us!

alexanmtz avatar Sep 17 '26 19:09 alexanmtz