-
Notifications
You must be signed in to change notification settings - Fork 0
Link task to GitHub Pull Request (Task Detail + MCP update_task) #4
Copy link
Copy link
Open
Description
Task ↔ Pull Request Linking (Task Detail + MCP update_task)
Summary
Add first-class PR linking for tasks from already linked GitHub repositories, available in:
- Task detail panel UI.
- MCP via existing
update_tasktool permission (no new MCP scope).
This will reuse existing task:update authorization and existing external_links storage (externalType = github_pr), with validation against linked repositories and real GitHub PR existence.
Implementation Plan
1. Add shared API contract for PR linking request
Files:
/Users/arnaudjezequel/Documents/dev/flowtask/packages/shared/src/types/task.ts
Changes:
- Add a new schema/type for linking a PR to a task, e.g.
LinkTaskGitHubPrSchemawith:owner: stringrepo: stringprNumber: positive int(coerced)
- Export the corresponding TypeScript type.
- Keep existing
UpdateTaskSchemaunchanged (PR linking remains a dedicated endpoint in REST).
2. Centralize GitHub PR link logic in API service
Files:
/Users/arnaudjezequel/Documents/dev/flowtask/apps/api/src/services/task-github-link-service.ts(new)
Changes:
- Create a small service/helper that:
- Resolves active GitHub integration for a project.
- Verifies the target repo is in integration
config.repositories. - Resolves installation ID for that repo.
- Fetches PR from GitHub (
getPullRequest) to validate and get canonical URL. - Checks duplicates before insert:
- same task + same PR (
ALREADY_LINKED) - same integration + same PR linked elsewhere (
PR_ALREADY_LINKED)
- same task + same PR (
- Inserts
external_linksrow with:externalType: 'github_pr'externalId: prNumber.toString()externalUrl: pullRequest.html_urllastSyncedAt: now
- Return structured domain errors (code + status) for route/MCP error mapping consistency.
3. Add REST endpoint for task detail panel
Files:
/Users/arnaudjezequel/Documents/dev/flowtask/apps/api/src/routes/tasks.ts
Changes:
- Add
POST /api/tasks/:taskId/github-prendpoint using new shared schema. - Authorization: same as update task (
task:update) via existingcheckTaskAccess. - Call the new service helper.
- On success:
- Publish
task:updatedSSE with refreshed task payload. - Return
201with linked PR info (URL + number).
- Publish
- Error codes:
NO_INTEGRATIONREPO_NOT_LINKEDNO_INSTALLATIONALREADY_LINKEDPR_ALREADY_LINKEDGITHUB_ERROR
4. Extend MCP update_task input to support PR linking
Files:
/Users/arnaudjezequel/Documents/dev/flowtask/packages/domain/src/agent/types.ts/Users/arnaudjequel/Documents/dev/flowtask/apps/api/src/routes/mcp.ts/Users/arnaudjequel/Documents/dev/flowtask/apps/api/src/routes/mcp-sse.ts
Changes:
- Extend
AGENT_TOOLSdefinition forupdate_taskwith optional fields:githubPrOwner: stringgithubPrRepo: stringgithubPrNumber: integer
- In both MCP execution paths (
mcp.tsandmcp-sse.ts):- Keep existing
update_taskscope check (no new tool). - Validate PR args are all present together if any is present.
- Reuse the same API helper/service for linking logic.
- Support both:
- link-only call
- combined update + link call
- Return the refreshed task (including updated
externalLinks).
- Keep existing
5. Update task detail panel UI
Files:
/Users/arnaudjezequel/Documents/dev/flowtask/apps/web/src/components/tasks/GitHubLinkSection.tsx
Changes:
- Add a “Link PR” flow in the GitHub section:
- Select linked repo.
- Input PR number.
- Submit to
POST /api/tasks/:taskId/github-pr.
- Keep current “Create issue” flow unchanged.
- Refresh task query after success.
- Show inline error text from API.
- Keep multiple PR links allowed and rendered as today.
Public API / Interface Changes
- New REST endpoint:
POST /api/tasks/:taskId/github-pr
- New shared schema/type in
@flowtask/sharedfor PR-link request payload. - MCP
update_tasktool input adds optional params:githubPrOwnergithubPrRepogithubPrNumber
- No new MCP tool, no new OAuth tool scope, no permission model changes.
Test Cases And Scenarios
API / Auth
- User with
task:updatecan link PR from a linked repo. - User without access gets
403. - Linking with repo not linked to project returns
REPO_NOT_LINKED. - Linking unknown PR number returns
GITHUB_ERROR/not found mapping. - Linking same PR twice on same task returns
ALREADY_LINKED. - Linking PR already linked to another task in same integration returns
PR_ALREADY_LINKED.
MCP
update_taskwith only PR args links successfully and returns task with newgithub_prexternal link.update_taskwith regular fields + PR args updates and links in one call.- Missing one PR arg (
owner/repo/number) fails with validation error. - Token lacking
update_taskscope cannot perform PR linking.
UI
- Task detail panel shows Link PR controls when GitHub repos are linked.
- Successful link appears immediately in PR links list.
- API errors are surfaced in panel.
- Multiple PR links can be added and displayed.
Validation Commands
bun run --filter @flowtask/shared buildbun run --filter @flowtask/domain buildbun run --filter @flowtask/api typecheckbun run --filter @flowtask/web typecheckbun run --filter @flowtask/api buildbun run --filter @flowtask/web build
Assumptions And Defaults
- UI input mode: repository selector + PR number entry.
- A task may have multiple linked PRs.
- MCP uses existing
update_tasktool (extended args), not a new tool. - This scope includes linking only (no unlink/remove PR in this change).
- Existing external ID convention remains (
externalId = PR number as string).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels