flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/services/runner/src/surroundings.ts

27 lines1,144 bytesCodeBlame
1/**
2 * What an agent run may be told about the projects around its repository:
3 * only those the person it acts for can read. Someone who reads every
4 * repository in the workspace is told of all of them; anyone else (a member
5 * whose base permission is None, an outside collaborator) of the projects
6 * the projects service lists for them.
7 *
8 * Only type imports, so it can be tested on its own.
9 */
10
11export type Neighbour = { slug: string; as: string | null };
12
13export type ProjectSurroundings = {
14 slug: string;
15 name: string;
16 dependencies: { dependsOn: Neighbour[]; usedBy: Neighbour[] };
17};
18
19/** `projects` with the neighbours not in `visible` left out; null `visible` reads everything. */
20export function readableSurroundings(projects: ProjectSurroundings[], visible: Set<string> | null): ProjectSurroundings[] {
21 if (!visible) return projects;
22 const keep = (list: Neighbour[]) => list.filter((neighbour) => visible.has(neighbour.slug.toLowerCase()));
23 return projects.map((project) => ({
24 ...project,
25 dependencies: { dependsOn: keep(project.dependencies.dependsOn), usedBy: keep(project.dependencies.usedBy) },
26 }));
27}