feat: several Git repositories per project
A project keeps a list of repositories (api, web, admin…), each with its own secret, instead of a single webhook secret. They all call the same URL; the secret that verifies the signature tells which one it was, and every commit, branch or pull request is linked with its repository's name (shown on the ticket and in the MCP). Rotating or removing one leaves the others alone, and what it linked stays. A project that had turned the single webhook on keeps its secret, as a repository named "principal". API: the enable/disable endpoints and mutations give way to adding a repository, rotating its secret and removing it (REST and GraphQL). The web settings card lists the repositories. Docs, Word and PDF updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,11 +2,11 @@ import { Args, ID, Mutation, Query, Resolver } from '@nestjs/graphql';
|
||||
import { User } from '@task-stream/api/identity/domain';
|
||||
import { CurrentUser } from '@task-stream/api/identity/presenters';
|
||||
import { GitService } from '@task-stream/api/tracker/application';
|
||||
import { GitIntegrationGql } from './types';
|
||||
import { GitIntegrationGql, GitRepositoryGql } from './types';
|
||||
|
||||
const webhookPath = (projectId: string) => `/api/webhooks/git/${projectId}`;
|
||||
|
||||
/** The project's Git integration (owners and admins configure it). */
|
||||
/** The project's Git repositories (owners and admins configure them). */
|
||||
@Resolver(() => GitIntegrationGql)
|
||||
export class GitResolver {
|
||||
constructor(private readonly git: GitService) {}
|
||||
@@ -20,24 +20,38 @@ export class GitResolver {
|
||||
return { ...integration, webhookPath: webhookPath(projectId) };
|
||||
}
|
||||
|
||||
@Mutation(() => GitIntegrationGql, {
|
||||
@Mutation(() => GitRepositoryGql, {
|
||||
description:
|
||||
'Turn the Git webhook on, with a new secret (also to rotate it)',
|
||||
'Add a repository with its own secret (the first turns the integration on)',
|
||||
})
|
||||
async enableGitIntegration(
|
||||
addGitRepository(
|
||||
@CurrentUser() me: User,
|
||||
@Args('projectId', { type: () => ID }) projectId: string,
|
||||
@Args('name') name: string,
|
||||
) {
|
||||
const integration = await this.git.enable(me.id, projectId);
|
||||
return { ...integration, webhookPath: webhookPath(projectId) };
|
||||
return this.git.addRepository(me.id, projectId, name);
|
||||
}
|
||||
|
||||
@Mutation(() => Boolean)
|
||||
async disableGitIntegration(
|
||||
@Mutation(() => GitRepositoryGql, {
|
||||
description: 'A new secret for a repository; the old one stops working',
|
||||
})
|
||||
rotateGitRepositorySecret(
|
||||
@CurrentUser() me: User,
|
||||
@Args('projectId', { type: () => ID }) projectId: string,
|
||||
@Args('repositoryId', { type: () => ID }) repositoryId: string,
|
||||
) {
|
||||
await this.git.disable(me.id, projectId);
|
||||
return this.git.rotateSecret(me.id, projectId, repositoryId);
|
||||
}
|
||||
|
||||
@Mutation(() => Boolean, {
|
||||
description: 'Remove a repository; what it linked stays on the tickets',
|
||||
})
|
||||
async removeGitRepository(
|
||||
@CurrentUser() me: User,
|
||||
@Args('projectId', { type: () => ID }) projectId: string,
|
||||
@Args('repositoryId', { type: () => ID }) repositoryId: string,
|
||||
) {
|
||||
await this.git.removeRepository(me.id, projectId, repositoryId);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,23 +170,45 @@ export class DevLinkGql {
|
||||
@Field({ description: 'Short SHA, branch or PR number' }) ref!: string;
|
||||
@Field(() => DevLinkState, { nullable: true }) state!: DevLinkState | null;
|
||||
@Field({ description: 'github, gitea or gitlab' }) provider!: string;
|
||||
@Field(() => String, {
|
||||
nullable: true,
|
||||
description: "The project's name for the repository it came from",
|
||||
})
|
||||
repository!: string | null;
|
||||
@Field(() => String, { nullable: true }) author!: string | null;
|
||||
@Field() at!: string;
|
||||
}
|
||||
|
||||
@ObjectType('GitIntegration', {
|
||||
description:
|
||||
'Webhook from GitHub, Gitea or GitLab: commits, branches and pull requests naming a ticket key are linked to it',
|
||||
@ObjectType('GitRepository', {
|
||||
description: 'A repository whose webhooks the project accepts',
|
||||
})
|
||||
export class GitIntegrationGql {
|
||||
@Field() enabled!: boolean;
|
||||
export class GitRepositoryGql {
|
||||
@Field(() => ID) id!: string;
|
||||
@Field({ description: "The project's name for it: api, web, admin…" })
|
||||
name!: string;
|
||||
@Field(() => String, {
|
||||
nullable: true,
|
||||
description: 'Webhook secret; only owners and admins see it',
|
||||
description:
|
||||
'Webhook secret of this repository; only owners and admins see it',
|
||||
})
|
||||
secret!: string | null;
|
||||
@Field({ description: 'Path of the webhook on this API' })
|
||||
@Field() createdAt!: string;
|
||||
}
|
||||
|
||||
@ObjectType('GitIntegration', {
|
||||
description:
|
||||
'Webhooks from GitHub, Gitea or GitLab: commits, branches and pull requests naming a ticket key are linked to it',
|
||||
})
|
||||
export class GitIntegrationGql {
|
||||
@Field({ description: 'On while there is at least one repository' })
|
||||
enabled!: boolean;
|
||||
@Field({
|
||||
description:
|
||||
'Path of the webhook on this API, the same for every repository',
|
||||
})
|
||||
webhookPath!: string;
|
||||
@Field(() => [GitRepositoryGql])
|
||||
repositories!: GitRepositoryGql[];
|
||||
}
|
||||
|
||||
@ObjectType('AutomationTriggerSpec')
|
||||
|
||||
Reference in New Issue
Block a user