Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: |
Registers a PKCE OAuth method on the `gitlab` integration so browser login works without the external opencode-gitlab-auth plugin. Token storage and refresh scheduling are already owned by core; this supplies the authorize, refresh, and label implementations plus a self-managed instance URL field. The bundled client ID is an instance-owned, trusted application registered for the loopback redirect; GITLAB_OAUTH_CLIENT_ID overrides it for self-managed instances. GitLab matches redirect_uri exactly and also requires it on the refresh grant, so the callback port is fixed and EADDRINUSE reports a clear message. Workflow discovery now prefers the instance an OAuth credential was issued against over ambient defaults.
abea2d3 to
567ec9d
Compare
|
This is an automated review generated by a coding agent. None of these are necessarily blockers; raising them for visibility. We'll look further tomorrow. Branch update: this branch was rebased onto the latest OAuth
Discovery
Tests / minor
|
|
Thanks for the thorough review! Addressed in 27cd0aa and a30dd17 (on top of your rebase): OAuth
Discovery
Tests / minor
|
Issue for this PR
Closes #50421
Type of change
What does this PR do?
Two related changes to the built-in GitLab Duo provider, both in
packages/core/src/plugin/provider/gitlab.ts.1. Restore workflow model discovery (#50421)
Restores the discovery call present in v1 but missing from the v2 GitLab
adapter. It calls
gitlab-ai-provider.discoverWorkflowModels()for the currentdirectory and adds the returned models, token limits, and
workflowRefsettingsto the provider catalog.
Discovery uses the existing credential resolution and refreshes on account
changes. Failures leave static chat models available, and existing model
definitions are preserved. Fetching and project detection remain in the SDK.
2. Add OAuth (PKCE) login
Adds a PKCE OAuth method to the
gitlabintegration, so "Login with GitLab"works out of the box. Until now the only in-core auth methods were the generic
key(personal access token) andenv(GITLAB_TOKEN) methods thatModelsDevPluginderives from the models.dev catalog; the OAuth path requiredthe external
opencode-gitlab-authplugin, which this makes unnecessary.
Core already owns credential storage, refresh scheduling, and merging
instanceUrl/apiKeyinto provider settings. This only supplies the pieces corecannot infer:
authorize,refresh,label, and a self-managed instance URLform field. The implementation follows the existing in-core OAuth providers
(
poe.ts,digitalocean.ts,snowflake-cortex.ts):crypto.subtlefor PKCE, aloopback
node:httplistener,OauthCallbackPagefor the browser response, andHttpClientfor the token exchange.GitLab specifics worth calling out:
redirect_uriexactly, so the listenercannot use an ephemeral port like
poe.tsdoes. It is pinned tohttp://127.0.0.1:8080/callback;EADDRINUSEreports an actionable message(same approach as
digitalocean.ts, which pins 1456).redirect_urion the refresh grant. GitLab requires it there too, unlikemost providers.
invalid_grant. GitLab returns one opaque error for a reused orexpired code, a PKCE verifier mismatch, a redirect-URI mismatch, and a
confidential-client misconfiguration alike, so failures are annotated with the
redirect URI and client ID actually sent (never the code or verifier).
exists on gitlab.com.
GITLAB_OAUTH_CLIENT_IDoverrides it for self-managedinstances, and the docs explain how to register one.
methodIDispkce, matching the credentials the external plugin alreadyissued, so existing logins keep resolving and refreshing.
How the two interact: discovery now prefers the instance an OAuth credential
was issued against over ambient defaults, so a self-managed login discovers
workflow models from the right host rather than
GITLAB_INSTANCE_URL/gitlab.com.3. Bump
gitlab-ai-providerto 6.18.0packages/coregoes from 6.16.0 to 6.18.0 (packages/core/package.jsonandbun.lockonly):cacheKeyfor workflow discovery, which this PR passes (review item 6).VERSIONconstant, which had always reported the previous release in theUser-Agent. The package also no longer bundles a copy of its own tarball.duo-chat-gpt-6-solandduo-chat-gpt-6-lunamappings. Their models.dev entries are in feat: add gitlab duo-chat-gpt-6-sol and duo-chat-gpt-6-luna models models.dev#7868.How did you verify your code works?
packages/core:bun typecheckclean; rootbun run checkpasses (thepre-push hook ran all 35 typecheck tasks successfully).
bun test test/plugin/— 322 pass, 0 fail across 42 files.test/plugin/provider-gitlab.test.ts, 12 tests): PAT/OAuth/environment credentials, registry population, exact ref routing, and account
changes/failures.
test/plugin/provider-gitlab-oauth.test.ts, 15 new tests): methodregistration shape, full authorize -> callback -> exchange against gitlab.com
and a self-managed URL, credential labelling, refresh (asserting
redirect_uriand the stored instance), invalid/denied callbacks, failed exchanges preserving
the previously active connection,
EADDRINUSE, and theGITLAB_OAUTH_CLIENT_IDoverride.GITLAB_TOKEN, and thegitlab-org/gitlabcheckout. The model API and CLIboth listed all 54 discovered workflow models with refs and positive token
limits. That dependency upgrade is tracked separately in chore: bump gitlab-ai-provider to 6.16.0 #50318.
One integration detail the tests surfaced: discovery subscribes to
Credential.Event.Switchedand resolves the credential, so it legitimately racesthe explicit
connection.resolveto refresh the same expired token. The refreshtest asserts on the matching token request rather than on a single queued reply.
Screenshots / recordings
Not a UI change. The new method appears as "Login with GitLab (OAuth)" in the
existing
/connectflow.Checklist