FN-7426: add GitLab lifecycle automation

Add GitLab lifecycle automation for comments and source item state changes.

- Add GitLab REST helpers for posting notes and closing or reopening issues and merge requests.
- Register GitLab source-comment, tracking-comment, tracking-state, and source-close services with multi-project lifecycle wiring.
- Add project settings, documentation, tests, and a changeset for GitLab completion comments and auto-close behavior.

Files changed:
 .changeset/fn-7426-gitlab-lifecycle.md             |  7 ++
 docs/cli-reference.md                              |  2 +-
 docs/dashboard-guide.md                            |  3 +-
 docs/settings-reference.md                         |  5 +-
 packages/core/src/settings-schema.ts               |  3 +
 packages/core/src/types.ts                         | 10 +++
 .../src/__tests__/gitlab-issue-comment.test.ts     | 37 +++++++++
 .../__tests__/gitlab-source-issue-close.test.ts    | 29 +++++++
 .../src/__tests__/gitlab-tracking-comments.test.ts | 31 +++++++
 .../src/__tests__/gitlab-tracking-state.test.ts    | 42 ++++++++++
 packages/dashboard/src/__tests__/gitlab.test.ts    | 18 ++++
 .../register-git-github.gitlab-lifecycle.test.ts   | 54 ++++++++++++
 packages/dashboard/src/gitlab-issue-comment.ts     | 62 ++++++++++++++
 packages/dashboard/src/gitlab-lifecycle.ts         | 58 +++++++++++++
 .../dashboard/src/gitlab-source-issue-close.ts     | 45 ++++++++++
 packages/dashboard/src/gitlab-tracking-comments.ts | 77 +++++++++++++++++
 packages/dashboard/src/gitlab-tracking-state.ts    | 97 ++++++++++++++++++++++
 packages/dashboard/src/gitlab.ts                   | 30 +++++++
 .../dashboard/src/routes/register-git-github.ts    | 23 +++++
 19 files changed, 630 insertions(+), 3 deletions(-)

Fusion-Task-Id: FN-7426

Fusion-Task-Lineage: a46bd11f-96ef-4291-ab41-829007fa057a

Co-authored-by: Fusion (runfusion.ai) <noreply@runfusion.ai>
This commit is contained in:
gsxdsm
2026-07-02 11:13:54 -07:00
parent 91737b1831
commit 34be333a2a
19 changed files with 630 additions and 3 deletions

View File

@@ -649,7 +649,7 @@ Default behavior: PR title/body are AI-generated unless both `--title` and `--bo
`fn task import` creates Fusion tasks from GitHub issues. If project or global GitHub tracking defaults are enabled, imported issue tasks are marked as tracked and the tracking hook links the source issue itself instead of opening a duplicate Fusion tracking issue.
`fn task import-gitlab` creates Fusion tasks from GitLab project issues, group issues, or project merge requests using the configured GitLab instance/API URL and access token (`read_api` or `api` scope). It uses the GitLab HTTP API only (no `glab` dependency), supports GitLab.com and self-managed instances, stores `gitlab_import` provenance plus `gitlabTracking` task metadata for dashboard badges/details, and skips duplicates by source URL/provenance. GitLab comment posting and remote auto-close are not part of this command yet.
`fn task import-gitlab` creates Fusion tasks from GitLab project issues, group issues, or project merge requests using the configured GitLab instance/API URL and access token (`read_api` or `api` scope for import; `api` for later comments/close actions). It uses the GitLab HTTP API only (no `glab` dependency), supports GitLab.com and self-managed instances, stores `gitlab_import` provenance plus `gitlabTracking` task metadata for dashboard badges/details, and skips duplicates by source URL/provenance. Imported GitLab tasks can post lifecycle comments and close/reopen source or tracking targets when project settings enable those side effects; group issues require backing project identity, and Fusion never merges GitLab merge requests.
```bash
fn pr create FN-001

View File

