@imenam/mcp-dependabot-tracker 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,11 +35,44 @@ export function processAlive(pid) {
35
35
  return err.code === "EPERM";
36
36
  }
37
37
  }
38
- /** Un dépôt enregistré sans branche choisie analyse sa branche par défaut. */
39
- function withBranches(file) {
38
+ /**
39
+ * Complète un fichier écrit par une version antérieure : un dépôt sans branche
40
+ * choisie analyse sa branche par défaut, un dépôt sans catégorie n'est rangé
41
+ * dans aucune, un fichier sans catégories n'en a aucune, un dépôt sans alerte
42
+ * corrigée à la main n'en a aucune. Une alerte sans date
43
+ * d'émission prend celle de la lecture qui l'a rapportée ; la lecture suivante
44
+ * la remplace par la vraie.
45
+ */
46
+ function normalizeReposFile(file) {
40
47
  if (!Array.isArray(file?.repos))
41
48
  return file;
42
- return { ...file, repos: file.repos.map((repo) => (typeof repo?.branch === "string" ? repo : { ...repo, branch: repo?.defaultBranch })) };
49
+ return {
50
+ ...file,
51
+ categories: file.categories ?? [],
52
+ repos: file.repos.map((repo) => ({
53
+ ...repo,
54
+ branch: typeof repo?.branch === "string" ? repo.branch : repo?.defaultBranch,
55
+ categoryId: repo?.categoryId ?? null,
56
+ handledAlerts: repo?.handledAlerts ?? [],
57
+ alerts: Array.isArray(repo?.alerts)
58
+ ? repo.alerts.map((alert) => ({ ...alert, createdAt: alert?.createdAt ?? repo.syncedAt ?? repo.addedAt }))
59
+ : repo?.alerts,
60
+ })),
61
+ };
62
+ }
63
+ function sameName(a, b) {
64
+ return a.trim().toLowerCase() === b.trim().toLowerCase();
65
+ }
66
+ function findCategoryIn(file, categoryId) {
67
+ const category = file.categories.find((candidate) => candidate.id === categoryId);
68
+ if (!category)
69
+ throw new NotFoundError(`Category "${categoryId}" does not exist.`);
70
+ return category;
71
+ }
72
+ function assertNameFree(file, name, exceptId) {
73
+ const taken = file.categories.find((category) => category.id !== exceptId && sameName(category.name, name));
74
+ if (taken)
75
+ throw new ConflictError(`A category named "${taken.name}" already exists.`);
43
76
  }
44
77
  export function isActive(operation) {
45
78
  return ACTIVE_STATUSES.includes(operation.status);
@@ -101,32 +134,32 @@ export class Store {
101
134
  fs.rmSync(this.lockPath, { force: true });
102
135
  }
103
136
  }
104
- // --- Dépôts -----------------------------------------------------------------
105
- readRepos() {
137
+ // --- Dépôts et catégories ----------------------------------------------------
138
+ readReposFile() {
106
139
  let raw;
107
140
  try {
108
141
  raw = fs.readFileSync(this.reposPath, "utf-8");
109
142
  }
110
143
  catch (err) {
111
144
  if (err.code === "ENOENT")
112
- return [];
145
+ return { categories: [], repos: [] };
113
146
  throw err;
114
147
  }
115
- const parsed = ReposFileSchema.safeParse(withBranches(JSON.parse(raw)));
148
+ const parsed = ReposFileSchema.safeParse(normalizeReposFile(JSON.parse(raw)));
116
149
  if (!parsed.success)
117
150
  throw new TrackerError(`${this.reposPath} is invalid: ${parsed.error.message}`);
118
- return parsed.data.repos;
151
+ return parsed.data;
119
152
  }
120
- writeRepos(repos) {
121
- writeJsonAtomic(this.reposPath, ReposFileSchema.parse({ repos }));
153
+ writeReposFile(file) {
154
+ writeJsonAtomic(this.reposPath, ReposFileSchema.parse(file));
122
155
  }
123
156
  listRepos() {
124
- return this.readRepos();
157
+ return this.readReposFile().repos;
125
158
  }
126
159
  /** Dépôt d'identifiant `propriétaire/nom`, sans tenir compte de la casse, comme GitHub. */
127
160
  findRepo(repoId) {
128
161
  const key = repoId.toLowerCase();
129
- return this.readRepos().find((repo) => repo.id.toLowerCase() === key) ?? null;
162
+ return this.listRepos().find((repo) => repo.id.toLowerCase() === key) ?? null;
130
163
  }
131
164
  getRepo(repoId) {
132
165
  const repo = this.findRepo(repoId);
@@ -134,33 +167,40 @@ export class Store {
134
167
  throw new NotFoundError(`Repository "${repoId}" is not tracked. Use list_repositories to see the tracked repositories.`);
135
168
  return repo;
136
169
  }
170
+ /** Ajoute un dépôt ; sa catégorie, s'il en a une, doit exister. */
137
171
  addRepo(repo) {
138
172
  return this.withLock(() => {
139
- const repos = this.readRepos();
140
- if (repos.some((existing) => existing.id.toLowerCase() === repo.id.toLowerCase())) {
173
+ const file = this.readReposFile();
174
+ if (file.repos.some((existing) => existing.id.toLowerCase() === repo.id.toLowerCase())) {
141
175
  throw new ConflictError(`Repository ${repo.id} is already tracked.`);
142
176
  }
143
- this.writeRepos([...repos, repo]);
177
+ if (repo.categoryId !== null)
178
+ findCategoryIn(file, repo.categoryId);
179
+ this.writeReposFile({ ...file, repos: [...file.repos, repo] });
144
180
  return repo;
145
181
  });
146
182
  }
183
+ /** Modifie un dépôt ; une catégorie qui lui est attribuée doit exister. */
147
184
  updateRepo(repoId, fn) {
148
185
  return this.withLock(() => {
149
- const repos = this.readRepos();
150
- const index = repos.findIndex((repo) => repo.id.toLowerCase() === repoId.toLowerCase());
186
+ const file = this.readReposFile();
187
+ const index = file.repos.findIndex((repo) => repo.id.toLowerCase() === repoId.toLowerCase());
151
188
  if (index === -1)
152
189
  throw new NotFoundError(`Repository "${repoId}" is not tracked.`);
153
- const updated = fn(repos[index]);
190
+ const updated = fn(file.repos[index]);
191
+ if (updated.categoryId !== null)
192
+ findCategoryIn(file, updated.categoryId);
193
+ const repos = [...file.repos];
154
194
  repos[index] = updated;
155
- this.writeRepos(repos);
195
+ this.writeReposFile({ ...file, repos });
156
196
  return updated;
157
197
  });
158
198
  }
159
199
  /** Retire un dépôt et ses opérations ; refusé pendant une opération en cours. */
160
200
  removeRepo(repoId) {
161
201
  this.withLock(() => {
162
- const repos = this.readRepos();
163
- const repo = repos.find((candidate) => candidate.id.toLowerCase() === repoId.toLowerCase());
202
+ const file = this.readReposFile();
203
+ const repo = file.repos.find((candidate) => candidate.id.toLowerCase() === repoId.toLowerCase());
164
204
  if (!repo)
165
205
  throw new NotFoundError(`Repository "${repoId}" is not tracked.`);
166
206
  const operations = this.readOperationsOf(repo.id);
@@ -168,7 +208,45 @@ export class Store {
168
208
  throw new ConflictError(`An operation is in progress on ${repo.id}: cancel it before removing the repository.`);
169
209
  for (const operation of operations)
170
210
  fs.rmSync(this.operationPath(operation.id), { force: true });
171
- this.writeRepos(repos.filter((candidate) => candidate !== repo));
211
+ this.writeReposFile({ ...file, repos: file.repos.filter((candidate) => candidate !== repo) });
212
+ });
213
+ }
214
+ /** Catégories dans l'ordre alphabétique. */
215
+ listCategories() {
216
+ return [...this.readReposFile().categories].sort((a, b) => a.name.localeCompare(b.name, "fr", { sensitivity: "base" }));
217
+ }
218
+ getCategory(categoryId) {
219
+ return findCategoryIn(this.readReposFile(), categoryId);
220
+ }
221
+ /** Crée une catégorie ; deux catégories ne portent pas le même nom, sans tenir compte de la casse. */
222
+ createCategory(name) {
223
+ return this.withLock(() => {
224
+ const file = this.readReposFile();
225
+ assertNameFree(file, name, null);
226
+ const category = { id: crypto.randomBytes(6).toString("hex"), name: name.trim() };
227
+ this.writeReposFile({ ...file, categories: [...file.categories, category] });
228
+ return category;
229
+ });
230
+ }
231
+ renameCategory(categoryId, name) {
232
+ return this.withLock(() => {
233
+ const file = this.readReposFile();
234
+ findCategoryIn(file, categoryId);
235
+ assertNameFree(file, name, categoryId);
236
+ const renamed = { id: categoryId, name: name.trim() };
237
+ this.writeReposFile({ ...file, categories: file.categories.map((category) => (category.id === categoryId ? renamed : category)) });
238
+ return renamed;
239
+ });
240
+ }
241
+ /** Supprime une catégorie ; ses dépôts restent suivis, sans catégorie. */
242
+ deleteCategory(categoryId) {
243
+ this.withLock(() => {
244
+ const file = this.readReposFile();
245
+ findCategoryIn(file, categoryId);
246
+ this.writeReposFile({
247
+ categories: file.categories.filter((category) => category.id !== categoryId),
248
+ repos: file.repos.map((repo) => (repo.categoryId === categoryId ? { ...repo, categoryId: null } : repo)),
249
+ });
172
250
  });
173
251
  }
174
252
  // --- Opérations ---------------------------------------------------------------
@@ -6,7 +6,7 @@ import path from "path";
6
6
  import fs from "fs";
7
7
  import { fileURLToPath } from "url";
8
8
  import { IPCMessageSchema } from "../shared/schemas/ipc.schema.js";
9
- import { AddRepoBodySchema, ForceBodySchema, PushBodySchema, SetBranchBodySchema, SetRightsBodySchema } from "../shared/schemas/api.schema.js";
9
+ import { AddRepoBodySchema, CategoryBodySchema, ForceBodySchema, PushBodySchema, SetBranchBodySchema, SetCategoryBodySchema, SetRightsBodySchema } from "../shared/schemas/api.schema.js";
10
10
  import { resolveLogDir } from "./core/log-dir.js";
11
11
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
12
12
  function findProjectRoot(startDir) {
@@ -211,6 +211,28 @@ app.put("/api/repos/:owner/:name/branch", async (c) => {
211
211
  return read.response;
212
212
  return forward(c, "SET_BRANCH", { repoId: repoId(c), body: read.body });
213
213
  });
214
+ app.put("/api/repos/:owner/:name/category", async (c) => {
215
+ const read = await readBody(c, SetCategoryBodySchema);
216
+ if ("response" in read)
217
+ return read.response;
218
+ return forward(c, "SET_CATEGORY", { repoId: repoId(c), body: read.body });
219
+ });
220
+ app.put("/api/repos/:owner/:name/alerts/:number/handled", (c) => forward(c, "MARK_ALERT_HANDLED", { repoId: repoId(c), number: c.req.param("number") }));
221
+ app.delete("/api/repos/:owner/:name/alerts/:number/handled", (c) => forward(c, "UNMARK_ALERT_HANDLED", { repoId: repoId(c), number: c.req.param("number") }));
222
+ app.get("/api/categories", (c) => forward(c, "LIST_CATEGORIES"));
223
+ app.post("/api/categories", async (c) => {
224
+ const read = await readBody(c, CategoryBodySchema);
225
+ if ("response" in read)
226
+ return read.response;
227
+ return forward(c, "CREATE_CATEGORY", { body: read.body });
228
+ });
229
+ app.put("/api/categories/:id", async (c) => {
230
+ const read = await readBody(c, CategoryBodySchema);
231
+ if ("response" in read)
232
+ return read.response;
233
+ return forward(c, "RENAME_CATEGORY", { categoryId: c.req.param("id"), body: read.body });
234
+ });
235
+ app.delete("/api/categories/:id", (c) => forward(c, "DELETE_CATEGORY", { categoryId: c.req.param("id") }));
214
236
  app.post("/api/repos/:owner/:name/operations", (c) => forward(c, "START_FIX", { repoId: repoId(c) }));
215
237
  app.get("/api/operations/:id", (c) => forward(c, "GET_OPERATION", { operationId: c.req.param("id") }));
216
238
  app.post("/api/operations/:id/force", async (c) => {
package/dist/src/index.js CHANGED
@@ -14,9 +14,9 @@ import { githubConfigured, readGitHubConfig } from "./core/config.js";
14
14
  import { ConflictError, NotFoundError, TrackerError } from "./core/errors.js";
15
15
  import { Store } from "./core/store.js";
16
16
  import { cancelOperation, decideForce, pushOperation, startUserFix } from "./core/operations.js";
17
- import { SYNC_INTERVAL_MS, addRepository, listAddableRepositories, listRepoBranches, listRepoViews, setBranch, repoView, setRights, staleRepos, syncRepository } from "./core/repos.js";
17
+ import { SYNC_INTERVAL_MS, addRepository, listAddableRepositories, listRepoBranches, listRepoViews, markAlertHandled, setBranch, setCategory, repoView, setRights, staleRepos, syncRepository, unmarkAlertHandled } from "./core/repos.js";
18
18
  import { GUI_REQUEST_TYPES, IPCMessageSchema } from "../shared/schemas/ipc.schema.js";
19
- import { AddRepoBodySchema, ForceBodySchema, OperationRequestSchema, PushBodySchema, RepoRequestSchema, SetBranchBodySchema, SetRightsBodySchema, } from "../shared/schemas/api.schema.js";
19
+ import { AddRepoBodySchema, AlertRequestSchema, CategoryBodySchema, CategoryRequestSchema, ForceBodySchema, OperationRequestSchema, PushBodySchema, RepoRequestSchema, SetBranchBodySchema, SetCategoryBodySchema, SetRightsBodySchema, } from "../shared/schemas/api.schema.js";
20
20
  import { errorResult, textResult } from "./tools/types.js";
21
21
  import { fixVulnerabilities, getAlerts, listRepositories, runAudit } from "./tools/tools.js";
22
22
  const __filename = fileURLToPath(import.meta.url);
@@ -131,7 +131,7 @@ async function handleGuiRequest(msg) {
131
131
  case "GET_CONFIG":
132
132
  return { version: APP_VERSION, dataDir, githubConfigured: githubConfigured() };
133
133
  case "LIST_REPOS":
134
- return { repos: listRepoViews(store) };
134
+ return { repos: listRepoViews(store), categories: store.listCategories() };
135
135
  case "LIST_ADDABLE_REPOS":
136
136
  return { repositories: await listAddableRepositories(store, readGitHubConfig()) };
137
137
  case "GET_REPO": {
@@ -140,7 +140,7 @@ async function handleGuiRequest(msg) {
140
140
  }
141
141
  case "ADD_REPO": {
142
142
  const body = parseRequest(AddRepoBodySchema, msg.data?.body);
143
- return repoView(store, await addRepository(store, readGitHubConfig(), body.repository));
143
+ return repoView(store, await addRepository(store, readGitHubConfig(), body.repository, body.categoryId));
144
144
  }
145
145
  case "REMOVE_REPO":
146
146
  store.removeRepo(parseRequest(RepoRequestSchema, msg.data).repoId);
@@ -159,6 +159,30 @@ async function handleGuiRequest(msg) {
159
159
  const body = parseRequest(SetBranchBodySchema, msg.data?.body);
160
160
  return repoView(store, await setBranch(store, readGitHubConfig(), repoId, body.branch));
161
161
  }
162
+ case "SET_CATEGORY": {
163
+ const { repoId } = parseRequest(RepoRequestSchema, msg.data);
164
+ const body = parseRequest(SetCategoryBodySchema, msg.data?.body);
165
+ return repoView(store, setCategory(store, repoId, body.categoryId));
166
+ }
167
+ case "MARK_ALERT_HANDLED": {
168
+ const { repoId, number } = parseRequest(AlertRequestSchema, msg.data);
169
+ return repoView(store, markAlertHandled(store, repoId, number));
170
+ }
171
+ case "UNMARK_ALERT_HANDLED": {
172
+ const { repoId, number } = parseRequest(AlertRequestSchema, msg.data);
173
+ return repoView(store, unmarkAlertHandled(store, repoId, number));
174
+ }
175
+ case "LIST_CATEGORIES":
176
+ return { categories: store.listCategories() };
177
+ case "CREATE_CATEGORY":
178
+ return store.createCategory(parseRequest(CategoryBodySchema, msg.data?.body).name);
179
+ case "RENAME_CATEGORY": {
180
+ const { categoryId } = parseRequest(CategoryRequestSchema, msg.data);
181
+ return store.renameCategory(categoryId, parseRequest(CategoryBodySchema, msg.data?.body).name);
182
+ }
183
+ case "DELETE_CATEGORY":
184
+ store.deleteCategory(parseRequest(CategoryRequestSchema, msg.data).categoryId);
185
+ return { deleted: true };
162
186
  case "START_FIX":
163
187
  return { operation: startUserFix(operations, parseRequest(RepoRequestSchema, msg.data).repoId) };
164
188
  case "GET_OPERATION": {
@@ -276,8 +300,11 @@ const REPOSITORY_DOC = "Tracked repository, as owner/name (see list_repositories
276
300
  const TOOLS = [
277
301
  {
278
302
  name: "list_repositories",
279
- description: "List the tracked repositories with their analysed branch, their open Dependabot alerts by severity, the time of the last sync, the rights the user gave you (audit, fix, force, push) and the operation in progress. Start here.",
280
- inputSchema: { type: "object", properties: {} },
303
+ description: "List the tracked repositories with their category, their analysed branch, their open Dependabot alerts by severity, the time of the last sync, the rights the user gave you (audit, fix, force, push) and the operation in progress. Start here.",
304
+ inputSchema: {
305
+ type: "object",
306
+ properties: { category: { type: "string", description: "Only list the repositories of this category, by name (case-insensitive). The user creates the categories in the GUI." } },
307
+ },
281
308
  },
282
309
  {
283
310
  name: "get_alerts",
@@ -1,7 +1,8 @@
1
- import { type Operation, type Repo } from "../../shared/schemas/model.schema.js";
1
+ import { type Category, type Operation, type Repo } from "../../shared/schemas/model.schema.js";
2
2
  import type { RepoView } from "../../shared/schemas/api.schema.js";
3
3
  export declare function rightsLabel(repo: Repo): string;
4
- export declare function describeRepo(view: RepoView): string;
4
+ /** Description d'un dépôt pour l'agent ; `category` est la catégorie où l'utilisateur l'a rangé. */
5
+ export declare function describeRepo(view: RepoView, category: Category | null): string;
5
6
  export declare function describeAlerts(repo: Repo): string;
6
7
  /** Compte rendu d'une opération pour l'agent : étapes, vulnérabilités, paquets modifiés, PR, erreur. */
7
8
  export declare function describeOperation(operation: Operation): string;
@@ -1,4 +1,5 @@
1
1
  import { ALERT_SEVERITIES, RIGHTS } from "../../shared/schemas/model.schema.js";
2
+ import { pendingAlerts } from "../../shared/alerts.js";
2
3
  import { projectLabel } from "../core/npm-audit.js";
3
4
  import { countBySeverity } from "../core/repos.js";
4
5
  /** Paquets cités en clair dans un résultat ; au-delà, le reste est compté. */
@@ -7,21 +8,32 @@ export function rightsLabel(repo) {
7
8
  const allowed = RIGHTS.filter((right) => repo.rights[right]);
8
9
  return allowed.length === 0 ? "none" : allowed.join(", ");
9
10
  }
11
+ /** Alertes restantes par gravité, et le nombre de celles que l'utilisateur a corrigées à la main. */
10
12
  function alertsLabel(repo) {
11
- if (repo.alerts.length === 0)
12
- return "none";
13
- const counts = countBySeverity(repo.alerts);
13
+ const pending = pendingAlerts(repo);
14
+ const handled = repo.alerts.length - pending.length;
15
+ const handledNote = handled > 0 ? ` + ${handled} fixed by hand by the user` : "";
16
+ if (pending.length === 0)
17
+ return `none${handledNote}`;
18
+ const counts = countBySeverity(pending);
14
19
  const detail = ALERT_SEVERITIES.filter((severity) => counts[severity] > 0).map((severity) => `${severity} ${counts[severity]}`);
15
- return `${repo.alerts.length} (${detail.join(", ")})`;
20
+ return `${pending.length} (${detail.join(", ")})${handledNote}`;
16
21
  }
17
- export function describeRepo(view) {
22
+ /** Description d'un dépôt pour l'agent ; `category` est la catégorie où l'utilisateur l'a rangé. */
23
+ export function describeRepo(view, category) {
18
24
  const { repo, activeOperation } = view;
19
25
  const lines = [
20
26
  `- ${repo.id} (analysed branch ${repo.branch}${repo.branch === repo.defaultBranch ? ", the default one" : `; default branch ${repo.defaultBranch}`})`,
27
+ ` Category: ${category ? category.name : "none"}`,
21
28
  ` Open Dependabot alerts: ${alertsLabel(repo)}${repo.syncedAt ? ` · synced ${repo.syncedAt}` : " · not synced yet"}`,
22
29
  ];
23
30
  if (repo.syncError)
24
31
  lines.push(` Last sync failed: ${repo.syncError}`);
32
+ if (view.unfixable.length > 0)
33
+ lines.push(` Last npm audit found no published fix for: ${view.unfixable.join(", ")}`);
34
+ if (view.cleanAuditAt) {
35
+ lines.push(` npm audit of ${view.cleanAuditAt} found no vulnerability on the default branch: these Dependabot alerts are probably not refreshed yet.`);
36
+ }
25
37
  lines.push(` Agent rights: ${rightsLabel(repo)}`);
26
38
  if (activeOperation)
27
39
  lines.push(` Operation in progress: ${activeOperation.id} (${activeOperation.status})`);
@@ -31,7 +43,9 @@ export function describeAlerts(repo) {
31
43
  const header = `${repo.id}: ${repo.alerts.length} open Dependabot alert(s), synced ${repo.syncedAt}.`;
32
44
  const lines = repo.alerts.map((alert) => {
33
45
  const patched = alert.patchedVersion ? ` — patched in ${alert.patchedVersion}` : " — no patched version";
34
- return `- #${alert.number} ${alert.severity} ${alert.package} (${alert.ecosystem}, ${alert.manifestPath}): ${alert.summary}${patched} — ${alert.url}`;
46
+ const mark = repo.handledAlerts.find((candidate) => candidate.number === alert.number);
47
+ const handled = mark ? ` — fixed by hand by the user on ${mark.markedAt}` : "";
48
+ return `- #${alert.number} ${alert.severity} ${alert.package} (${alert.ecosystem}, ${alert.manifestPath}): ${alert.summary}${patched}${handled} — ${alert.url}`;
35
49
  });
36
50
  return [header, ...lines].join("\n");
37
51
  }
@@ -3,6 +3,7 @@ import type { GitHubConfig } from "../core/config.js";
3
3
  import { type OperationContext } from "../core/operations.js";
4
4
  import type { Store } from "../core/store.js";
5
5
  import { type Args, type ToolResult } from "./types.js";
6
+ /** Dépôts suivis, tous ou ceux d'une catégorie désignée par son nom, sans tenir compte de la casse. */
6
7
  export declare function listRepositories(store: Store, args: Args): ToolResult;
7
8
  /** Relit les alertes sur GitHub avant de les lister. */
8
9
  export declare function getAlerts(store: Store, config: GitHubConfig, args: Args): Promise<ToolResult>;
@@ -16,12 +16,27 @@ function assertAllowed(repo, right) {
16
16
  throw new TrackerError(`The agent is not allowed to ${RIGHT_LABELS[right]} on ${repo.id}. Only the user can grant this right, in the GUI.`);
17
17
  }
18
18
  }
19
+ /** Dépôts suivis, tous ou ceux d'une catégorie désignée par son nom, sans tenir compte de la casse. */
19
20
  export function listRepositories(store, args) {
20
- rejectUnknownFields(args, []);
21
- const views = listRepoViews(store);
22
- if (views.length === 0)
23
- return textResult("No repository is tracked. The user adds repositories in the GUI.");
24
- return textResult([`${views.length} tracked repositor${views.length === 1 ? "y" : "ies"}:`, ...views.map(describeRepo)].join("\n"));
21
+ rejectUnknownFields(args, ["category"]);
22
+ const categories = store.listCategories();
23
+ const categoryName = optionalString(args, "category");
24
+ let views = listRepoViews(store);
25
+ let scope = "tracked";
26
+ if (categoryName !== undefined) {
27
+ const category = categories.find((candidate) => candidate.name.toLowerCase() === categoryName.trim().toLowerCase());
28
+ if (!category) {
29
+ const known = categories.length === 0 ? "the user has created none" : `existing categories: ${categories.map((candidate) => candidate.name).join(", ")}`;
30
+ throw new TrackerError(`Category "${categoryName}" does not exist (${known}).`);
31
+ }
32
+ views = views.filter((view) => view.repo.categoryId === category.id);
33
+ scope = `in category ${category.name}`;
34
+ }
35
+ if (views.length === 0) {
36
+ return textResult(categoryName === undefined ? "No repository is tracked. The user adds repositories in the GUI." : `No repository ${scope}.`);
37
+ }
38
+ const categoryOf = (view) => categories.find((category) => category.id === view.repo.categoryId) ?? null;
39
+ return textResult([`${views.length} repositor${views.length === 1 ? "y" : "ies"} ${scope}:`, ...views.map((view) => describeRepo(view, categoryOf(view)))].join("\n"));
25
40
  }
26
41
  /** Relit les alertes sur GitHub avant de les lister. */
27
42
  export async function getAlerts(store, config, args) {