@@ -1083,8 +1083,9 @@ Inspect task definition, logs, review feedback, comments, artifacts, workflow ou
- After delete confirmations are complete, Task Detail closes immediately while the delete request finishes in the background; success and error outcomes still appear as toasts.
- Eligible existing tasks (triage, todo, in-progress, in-review) expose a **GitHub tracking** section directly in Task Detail, even when tracking is currently disabled.
- The GitHub tracking section now defaults to a compact summary row; use the disclosure arrow to expand linked-issue details plus tracking edit controls.
- Tasks linked to GitLab imports show a separate **GitLab tracking** section for GitLab.com and self-managed project issues, group issues, and merge requests. The section provides **Open in GitLab** and local **Unlink GitLab item** actions only; comment posting, remote close/delete, and auto-close behavior are reserved for later GitLab parity work.
- Tasks linked to GitLab imports show a separate **GitLab tracking** section for GitLab.com and self-managed project issues, group issues, and merge requests. The section provides **Open in GitLab** and local **Unlink GitLab item** actions; lifecycle side effects run in the background and appear as task-log entries such as `Posted GitLab tracking comment`, `Closed linked GitLab source issue`, or `Skipped closing GitLab merge request`.
- GitLab stale state means Fusion is displaying the last persisted GitLab metadata after a sync/import refresh could not confirm a newer state; no GitLab token or secret is stored on the task.
- GitLab comment and close/reopen actions use the configured GitLab REST API base URL for GitLab.com or self-managed instances. Group-imported issues are updated only when Fusion has the concrete project identity plus IID, and merge requests are closed/reopened only for GitLab-supported states; Fusion never auto-merges a GitLab merge request.
- Backstop reconciliation runs every 15 minutes to close tracked GitHub issues for soft-deleted and archived tasks even after restart; the sweep is paginated so large archive backlogs are eventually drained.
- In shared task edit/create forms, GitHub Tracking appears at the bottom of **More options**, after **Workflow Steps**.
- From this section you can explicitly enable/disable tracking and manage a per-task repo override (`owner/repo`). Clearing the override saves `null` and falls back to project/global defaults.

View File

@@ -594,11 +594,14 @@ Default notes:
| `gitlabApiBaseUrl` | `string` | `undefined` (effective global fallback, then `<instance>/api/v4`) | Optional project GitLab REST API base URL. Blank/unset inherits global `gitlabApiBaseUrl`; if still unset, Fusion derives `<instance>/api/v4`, preserving self-managed path prefixes. Override only for API gateways with a different absolute HTTP(S) base URL. |
| `gitlabAuthToken` | `string` | `undefined` | Project GitLab access token for later GitLab import/tracking/comment/close HTTP API tasks. Project value takes precedence over global `gitlabAuthToken`, then process `GITLAB_TOKEN`. The dashboard renders the field as a password input and trims values on save; blank clears the project override. Dashboard location: **Settings → Project → Merge → GitLab Authentication**. |
| `gitlabAuthTokenType` | `"personal" \| "project" \| "group"` | `undefined` (effective `"personal"` when a token exists) | Project GitLab token family label. Supported values are personal access token, project access token, and group access token. Select the token family that matches the credential; unsupported values fail auth resolution with `invalid_token_type`. |
| `gitlabCommentOnDone` | `boolean` | `false` | When enabled, tasks imported from GitLab project issues, group-backed issues with project identity, or merge requests post a completion note when the task moves to `done`. Requires a GitLab token with write-capable API access (`api`) to the target project. |
| `gitlabCommentTemplate` | `string` | `undefined` | Optional GitLab source note template used by `gitlabCommentOnDone`. Supports `{taskId}` and `{taskTitle}` placeholders. If unset, Fusion uses the same concise completion message shape as GitHub source comments. |
| `gitlabCloseSourceIssueOnDone` | `boolean` | `false` | When enabled, source-imported GitLab project issues and merge requests close when the Fusion task moves to `done` and reopen when moved out of `done`, where GitLab supports `state_event`. Fusion never merges merge requests; merged MRs and group issues without backing `projectId`/`projectPath` plus IID are skipped with task-log diagnostics. |
| `githubTrackingDedupEnabled` | `boolean` | `true` | When enabled, tracking issue creation searches open and closed repo issues for likely duplicates before opening a new issue (gh CLI search first, with REST search fallback). Set `false` to skip dedup and always create a new issue when tracking is enabled. Dashboard location: **Settings → Project → General → GitHub Tracking**. |
| `githubAuthMode` | `"gh-cli" \| "token"` | `"gh-cli"` | Project GitHub auth strategy used by tracking lifecycle integration. `"gh-cli"` requires an installed/authenticated `gh` CLI. `"token"` requires a non-empty `githubAuthToken` (or `GITHUB_TOKEN` env fallback). Tracking lifecycle auth is strict per selected mode (no cross-fallback). |
| `githubAuthToken` | `string` | `undefined` | Optional project PAT used when `githubAuthMode` is `"token"` (takes precedence over server startup token for tracking flows). |
GitLab configuration examples: leave both URL fields blank for GitLab.com (`https://gitlab.com`, API `https://gitlab.com/api/v4`); set only `gitlabInstanceUrl=https://gitlab.example.com/gitlab` for a self-managed path-prefix install (API derives `https://gitlab.example.com/gitlab/api/v4`); set both URL fields when a self-managed API gateway differs from the web URL. GitLab auth uses access tokens over the GitLab REST API `PRIVATE-TOKEN` header; Fusion does not require or invoke `glab`. Supported token families are [personal access tokens](https://docs.gitlab.com/user/profile/personal_access_tokens/), [project access tokens](https://docs.gitlab.com/user/project/settings/project_access_tokens/), and [group access tokens](https://docs.gitlab.com/user/group/settings/group_access_tokens/). For later read-only GitLab issue/MR import and tracking reads, tokens need `read_api` or `api`; for later write-capable actions such as posting notes/comments and closing issues/MRs, tokens need `api`. Project and group access tokens are constrained to their associated resource and role membership, so the configured token must cover the target project or group. See GitLab REST authentication docs: <https://docs.gitlab.com/api/rest/authentication/>. GitLab issue/MR import, tracking, comments, auto-close, Command Center signals, research/search providers, and star-prompt behavior remain deferred to later GitLab subtasks tracked from [GitLab Parity Inventory](./gitlab-parity-inventory.md).
GitLab configuration examples: leave both URL fields blank for GitLab.com (`https://gitlab.com`, API `https://gitlab.com/api/v4`); set only `gitlabInstanceUrl=https://gitlab.example.com/gitlab` for a self-managed path-prefix install (API derives `https://gitlab.example.com/gitlab/api/v4`); set both URL fields when a self-managed API gateway differs from the web URL. GitLab auth uses access tokens over the GitLab REST API `PRIVATE-TOKEN` header; Fusion does not require or invoke `glab`. Supported token families are [personal access tokens](https://docs.gitlab.com/user/profile/personal_access_tokens/), [project access tokens](https://docs.gitlab.com/user/project/settings/project_access_tokens/), and [group access tokens](https://docs.gitlab.com/user/group/settings/group_access_tokens/). GitLab issue/MR import and tracking reads need `read_api` or `api`; posting notes/comments and closing/reopening issues or MRs need `api`. Project and group access tokens are constrained to their associated resource and role membership, so the configured token must cover the target project or group. Lifecycle actions use the configured API base URL for GitLab.com and self-managed instances, URL-encode project path identifiers, and skip unsupported targets such as terminal merged merge requests or group issues missing concrete project identity. Command Center signals, research/search providers, and star-prompt behavior remain deferred to later GitLab subtasks tracked from [GitLab Parity Inventory](./gitlab-parity-inventory.md).
| `autoCreatePr` | `boolean` | `false` | Auto-create PRs for completed tasks. |
| `autoBackupEnabled` | `boolean` | `false` | Enable scheduled DB backups. |