@lbdudc/linea-git 0.3.1 → 0.3.2

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.
@@ -51,6 +51,14 @@ export interface IssueRecord {
51
51
  closedAt: string | null;
52
52
  comments: CommentRecord[];
53
53
  nextComment: number;
54
+ /** The labels put on it and taken off it (older issues have none). */
55
+ labelEvents?: LabelEventRecord[];
56
+ }
57
+ export interface LabelEventRecord {
58
+ label: string;
59
+ action: 'added' | 'removed';
60
+ author: string;
61
+ createdAt: string;
54
62
  }
55
63
  export interface TemplateRecord {
56
64
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/local/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AA2G5B,MAAM,KAAK,GAAU,EAAE,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,CAAA;AAElE,MAAM,UAAU,GAAG,CAAI,KAAQ,EAAK,EAAE;IACpC,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAClE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACpB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;YAAE,UAAU,CAAC,KAAK,CAAC,CAAA;IAC7D,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,6FAA6F;AAC7F,MAAM,MAAM,GAAG,IAAI,GAAG,EAA4B,CAAA;AAElD,sIAAsI;AACtI,oFAAoF;AACpF,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAA;AAC9B,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,O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AAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;YAC/F,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAA;YAC/E,IAAI,KAAK;gBAAE,KAAK,CAAC,WAAW,GAAG,WAAW,CAAA;;gBACrC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAA;QACzD,CAAC,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\n/**\n * What the `local` host knows about its repositories besides what git keeps: the namespaces (groups), who is in a repository, its\n * topics, its change requests and webhooks. One JSON file next to the repositories, read and written whole, one operation at a time.\n * (A host with many writers would use a database; this one is the server of one team.)\n */\n\nexport interface ThreadRecord {\n id: number\n position?: { path: string, line: number, side: 'new' | 'old' }\n resolved: boolean\n comments: CommentRecord[]\n}\n\nexport interface ChangeRequestRecord {\n number: number\n title: string\n sourceBranch: string\n targetBranch: string\n state: 'opened' | 'merged' | 'closed'\n createdAt: string\n // (absent in a state written before the pages of merge requests existed)\n description?: string\n author?: string\n labels?: string[]\n reviewers?: string[]\n updatedAt?: string\n mergedAt?: string | null\n threads?: ThreadRecord[]\n nextThread?: number\n nextComment?: number\n}\n\nexport interface CommentRecord {\n id: number\n author: string\n body: string\n createdAt: string\n updatedAt: string\n}\n\nexport interface IssueRecord {\n number: number\n title: string\n description: string\n state: 'opened' | 'closed'\n author: string\n assignees: string[]\n labels: string[]\n milestone: string | null\n createdAt: string\n updatedAt: string\n closedAt: string | null\n comments: CommentRecord[]\n nextComment: number\n}\n\nexport interface TemplateRecord {\n name: string\n content: string\n}\n\nexport interface ReleaseRecord {\n tag: string\n name: string\n description: string\n prerelease: boolean\n createdAt: string\n}\n\nexport interface NamespaceRecord {\n id: number\n name: string\n /** `group/sub`: what the host shows as the path. */\n path: string\n parentId: number | null\n owner: string\n}\n\nexport interface RepositoryRecord {\n id: number\n name: string\n namespaceId: number\n description: string\n topics: string[]\n defaultBranch: string\n owner: string\n members: { username: string, accessLevel: number }[]\n changeRequests: ChangeRequestRecord[]\n nextChangeRequest: number\n /** (absent in a state written before issues existed) */\n issues?: IssueRecord[]\n nextIssue?: number\n /** (absent in a state written before releases existed) */\n releases?: ReleaseRecord[]\n templates?: { issue: TemplateRecord[], mergeRequest: TemplateRecord[] }\n hooks: { url: string, secret: string, branch: string | null }[]\n createdAt: string\n}\n\nexport interface State {\n next: number\n namespaces: NamespaceRecord[]\n repositories: RepositoryRecord[]\n}\n\nconst EMPTY: State = { next: 1, namespaces: [], repositories: [] }\n\nconst deepFreeze = <T>(value: T): T => {\n if (value && typeof value === 'object' && !Object.isFrozen(value)) {\n Object.freeze(value)\n for (const child of Object.values(value)) deepFreeze(child)\n }\n return value\n}\n\n// operations on one folder run one after another, whoever asks (the file is rewritten whole)\nconst queues = new Map<string, Promise<unknown>>()\n\n// Another process on the same folder (the CLI, a second server) must not write at the same time: a lock file next to the state, taken\n// for each change. A lock left by a process that died is taken over after STALE_MS.\nexport const STALE_MS = 30_000\nconst sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms))\n\nexport class LocalStore {\n readonly dir: string\n private readonly file: string\n private readonly lock: string\n\n constructor(dataDir: string) {\n this.dir = path.resolve(dataDir)\n this.file = path.join(this.dir, 'state.json')\n this.lock = `${this.file}.lock`\n }\n\n /** Where the bare repository of `id` is. */\n repositoryDir(id: number): string {\n return path.join(this.dir, 'repos', `${id}.git`)\n }\n\n // The state as it was last read, and which file that was (a rewrite is a new inode, so another process's write is seen too): a read that\n // finds the file as it was does not parse it again. Frozen, because it is shared: whoever changes the state does it in `update`, on a copy.\n private cached: { signature: string, state: State } | null = null\n private recovered = false\n\n private parse(file: string): State {\n return JSON.parse(fs.readFileSync(file, 'utf8')) as State\n }\n\n private signature(): string | null {\n try {\n const stat = fs.statSync(this.file)\n return `${stat.ino}:${stat.size}:${stat.mtimeMs}`\n } catch {\n return null\n }\n }\n\n private load(): State {\n const signature = this.signature()\n if (signature && this.cached?.signature === signature) return this.cached.state\n this.recovered = false\n const state = this.read_()\n // (a copy recovered from a file that could not be read is not remembered: the file is still damaged)\n if (signature && !this.recovered && this.signature() === signature) this.cached = { signature, state: deepFreeze(state) }\n else this.cached = null\n return this.cached?.state ?? state\n }\n\n private read_(): State {\n try {\n return this.parse(this.file)\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return structuredClone(EMPTY)\n // a file that cannot be read (a write cut short, a disk that lied): the last good copy, if there is one, rather than a host that is down\n try {\n const recovered = this.parse(`${this.file}.bak`)\n this.recovered = true\n console.error(`[local git] ${this.file} could not be read (${(error as Error).message}): using the last good copy`)\n return recovered\n } catch {\n throw new Error(`${this.file} is damaged and there is no copy to recover from: ${(error as Error).message}`)\n }\n }\n }\n\n read<T>(fn: (state: State) => T): Promise<T> {\n return this.queue(() => fn(this.load()))\n }\n\n private async lockFile(): Promise<() => void> {\n fs.mkdirSync(this.dir, { recursive: true })\n for (let attempt = 0; ; attempt += 1) {\n try {\n const fd = fs.openSync(this.lock, 'wx')\n fs.writeSync(fd, String(process.pid))\n fs.closeSync(fd)\n return () => fs.rmSync(this.lock, { force: true })\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error\n let age = 0\n try { age = Date.now() - fs.statSync(this.lock).mtimeMs } catch { continue }\n if (age > STALE_MS) { fs.rmSync(this.lock, { force: true }); continue }\n if (attempt > 600) throw new Error(`${this.lock} is held by another process`)\n await sleep(20)\n }\n }\n }\n\n /** Writes the state so that a cut leaves the old file or the new one, never half: to a temporary file, to disk, over the old. */\n private write(state: State): void {\n const tmp = `${this.file}.${process.pid}.tmp`\n const fd = fs.openSync(tmp, 'w')\n try {\n fs.writeSync(fd, JSON.stringify(state, null, 2))\n fs.fsyncSync(fd)\n } finally {\n fs.closeSync(fd)\n }\n // the file that is about to be replaced is the last good one\n if (fs.existsSync(this.file)) fs.copyFileSync(this.file, `${this.file}.bak`)\n fs.renameSync(tmp, this.file)\n this.cached = null\n try {\n const directory = fs.openSync(this.dir, 'r')\n fs.fsyncSync(directory)\n fs.closeSync(directory)\n } catch { /* a platform that cannot sync a folder */ }\n }\n\n /** Changes the state: `fn` gets it and returns what the caller wants back; what it changed is saved when it is done. */\n update<T>(fn: (state: State) => T | Promise<T>): Promise<T> {\n return this.queue(async () => {\n const release = await this.lockFile()\n try {\n const state = structuredClone(this.load()) // a copy: `fn` may change it and then fail\n const before = JSON.stringify(state)\n const result = await fn(state)\n if (JSON.stringify(state) !== before) this.write(state)\n return result\n } finally {\n release()\n }\n })\n }\n\n private queue<T>(run: () => T | Promise<T>): Promise<T> {\n const previous = queues.get(this.file) ?? Promise.resolve()\n const current = previous.then(run, run)\n queues.set(this.file, current.catch(() => undefined))\n return current\n }\n\n /** Adds (or raises) a person's access to a repository: how an administrator lets someone else in. */\n addMember({ repositoryId, username, accessLevel }: { repositoryId: number | string, username: string, accessLevel: number }): Promise<void> {\n return this.update((state) => {\n const repository = state.repositories.find((candidate) => candidate.id === Number(repositoryId))\n if (!repository) throw Object.assign(new Error('There is no such repository'), { status: 404 })\n const known = repository.members.find((member) => member.username === username)\n if (known) known.accessLevel = accessLevel\n else repository.members.push({ username, accessLevel })\n })\n }\n}\n"]}
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/local/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAoH5B,MAAM,KAAK,GAAU,EAAE,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,CAAA;AAElE,MAAM,UAAU,GAAG,CAAI,KAAQ,EAAK,EAAE;IACpC,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,C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E,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;QACrD,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,qGAAqG;IACrG,SAAS,CAAC,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAA4E;QACzH,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YAC3B,MAAM,UAAU,GAAG,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,KAAK,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;YAChG,IAAI,CAAC,UAAU;gBAAE,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,6BAA6B,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;YAC/F,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAA;YAC/E,IAAI,KAAK;gBAAE,KAAK,CAAC,WAAW,GAAG,WAAW,CAAA;;gBACrC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAA;QACzD,CAAC,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\n/**\n * What the `local` host knows about its repositories besides what git keeps: the namespaces (groups), who is in a repository, its\n * topics, its change requests and webhooks. One JSON file next to the repositories, read and written whole, one operation at a time.\n * (A host with many writers would use a database; this one is the server of one team.)\n */\n\nexport interface ThreadRecord {\n id: number\n position?: { path: string, line: number, side: 'new' | 'old' }\n resolved: boolean\n comments: CommentRecord[]\n}\n\nexport interface ChangeRequestRecord {\n number: number\n title: string\n sourceBranch: string\n targetBranch: string\n state: 'opened' | 'merged' | 'closed'\n createdAt: string\n // (absent in a state written before the pages of merge requests existed)\n description?: string\n author?: string\n labels?: string[]\n reviewers?: string[]\n updatedAt?: string\n mergedAt?: string | null\n threads?: ThreadRecord[]\n nextThread?: number\n nextComment?: number\n}\n\nexport interface CommentRecord {\n id: number\n author: string\n body: string\n createdAt: string\n updatedAt: string\n}\n\nexport interface IssueRecord {\n number: number\n title: string\n description: string\n state: 'opened' | 'closed'\n author: string\n assignees: string[]\n labels: string[]\n milestone: string | null\n createdAt: string\n updatedAt: string\n closedAt: string | null\n comments: CommentRecord[]\n nextComment: number\n /** The labels put on it and taken off it (older issues have none). */\n labelEvents?: LabelEventRecord[]\n}\n\nexport interface LabelEventRecord {\n label: string\n action: 'added' | 'removed'\n author: string\n createdAt: string\n}\n\nexport interface TemplateRecord {\n name: string\n content: string\n}\n\nexport interface ReleaseRecord {\n tag: string\n name: string\n description: string\n prerelease: boolean\n createdAt: string\n}\n\nexport interface NamespaceRecord {\n id: number\n name: string\n /** `group/sub`: what the host shows as the path. */\n path: string\n parentId: number | null\n owner: string\n}\n\nexport interface RepositoryRecord {\n id: number\n name: string\n namespaceId: number\n description: string\n topics: string[]\n defaultBranch: string\n owner: string\n members: { username: string, accessLevel: number }[]\n changeRequests: ChangeRequestRecord[]\n nextChangeRequest: number\n /** (absent in a state written before issues existed) */\n issues?: IssueRecord[]\n nextIssue?: number\n /** (absent in a state written before releases existed) */\n releases?: ReleaseRecord[]\n templates?: { issue: TemplateRecord[], mergeRequest: TemplateRecord[] }\n hooks: { url: string, secret: string, branch: string | null }[]\n createdAt: string\n}\n\nexport interface State {\n next: number\n namespaces: NamespaceRecord[]\n repositories: RepositoryRecord[]\n}\n\nconst EMPTY: State = { next: 1, namespaces: [], repositories: [] }\n\nconst deepFreeze = <T>(value: T): T => {\n if (value && typeof value === 'object' && !Object.isFrozen(value)) {\n Object.freeze(value)\n for (const child of Object.values(value)) deepFreeze(child)\n }\n return value\n}\n\n// operations on one folder run one after another, whoever asks (the file is rewritten whole)\nconst queues = new Map<string, Promise<unknown>>()\n\n// Another process on the same folder (the CLI, a second server) must not write at the same time: a lock file next to the state, taken\n// for each change. A lock left by a process that died is taken over after STALE_MS.\nexport const STALE_MS = 30_000\nconst sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms))\n\nexport class LocalStore {\n readonly dir: string\n private readonly file: string\n private readonly lock: string\n\n constructor(dataDir: string) {\n this.dir = path.resolve(dataDir)\n this.file = path.join(this.dir, 'state.json')\n this.lock = `${this.file}.lock`\n }\n\n /** Where the bare repository of `id` is. */\n repositoryDir(id: number): string {\n return path.join(this.dir, 'repos', `${id}.git`)\n }\n\n // The state as it was last read, and which file that was (a rewrite is a new inode, so another process's write is seen too): a read that\n // finds the file as it was does not parse it again. Frozen, because it is shared: whoever changes the state does it in `update`, on a copy.\n private cached: { signature: string, state: State } | null = null\n private recovered = false\n\n private parse(file: string): State {\n return JSON.parse(fs.readFileSync(file, 'utf8')) as State\n }\n\n private signature(): string | null {\n try {\n const stat = fs.statSync(this.file)\n return `${stat.ino}:${stat.size}:${stat.mtimeMs}`\n } catch {\n return null\n }\n }\n\n private load(): State {\n const signature = this.signature()\n if (signature && this.cached?.signature === signature) return this.cached.state\n this.recovered = false\n const state = this.read_()\n // (a copy recovered from a file that could not be read is not remembered: the file is still damaged)\n if (signature && !this.recovered && this.signature() === signature) this.cached = { signature, state: deepFreeze(state) }\n else this.cached = null\n return this.cached?.state ?? state\n }\n\n private read_(): State {\n try {\n return this.parse(this.file)\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return structuredClone(EMPTY)\n // a file that cannot be read (a write cut short, a disk that lied): the last good copy, if there is one, rather than a host that is down\n try {\n const recovered = this.parse(`${this.file}.bak`)\n this.recovered = true\n console.error(`[local git] ${this.file} could not be read (${(error as Error).message}): using the last good copy`)\n return recovered\n } catch {\n throw new Error(`${this.file} is damaged and there is no copy to recover from: ${(error as Error).message}`)\n }\n }\n }\n\n read<T>(fn: (state: State) => T): Promise<T> {\n return this.queue(() => fn(this.load()))\n }\n\n private async lockFile(): Promise<() => void> {\n fs.mkdirSync(this.dir, { recursive: true })\n for (let attempt = 0; ; attempt += 1) {\n try {\n const fd = fs.openSync(this.lock, 'wx')\n fs.writeSync(fd, String(process.pid))\n fs.closeSync(fd)\n return () => fs.rmSync(this.lock, { force: true })\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error\n let age = 0\n try { age = Date.now() - fs.statSync(this.lock).mtimeMs } catch { continue }\n if (age > STALE_MS) { fs.rmSync(this.lock, { force: true }); continue }\n if (attempt > 600) throw new Error(`${this.lock} is held by another process`)\n await sleep(20)\n }\n }\n }\n\n /** Writes the state so that a cut leaves the old file or the new one, never half: to a temporary file, to disk, over the old. */\n private write(state: State): void {\n const tmp = `${this.file}.${process.pid}.tmp`\n const fd = fs.openSync(tmp, 'w')\n try {\n fs.writeSync(fd, JSON.stringify(state, null, 2))\n fs.fsyncSync(fd)\n } finally {\n fs.closeSync(fd)\n }\n // the file that is about to be replaced is the last good one\n if (fs.existsSync(this.file)) fs.copyFileSync(this.file, `${this.file}.bak`)\n fs.renameSync(tmp, this.file)\n this.cached = null\n try {\n const directory = fs.openSync(this.dir, 'r')\n fs.fsyncSync(directory)\n fs.closeSync(directory)\n } catch { /* a platform that cannot sync a folder */ }\n }\n\n /** Changes the state: `fn` gets it and returns what the caller wants back; what it changed is saved when it is done. */\n update<T>(fn: (state: State) => T | Promise<T>): Promise<T> {\n return this.queue(async () => {\n const release = await this.lockFile()\n try {\n const state = structuredClone(this.load()) // a copy: `fn` may change it and then fail\n const before = JSON.stringify(state)\n const result = await fn(state)\n if (JSON.stringify(state) !== before) this.write(state)\n return result\n } finally {\n release()\n }\n })\n }\n\n private queue<T>(run: () => T | Promise<T>): Promise<T> {\n const previous = queues.get(this.file) ?? Promise.resolve()\n const current = previous.then(run, run)\n queues.set(this.file, current.catch(() => undefined))\n return current\n }\n\n /** Adds (or raises) a person's access to a repository: how an administrator lets someone else in. */\n addMember({ repositoryId, username, accessLevel }: { repositoryId: number | string, username: string, accessLevel: number }): Promise<void> {\n return this.update((state) => {\n const repository = state.repositories.find((candidate) => candidate.id === Number(repositoryId))\n if (!repository) throw Object.assign(new Error('There is no such repository'), { status: 404 })\n const known = repository.members.find((member) => member.username === username)\n if (known) known.accessLevel = accessLevel\n else repository.members.push({ username, accessLevel })\n })\n }\n}\n"]}
@@ -40,6 +40,20 @@ export interface Member {
40
40
  /** 10 guest, 20 reporter/read, 30 developer/write, 40 maintainer, 50 owner/admin. */
41
41
  accessLevel: number;
42
42
  }
43
+ /** Who has access to a repository, at what level and where the access comes from. */
44
+ export interface AccessEntry {
45
+ username: string;
46
+ /** One of the four levels of LINEA: 20 reporter, 30 developer, 40 maintainer, 50 owner. */
47
+ accessLevel: number;
48
+ /** `direct`: set on the repository itself; `inherited`: from the group or organization that holds it. */
49
+ source: 'direct' | 'inherited';
50
+ }
51
+ /** A person of a host, as `searchUsers` finds them. */
52
+ export interface HostUser {
53
+ username: string;
54
+ name: string;
55
+ avatarUrl: string | null;
56
+ }
43
57
  export interface RepositoryFile {
44
58
  path: string;
45
59
  name: string;
@@ -107,6 +121,13 @@ export interface Comment {
107
121
  createdAt: string;
108
122
  updatedAt: string;
109
123
  }
124
+ /** A label put on an issue or taken off it: by whom and when. */
125
+ export interface LabelEvent {
126
+ label: string;
127
+ action: 'added' | 'removed';
128
+ author: string | undefined;
129
+ createdAt: string;
130
+ }
110
131
  /** A release of a tag: what the host shows as the release notes of a version. `tag` is its key (one release per tag). */
111
132
  export interface Release {
112
133
  tag: string;
@@ -362,6 +383,25 @@ export interface Tokens {
362
383
  accessToken: string;
363
384
  refreshToken: string | null;
364
385
  }
386
+ /** What the person is shown to approve a sign-in from a machine with no browser (the OAuth device authorization grant). */
387
+ export interface DeviceAuthorization {
388
+ /** Kept by the client and given back to poll; useless without the host's OAuth app secret on confidential apps. */
389
+ deviceCode: string;
390
+ userCode: string;
391
+ verificationUri: string;
392
+ verificationUriComplete?: string | undefined;
393
+ /** Seconds the codes last. */
394
+ expiresIn: number;
395
+ /** Seconds to wait between polls. */
396
+ interval: number;
397
+ }
398
+ export type DevicePoll = {
399
+ status: 'pending';
400
+ interval: number;
401
+ } | {
402
+ status: 'done';
403
+ tokens: Tokens;
404
+ };
365
405
  export interface AuthConfig {
366
406
  kind: GitHostKind;
367
407
  clientId: string | undefined;
@@ -400,6 +440,17 @@ export interface GitProvider {
400
440
  username: string;
401
441
  avatarUrl: string;
402
442
  }>;
443
+ /**
444
+ * Device authorization: for hosts that have it (GitLab, GitHub), not part of GIT_PROVIDER_METHODS. Rejects with `GitDeviceFlowError`
445
+ * (`unsupported` when the host has no such flow); polling rejects with `expired_token` / `access_denied` when it cannot go on.
446
+ */
447
+ startDeviceAuthorization?(args?: {
448
+ scope?: string;
449
+ }): Promise<DeviceAuthorization>;
450
+ pollDeviceAuthorization?(args: {
451
+ deviceCode: string;
452
+ interval?: number;
453
+ }): Promise<DevicePoll>;
403
454
  /** Where the user may create things. */
404
455
  listNamespaces(args: {
405
456
  token: string;
@@ -486,6 +537,29 @@ export interface GitProvider {
486
537
  id: Id;
487
538
  username: string;
488
539
  }): Promise<number>;
540
+ /** Everybody with access to the repository, each with the level and where it comes from (needs Maintainer to read the whole list). */
541
+ listAccess(args: {
542
+ token: string;
543
+ id: Id;
544
+ }): Promise<AccessEntry[]>;
545
+ /** Gives a person a level (20, 30, 40 or 50) on the repository, or changes it. */
546
+ setAccess(args: {
547
+ token: string;
548
+ id: Id;
549
+ username: string;
550
+ accessLevel: number;
551
+ }): Promise<void>;
552
+ /** Takes the access set on the repository itself from a person (one inherited from a group stays: it is the group's). */
553
+ removeAccess(args: {
554
+ token: string;
555
+ id: Id;
556
+ username: string;
557
+ }): Promise<void>;
558
+ /** People of the host whose username or name matches `query`. */
559
+ searchUsers(args: {
560
+ token: string;
561
+ query: string;
562
+ }): Promise<HostUser[]>;
489
563
  getFile(args: {
490
564
  token: string;
491
565
  id: Id;
@@ -691,6 +765,12 @@ export interface GitProvider {
691
765
  id: Id;
692
766
  number: number;
693
767
  }): Promise<Comment[]>;
768
+ /** The labels put on an issue and taken off it, oldest first (those it was opened with too): who and when. */
769
+ listIssueLabelEvents(args: {
770
+ token: string;
771
+ id: Id;
772
+ number: number;
773
+ }): Promise<LabelEvent[]>;
694
774
  addIssueComment(args: {
695
775
  token: string;
696
776
  id: Id;
@@ -885,4 +965,4 @@ export interface GitProvider {
885
965
  isAlreadyExistsError(error: unknown): boolean;
886
966
  }
887
967
  /** The methods a provider has to have: what the contract test checks and what a new host has to fill in. */
888
- export declare const GIT_PROVIDER_METHODS: readonly ["authConfig", "exchangeCode", "refreshToken", "getUser", "listNamespaces", "findNamespace", "createNamespace", "deleteNamespace", "renameNamespace", "createRepository", "deleteRepository", "listPendingDeletion", "restoreRepository", "restoreNamespace", "renameRepository", "getRepository", "findRepository", "listRepositories", "addTopic", "setDefaultBranch", "getMembers", "getAccessLevel", "getFile", "getFileRevision", "readFile", "listFiles", "createFile", "saveFile", "commit", "downloadArchive", "getCommits", "compare", "createBranch", "listBranches", "getBranch", "listTags", "getTag", "createTag", "createRelease", "getRelease", "listReleases", "updateRelease", "createChangeRequest", "createOrRenameChangeRequest", "listChangeRequests", "listChangeRequestPipelines", "mergeChangeRequest", "getLatestPipeline", "listPipelines", "getPipelineJobs", "retryPipeline", "cancelPipeline", "cancelJob", "enablePipelines", "disablePipelines", "pipelinesEnabled", "getCiRunners", "setInstanceRunners", "getJobTrace", "ensureWebhook", "verifyWebhook", "parsePushEvent", "listMergeRequests", "getMergeRequest", "createMergeRequest", "updateMergeRequest", "getMergeRequestDiff", "listMergeRequestThreads", "addMergeRequestComment", "setThreadResolved", "mergeMergeRequest", "approveMergeRequest", "capabilities", "listIssues", "getIssue", "createIssue", "updateIssue", "listIssueComments", "addIssueComment", "listLabels", "listMilestones", "listTemplates", "saveTemplate", "deleteTemplate", "rollback", "isAuthError", "isAlreadyExistsError"];
968
+ export declare const GIT_PROVIDER_METHODS: readonly ["authConfig", "exchangeCode", "refreshToken", "getUser", "listNamespaces", "findNamespace", "createNamespace", "deleteNamespace", "renameNamespace", "createRepository", "deleteRepository", "listPendingDeletion", "restoreRepository", "restoreNamespace", "renameRepository", "getRepository", "findRepository", "listRepositories", "addTopic", "setDefaultBranch", "getMembers", "getAccessLevel", "listAccess", "setAccess", "removeAccess", "searchUsers", "getFile", "getFileRevision", "readFile", "listFiles", "createFile", "saveFile", "commit", "downloadArchive", "getCommits", "compare", "createBranch", "listBranches", "getBranch", "listTags", "getTag", "createTag", "createRelease", "getRelease", "listReleases", "updateRelease", "createChangeRequest", "createOrRenameChangeRequest", "listChangeRequests", "listChangeRequestPipelines", "mergeChangeRequest", "getLatestPipeline", "listPipelines", "getPipelineJobs", "retryPipeline", "cancelPipeline", "cancelJob", "enablePipelines", "disablePipelines", "pipelinesEnabled", "getCiRunners", "setInstanceRunners", "getJobTrace", "ensureWebhook", "verifyWebhook", "parsePushEvent", "listMergeRequests", "getMergeRequest", "createMergeRequest", "updateMergeRequest", "getMergeRequestDiff", "listMergeRequestThreads", "addMergeRequestComment", "setThreadResolved", "mergeMergeRequest", "approveMergeRequest", "capabilities", "listIssues", "getIssue", "createIssue", "updateIssue", "listIssueComments", "listIssueLabelEvents", "addIssueComment", "listLabels", "listMilestones", "listTemplates", "saveTemplate", "deleteTemplate", "rollback", "isAuthError", "isAlreadyExistsError"];
package/dist/provider.js CHANGED
@@ -16,14 +16,14 @@ export const GIT_PROVIDER_METHODS = [
16
16
  'authConfig', 'exchangeCode', 'refreshToken', 'getUser',
17
17
  'listNamespaces', 'findNamespace', 'createNamespace', 'deleteNamespace', 'renameNamespace',
18
18
  'createRepository', 'deleteRepository', 'listPendingDeletion', 'restoreRepository', 'restoreNamespace', 'renameRepository', 'getRepository', 'findRepository', 'listRepositories', 'addTopic',
19
- 'setDefaultBranch', 'getMembers', 'getAccessLevel',
19
+ 'setDefaultBranch', 'getMembers', 'getAccessLevel', 'listAccess', 'setAccess', 'removeAccess', 'searchUsers',
20
20
  'getFile', 'getFileRevision', 'readFile', 'listFiles', 'createFile', 'saveFile', 'commit', 'downloadArchive', 'getCommits', 'compare',
21
21
  'createBranch', 'listBranches', 'getBranch', 'listTags', 'getTag', 'createTag',
22
22
  'createRelease', 'getRelease', 'listReleases', 'updateRelease',
23
23
  'createChangeRequest', 'createOrRenameChangeRequest', 'listChangeRequests', 'listChangeRequestPipelines', 'mergeChangeRequest',
24
24
  'getLatestPipeline', 'listPipelines', 'getPipelineJobs', 'retryPipeline', 'cancelPipeline', 'cancelJob', 'enablePipelines', 'disablePipelines', 'pipelinesEnabled', 'getCiRunners', 'setInstanceRunners', 'getJobTrace', 'ensureWebhook', 'verifyWebhook', 'parsePushEvent',
25
25
  'listMergeRequests', 'getMergeRequest', 'createMergeRequest', 'updateMergeRequest', 'getMergeRequestDiff', 'listMergeRequestThreads', 'addMergeRequestComment', 'setThreadResolved', 'mergeMergeRequest', 'approveMergeRequest',
26
- 'capabilities', 'listIssues', 'getIssue', 'createIssue', 'updateIssue', 'listIssueComments', 'addIssueComment', 'listLabels', 'listMilestones', 'listTemplates', 'saveTemplate', 'deleteTemplate',
26
+ 'capabilities', 'listIssues', 'getIssue', 'createIssue', 'updateIssue', 'listIssueComments', 'listIssueLabelEvents', 'addIssueComment', 'listLabels', 'listMilestones', 'listTemplates', 'saveTemplate', 'deleteTemplate',
27
27
  'rollback', 'isAuthError', 'isAlreadyExistsError'
28
28
  ];
29
29
  //# sourceMappingURL=provider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAmjBH,4GAA4G;AAC5G,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,SAAS;IACvD,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB;IAC1F,kBAAkB,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,UAAU;IAC7L,kBAAkB,EAAE,YAAY,EAAE,gBAAgB;IAClD,SAAS,EAAE,iBAAiB,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,iBAAiB,EAAE,YAAY,EAAE,SAAS;IACrI,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW;IAC9E,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,eAAe;IAC9D,qBAAqB,EAAE,6BAA6B,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,oBAAoB;IAC9H,mBAAmB,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,gBAAgB,EAAE,WAAW,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,cAAc,EAAE,oBAAoB,EAAE,aAAa,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB;IAC3Q,mBAAmB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,qBAAqB;IAC/N,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB;IACjM,UAAU,EAAE,aAAa,EAAE,sBAAsB;CACzC,CAAA","sourcesContent":["/**\n * The git host LINEA works on (GitLab, or GitHub): everything LINEA needs from it, in the host's own words left out.\n *\n * A deployment talks to ONE host. The server and the CLI never speak a host's API: they take a `GitProvider` (`createGitProvider`) and\n * use only the methods below, with the shapes below. What differs between hosts is hidden in the provider: GitLab calls the same things\n * groups, projects and merge requests; GitHub calls them organisations, repositories and pull requests, and has no groups inside\n * groups (see docs/git-provider.md for how each difference is absorbed).\n *\n * A provider object is also a unit of work: what it creates (namespaces, repositories, files, commits, branches, tags) is remembered,\n * and `rollback()` undoes it, newest first. Make one per operation.\n *\n * Every method takes the user's access `token` first. `id` is the repository id (or its `path`), `namespaceId` the id of a namespace.\n */\n\nexport type Id = number | string\n\nexport interface Repository {\n id: Id\n name: string\n /** Full path as the host shows it: `group/sub/name`, `owner/name`. */\n path: string\n description: string\n webUrl: string\n webIdeUrl: string\n namespaceId: Id | undefined\n /** The namespace that contains this repository's namespace (for a product: the one that is its line). */\n parentNamespaceId?: Id | undefined\n defaultBranch?: string | undefined\n topics: string[]\n /** When the host made it (a host that does not keep it says nothing). */\n createdAt?: string | undefined\n}\n\nexport interface Namespace {\n id: Id\n fullPath: string\n name: string\n /** Made by `createNamespace` but not yet on the host: the repository that follows is what creates it. */\n pending?: boolean\n}\n\nexport interface Member {\n username: string\n /** 10 guest, 20 reporter/read, 30 developer/write, 40 maintainer, 50 owner/admin. */\n accessLevel: number\n}\n\nexport interface RepositoryFile {\n path: string\n name: string\n /** base64 */\n content: string\n encoding: 'base64'\n /** What to quote to say \"I changed this file starting from this version\" (GitLab: last commit id; GitHub: blob sha). */\n revision: string\n}\n\nexport interface CommitSummary {\n shortId: string\n title: string\n authorName: string\n createdAt: string\n webUrl?: string | undefined\n /** The whole message (title, blank line, body), when the host gives it. */\n message?: string | undefined\n}\n\n/** A merge request (GitLab) or a pull request (GitHub). */\nexport interface ChangeRequest {\n number: number\n title: string\n sourceBranch: string\n targetBranch: string\n webUrl: string\n hasConflicts: boolean\n /** `opened`, `merged` or `closed`. Only the lists that ask for every state fill what follows. */\n state?: 'opened' | 'merged' | 'closed' | undefined\n author?: string | undefined\n createdAt?: string | undefined\n mergedAt?: string | null | undefined\n /** The commit at the tip of the source branch: the one its checks are for. */\n headSha?: string | undefined\n}\n\n/** An issue, as every host shows it. `number` is the one of the repository (GitLab `iid`, GitHub `number`). */\n/** The difference between two refs: what `to` brought since it left `from`. */\nexport interface Comparison {\n commits: CommitSummary[]\n files: FileDiff[]\n}\n\nexport interface Issue {\n number: number\n title: string\n /** Markdown. */\n description: string\n state: 'opened' | 'closed'\n author: string | undefined\n assignees: string[]\n labels: string[]\n /** The title of the milestone it belongs to. */\n milestone: string | null\n createdAt: string\n updatedAt: string\n closedAt: string | null\n /** The page of the issue on the host (empty for a host that has no pages). */\n webUrl: string\n commentCount: number\n}\n\n/** One message of the thread of an issue. */\nexport interface Comment {\n id: Id\n author: string | undefined\n /** Markdown. */\n body: string\n createdAt: string\n updatedAt: string\n}\n\n/** A release of a tag: what the host shows as the release notes of a version. `tag` is its key (one release per tag). */\nexport interface Release {\n tag: string\n name: string\n /** Markdown. */\n description: string\n createdAt: string\n /** The page of it on the host (empty for a host that has no pages). */\n url: string\n prerelease: boolean\n}\n\nexport interface ReleaseChanges {\n name?: string\n description?: string\n prerelease?: boolean\n}\n\nexport interface Label {\n name: string\n /** `#rrggbb`, when the host has colours for labels. */\n color?: string | undefined\n}\n\nexport interface Milestone {\n title: string\n state: 'opened' | 'closed'\n dueDate?: string | null | undefined\n}\n\nexport interface IssueFilter {\n /** Default `opened`. */\n state?: 'opened' | 'closed' | 'all'\n author?: string\n assignee?: string\n /** All of them. */\n labels?: string[]\n /** The title of a milestone. */\n milestone?: string\n /** Text in the title or the description. */\n search?: string\n /** From 1. */\n page?: number\n /** Default 20, at most 100. */\n perPage?: number\n}\n\n/** One page of a list. A host does not always know how many there are in all: `hasMore` is what every host can say. */\nexport interface Page<T> {\n items: T[]\n page: number\n perPage: number\n hasMore: boolean\n}\n\nexport interface IssueChanges {\n title?: string\n description?: string\n labels?: string[]\n assignees?: string[]\n /** The title of a milestone; `null` takes the issue out of its milestone. */\n milestone?: string | null\n state?: 'opened' | 'closed'\n}\n\n/**\n * What a host can do beyond the common part. The UI offers only what is `true`, and a call for something that is not is refused with\n * status 400 rather than ignored.\n */\n/** A repository the host is about to delete for good. */\nexport interface PendingDeletion {\n id: Id\n name: string\n /** Where it was, as it was called before the host renamed it for the deletion. */\n path: string\n /** Its page now, with whatever name the host gave it for the deletion: the only address that opens. */\n webUrl: string\n namespaceId: Id | undefined\n /** The namespace that contains this repository's namespace (for a product: the one that is its line). */\n parentNamespaceId?: Id | undefined\n /** The day the host deletes it for good; `null` when the host does not say. */\n deletesOn: string | null\n /** When the host made the repository, if it says. */\n createdAt?: string\n repositoryScheduled: boolean\n namespaceScheduled: boolean\n /** Something above its namespace waits to be deleted: it cannot come back before that does. */\n ancestorScheduled: boolean\n}\n\nexport type TemplateKind = 'issue' | 'mergeRequest'\n\nexport interface Template {\n name: string\n content: string\n}\n\nexport interface Capabilities {\n issues: {\n labels: boolean\n milestones: boolean\n assignees: boolean\n closingWords: boolean\n }\n templates: {\n editable: boolean\n }\n mergeRequests: {\n labels: boolean\n reviewers: boolean\n /** Approvals can be given (and counted). */\n approvals: boolean\n /** A thread of the code can be marked resolved. */\n resolvableThreads: boolean\n /** A merge can leave one commit. */\n squash: boolean\n }\n deletion: {\n namespaceIsRepository: boolean\n delayed: boolean\n }\n releases: {\n /** A release can be marked as a prerelease (GitLab has no such mark: it ignores it and always says `false`). */\n prerelease: boolean\n }\n}\n\n/** A merge request (GitLab) or a pull request (GitHub) as the pages of LINEA show it: more than `ChangeRequest`, which is what the code needs. */\nexport interface MergeRequest {\n number: number\n title: string\n /** Markdown. */\n description: string\n state: 'opened' | 'merged' | 'closed'\n author: string | undefined\n sourceBranch: string\n targetBranch: string\n labels: string[]\n reviewers: string[]\n assignees: string[]\n createdAt: string\n updatedAt: string\n mergedAt: string | null\n /** The page of it on the host (empty for a host that has no pages). */\n webUrl: string\n hasConflicts: boolean\n /** The commit at the tip of the source branch: the one its checks are for. */\n headSha: string | undefined\n /** Messages of people in all its threads. */\n commentCount: number\n /** Who approved it, and how many approvals it asks for (`null`: it does not say). Only on a host that has approvals. */\n approvals?: { required: number | null, given: string[] } | undefined\n}\n\nexport interface MergeRequestFilter {\n /** Default `opened`. */\n state?: 'opened' | 'merged' | 'closed' | 'all'\n author?: string\n reviewer?: string\n labels?: string[]\n search?: string\n sourceBranch?: string\n targetBranch?: string\n page?: number\n perPage?: number\n}\n\n/** One file of the code a merge request proposes. `patch` is the unified diff from the first `@@` on (empty for a file git cannot show, as a binary one). */\nexport interface FileDiff {\n oldPath: string\n newPath: string\n status: 'added' | 'modified' | 'deleted' | 'renamed'\n additions: number\n deletions: number\n patch: string\n}\n\n/** A line of the code of a merge request: of the new version of the file, or (`old`) of the one it replaces. */\nexport interface DiffPosition {\n path: string\n line: number\n side: 'new' | 'old'\n}\n\n/** A conversation of a merge request: a message of its own, or a line of the code with what was said about it. */\nexport interface Thread {\n id: Id\n /** The host can mark it resolved (GitHub can only through an API LINEA does not use). */\n resolvable: boolean\n resolved: boolean\n /** The line it is about; none for a general message. */\n position?: DiffPosition | undefined\n comments: Comment[]\n}\n\nexport interface MergeOptions {\n /** One commit in the target instead of the history of the branch. */\n squash?: boolean\n deleteSourceBranch?: boolean\n /** The message of the commit that is made. */\n message?: string\n}\n\nexport interface MergeRequestChanges {\n title?: string\n description?: string\n labels?: string[]\n reviewers?: string[]\n /** Closing and reopening are `state`. */\n state?: 'opened' | 'closed'\n}\n\nexport interface FileAction {\n action: 'create' | 'update' | 'delete'\n path: string\n content?: string\n /** How `content` is written (default text). */\n encoding?: 'text' | 'base64'\n /** Refuse the change when the file moved on from this revision (status 409). */\n expectedRevision?: string\n}\n\nexport interface Pipeline {\n /** The id the host gives it, for asking about its jobs or running it again. */\n id?: Id\n /** The commit it ran for. */\n sha?: string\n /** `success`, `failed`, `running`, `pending`, `canceled`, `skipped`. */\n status: string\n ref: string\n createdAt: string\n webUrl: string\n}\n\n/** One step of a pipeline (a job of GitLab, a job of a workflow run of GitHub). */\nexport interface PipelineJob {\n id: Id\n name: string\n /** The stage it belongs to (GitHub has none: its jobs are all `jobs`). */\n stage: string\n /** `success`, `failed`, `running`, `pending`, `canceled`, `skipped`. */\n status: string\n /** Seconds, when it has started. */\n duration: number | null\n webUrl: string\n}\n\n/** A runner of the host's CI, as it shows for a repository. */\nexport interface Runner {\n id: Id\n description: string\n online: boolean\n paused: boolean\n /** A runner shared by the whole instance (not one of the repository). */\n shared: boolean\n /** Jobs that ask for none of these tags are not run by it, unless it takes untagged jobs. */\n tags: string[]\n runsUntagged: boolean\n}\n\n/** What the host's CI offers a repository: whether it has runners to take its jobs. */\nexport interface CiRunners {\n /** `false` for a host that runs no pipelines (or whose runners cannot be asked for). */\n supported: boolean\n /** Whether the runners of the whole instance take this repository's jobs (`null`: not asked, or not a thing of this host). */\n instanceRunners: boolean | null\n /** `false` when the host would not list them for this token: `runners` being empty then says nothing. */\n listed?: boolean\n runners: Runner[]\n}\n\nexport interface Tokens {\n accessToken: string\n refreshToken: string | null\n}\n\nexport interface AuthConfig {\n kind: GitHostKind\n clientId: string | undefined\n redirectUri: string\n /** The address of the host's website. */\n url: string\n /** Where a browser is sent to log in; add `client_id`, `redirect_uri`, `response_type=code`, `scope` and `state`. */\n authorizeUrl: string\n /** What to ask the user to allow. */\n scope: string\n}\n\nexport type GitHostKind = 'local' | 'gitlab' | 'github'\n\nexport interface Delivery {\n headers: Record<string, string | undefined>\n rawBody?: Buffer | string\n secret?: string\n}\n\nexport interface GitProvider {\n readonly kind: GitHostKind\n /** Whether a namespace can hold namespaces (GitLab groups do; a GitHub account cannot). */\n readonly nestsNamespaces: boolean\n readonly webhookPath: string\n\n // Identity\n authConfig(): AuthConfig\n exchangeCode(args: { code: string, redirectUri: string }): Promise<Tokens>\n /** Keeps `accessToken` when the host's tokens do not expire. */\n refreshToken(args: { refreshToken: string | null, accessToken: string }): Promise<Tokens>\n getUser(args: { token: string }): Promise<{ username: string, avatarUrl: string }>\n\n // Namespaces: the place repositories live in\n /** Where the user may create things. */\n listNamespaces(args: { token: string }): Promise<Namespace[]>\n findNamespace(args: { token: string, fullPath: string }): Promise<Namespace | null>\n createNamespace(args: { token: string, name: string, parentId?: Id | undefined }): Promise<Namespace>\n /** With everything in it. */\n deleteNamespace(args: { token: string, id: Id }): Promise<unknown>\n renameNamespace(args: { token: string, id: Id, name: string }): Promise<unknown>\n\n // Repositories\n createRepository(args: { token: string, name: string, namespaceId?: Id | undefined, topics?: string[], defaultBranch?: string | undefined }): Promise<Repository>\n deleteRepository(args: { token: string, id: Id }): Promise<unknown>\n /** The repositories with this topic the user reaches that wait to be deleted; a host that deletes at once has none. */\n listPendingDeletion(args: { token: string, topic: string }): Promise<PendingDeletion[]>\n restoreRepository(args: { token: string, id: Id }): Promise<unknown>\n restoreNamespace(args: { token: string, id: Id }): Promise<unknown>\n renameRepository(args: { token: string, id: Id, name: string }): Promise<Repository>\n getRepository(args: { token: string, id: Id }): Promise<Repository>\n /** By its full path; `null` when there is none. */\n findRepository(args: { token: string, path: string }): Promise<Repository | null>\n /** The live repositories of the user that have a topic. */\n listRepositories(args: { token: string, topic: string }): Promise<Repository[]>\n addTopic(args: { token: string, id: Id, topic: string }): Promise<void>\n setDefaultBranch(args: { token: string, id: Id, branch: string }): Promise<unknown>\n getMembers(args: { token: string, id: Id }): Promise<Member[]>\n /** The level of the user of `token` on the repository (0: none). */\n getAccessLevel(args: { token: string, id: Id, username: string }): Promise<number>\n\n // Files, commits, archives\n getFile(args: { token: string, id: Id, path: string, ref: string }): Promise<RepositoryFile>\n /** Like `getFile`, never remembered for rollback. */\n getFileRevision(args: { token: string, id: Id, path: string, ref: string }): Promise<RepositoryFile>\n /** The bytes, or `null` when there is no such file. */\n readFile(args: { token: string, id: Id, path: string, ref: string }): Promise<Buffer | null>\n /** Every file of a repository at `ref`. */\n listFiles(args: { token: string, id: Id, ref: string }): Promise<string[]>\n createFile(args: { token: string, id: Id, path: string, branch: string, content: string }): Promise<unknown>\n saveFile(args: { token: string, id: Id, path: string, branch: string, content: string }): Promise<unknown>\n commit(args: { token: string, id: Id, branch: string, message: string, actions: FileAction[], track?: boolean }): Promise<{ id: string }>\n /** A zip of the repository at `ref`. */\n downloadArchive(args: { token: string, id: Id, ref?: string }): Promise<NodeJS.ReadableStream>\n getCommits(args: { token: string, id: Id, ref: string, perPage?: number }): Promise<CommitSummary[]>\n /** What `to` has that `from` has not: its commits (newest first) and the files they change, as the host's own comparison shows them. */\n compare(args: { token: string, id: Id, from: string, to: string }): Promise<Comparison>\n\n // Branches and tags\n createBranch(args: { token: string, id: Id, branch: string, ref: string, track?: boolean }): Promise<unknown>\n /** The names of the branches of a repository. */\n listBranches(args: { token: string, id: Id }): Promise<string[]>\n getBranch(args: { token: string, id: Id, branch: string }): Promise<{ name: string, lastCommit: CommitSummary | null }>\n listTags(args: { token: string, id: Id }): Promise<{ name: string }[]>\n /** `message` is the annotation of the tag (null for one that has none): what `createTag` was given. */\n getTag(args: { token: string, id: Id, tag: string }): Promise<{ name: string, commitId: string, message: string | null } | null>\n createTag(args: { token: string, id: Id, tag: string, ref: string, message?: string }): Promise<unknown>\n\n // Releases: one per tag. Creating the release of a tag that has one fails with an \"already exists\" error (`isAlreadyExistsError`) and\n // leaves it as it was; `updateRelease` is the way to change it. A tag that does not exist is refused with status 404.\n /** `name` defaults to the tag. `prerelease` is ignored by a host whose `capabilities().releases.prerelease` is `false`. */\n createRelease(args: { token: string, id: Id, tag: string, name?: string, description?: string, prerelease?: boolean }): Promise<Release>\n /** `null` when the tag has no release. */\n getRelease(args: { token: string, id: Id, tag: string }): Promise<Release | null>\n /** Newest first. */\n listReleases(args: { token: string, id: Id }): Promise<Release[]>\n /** Only what is in `changes` is touched (`prerelease` only where the host has it); status 404 when the tag has no release. */\n updateRelease(args: { token: string, id: Id, tag: string, changes: ReleaseChanges }): Promise<Release>\n\n // Change requests\n createChangeRequest(args: { token: string, id: Id, title: string, sourceBranch: string, targetBranch: string }): Promise<ChangeRequest>\n createOrRenameChangeRequest(args: { token: string, id: Id, title: string, sourceBranch: string, targetBranch?: string }): Promise<ChangeRequest>\n listChangeRequests(args: { token: string, id: Id, state?: 'opened' | 'merged' | 'closed' | 'all', targetBranch?: string }): Promise<ChangeRequest[]>\n /** The pipelines that ran for a change request (its checks), newest first. */\n listChangeRequestPipelines(args: { token: string, id: Id, number: number }): Promise<Pipeline[]>\n /** Merges it when it can; `true` when it has conflicts (or is not open). */\n mergeChangeRequest(args: { token: string, id: Id, number: number, deleteSourceBranch?: boolean }): Promise<boolean>\n\n // Issues\n capabilities(): Capabilities\n listIssues(args: { token: string, id: Id, filter?: IssueFilter }): Promise<Page<Issue>>\n getIssue(args: { token: string, id: Id, number: number }): Promise<Issue>\n createIssue(args: { token: string, id: Id, title: string, description?: string, labels?: string[], assignees?: string[], milestone?: string | null }): Promise<Issue>\n /** Only what is in `changes` is touched. Closing and reopening are `state`. */\n updateIssue(args: { token: string, id: Id, number: number, changes: IssueChanges }): Promise<Issue>\n /** The messages the people wrote, oldest first (what the host writes by itself, \"changed the label\", is left out). */\n listIssueComments(args: { token: string, id: Id, number: number }): Promise<Comment[]>\n addIssueComment(args: { token: string, id: Id, number: number, body: string }): Promise<Comment>\n listLabels(args: { token: string, id: Id }): Promise<Label[]>\n listMilestones(args: { token: string, id: Id }): Promise<Milestone[]>\n\n listTemplates(args: { token: string, id: Id, kind: TemplateKind }): Promise<Template[]>\n saveTemplate(args: { token: string, id: Id, kind: TemplateKind, name: string, content: string }): Promise<Template>\n deleteTemplate(args: { token: string, id: Id, kind: TemplateKind, name: string }): Promise<void>\n\n // Merge requests (the part of them the pages need; `createChangeRequest` and the rest are what the code needs)\n listMergeRequests(args: { token: string, id: Id, filter?: MergeRequestFilter }): Promise<Page<MergeRequest>>\n getMergeRequest(args: { token: string, id: Id, number: number }): Promise<MergeRequest>\n createMergeRequest(args: { token: string, id: Id, title: string, description?: string, sourceBranch: string, targetBranch: string, labels?: string[], reviewers?: string[] }): Promise<MergeRequest>\n /** Only what is in `changes` is touched. */\n updateMergeRequest(args: { token: string, id: Id, number: number, changes: MergeRequestChanges }): Promise<MergeRequest>\n /** The files it changes, as the target would see them after the merge. */\n getMergeRequestDiff(args: { token: string, id: Id, number: number }): Promise<FileDiff[]>\n /** Every conversation, oldest first: the general messages and the ones about lines of the code. */\n listMergeRequestThreads(args: { token: string, id: Id, number: number }): Promise<Thread[]>\n /** A general message, one about a line (`position`), or an answer in a thread (`threadId`). Answers with the thread it is in. */\n addMergeRequestComment(args: { token: string, id: Id, number: number, body: string, position?: DiffPosition, threadId?: Id }): Promise<Thread>\n setThreadResolved(args: { token: string, id: Id, number: number, threadId: Id, resolved: boolean }): Promise<Thread>\n /** Merges it; `true` when it has conflicts (or is not open), as `mergeChangeRequest`. */\n mergeMergeRequest(args: { token: string, id: Id, number: number, options?: MergeOptions }): Promise<boolean>\n /** Gives the approval of the user of `token` (a host with no approvals refuses with status 400). */\n approveMergeRequest(args: { token: string, id: Id, number: number }): Promise<void>\n\n // CI and hooks\n getLatestPipeline(args: { token: string, id: Id, ref: string }): Promise<Pipeline | null>\n /** The last pipelines of a branch (or of the repository, without `ref`), newest first. */\n listPipelines(args: { token: string, id: Id, ref?: string, perPage?: number }): Promise<Pipeline[]>\n /** The jobs of a pipeline, in the order they run. */\n getPipelineJobs(args: { token: string, id: Id, pipelineId: Id }): Promise<PipelineJob[]>\n /** Runs the failed jobs of a pipeline again. */\n retryPipeline(args: { token: string, id: Id, pipelineId: Id }): Promise<void>\n /** Stops a pipeline that has not finished: its running and waiting jobs are canceled. */\n cancelPipeline(args: { token: string, id: Id, pipelineId: Id }): Promise<void>\n /** Makes sure a repository can run pipelines (a project made with CI/CD switched off gets it switched on). Answers whether it changed anything. */\n enablePipelines(args: { token: string, id: Id }): Promise<boolean>\n /** Turns CI/CD off for a repository; `true` when it had to be changed. A host where that is not the repository's to choose does nothing. */\n disablePipelines(args: { token: string, id: Id }): Promise<boolean>\n /** Whether CI/CD is on for a repository; `null` when the host does not say, or it is not a thing of this host. */\n pipelinesEnabled(args: { token: string, id: Id }): Promise<boolean | null>\n /** Stops one job that has not finished (hosts that cannot cancel a single job say so). */\n cancelJob(args: { token: string, id: Id, jobId: Id }): Promise<void>\n /** The runners that can take the jobs of a repository, and whether the instance's own are turned on for it. */\n getCiRunners(args: { token: string, id: Id }): Promise<CiRunners>\n /** Turns on (or off) the runners of the whole instance for a repository. */\n setInstanceRunners(args: { token: string, id: Id, enabled: boolean }): Promise<void>\n /** The end of what a job printed (the last `lines`). */\n getJobTrace(args: { token: string, id: Id, jobId: Id, lines?: number }): Promise<string>\n ensureWebhook(args: { token: string, id: Id, url: string, secret: string, branch?: string }): Promise<{ status: 'created' | 'already_exists', hookId?: Id | null }>\n verifyWebhook(args: Required<Delivery>): boolean\n parsePushEvent(args: { headers: Record<string, string | undefined>, body: any }): { repositoryId: Id, branch: string } | null\n\n // Unit of work, errors\n rollback(): Promise<void>\n /** The token is expired or revoked. */\n isAuthError(error: unknown): boolean\n /** A branch (or other ref) that exists already. */\n isAlreadyExistsError(error: unknown): boolean\n}\n\n/** The methods a provider has to have: what the contract test checks and what a new host has to fill in. */\nexport const GIT_PROVIDER_METHODS = [\n 'authConfig', 'exchangeCode', 'refreshToken', 'getUser',\n 'listNamespaces', 'findNamespace', 'createNamespace', 'deleteNamespace', 'renameNamespace',\n 'createRepository', 'deleteRepository', 'listPendingDeletion', 'restoreRepository', 'restoreNamespace', 'renameRepository', 'getRepository', 'findRepository', 'listRepositories', 'addTopic',\n 'setDefaultBranch', 'getMembers', 'getAccessLevel',\n 'getFile', 'getFileRevision', 'readFile', 'listFiles', 'createFile', 'saveFile', 'commit', 'downloadArchive', 'getCommits', 'compare',\n 'createBranch', 'listBranches', 'getBranch', 'listTags', 'getTag', 'createTag',\n 'createRelease', 'getRelease', 'listReleases', 'updateRelease',\n 'createChangeRequest', 'createOrRenameChangeRequest', 'listChangeRequests', 'listChangeRequestPipelines', 'mergeChangeRequest',\n 'getLatestPipeline', 'listPipelines', 'getPipelineJobs', 'retryPipeline', 'cancelPipeline', 'cancelJob', 'enablePipelines', 'disablePipelines', 'pipelinesEnabled', 'getCiRunners', 'setInstanceRunners', 'getJobTrace', 'ensureWebhook', 'verifyWebhook', 'parsePushEvent',\n 'listMergeRequests', 'getMergeRequest', 'createMergeRequest', 'updateMergeRequest', 'getMergeRequestDiff', 'listMergeRequestThreads', 'addMergeRequestComment', 'setThreadResolved', 'mergeMergeRequest', 'approveMergeRequest',\n 'capabilities', 'listIssues', 'getIssue', 'createIssue', 'updateIssue', 'listIssueComments', 'addIssueComment', 'listLabels', 'listMilestones', 'listTemplates', 'saveTemplate', 'deleteTemplate',\n 'rollback', 'isAuthError', 'isAlreadyExistsError'\n] as const\n"]}
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA4mBH,4GAA4G;AAC5G,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,SAAS;IACvD,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB;IAC1F,kBAAkB,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,UAAU;IAC7L,kBAAkB,EAAE,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa;IAC5G,SAAS,EAAE,iBAAiB,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,iBAAiB,EAAE,YAAY,EAAE,SAAS;IACrI,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW;IAC9E,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,eAAe;IAC9D,qBAAqB,EAAE,6BAA6B,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,oBAAoB;IAC9H,mBAAmB,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,gBAAgB,EAAE,WAAW,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,cAAc,EAAE,oBAAoB,EAAE,aAAa,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB;IAC3Q,mBAAmB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,qBAAqB;IAC/N,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB;IACzN,UAAU,EAAE,aAAa,EAAE,sBAAsB;CACzC,CAAA","sourcesContent":["/**\n * The git host LINEA works on (GitLab, or GitHub): everything LINEA needs from it, in the host's own words left out.\n *\n * A deployment talks to ONE host. The server and the CLI never speak a host's API: they take a `GitProvider` (`createGitProvider`) and\n * use only the methods below, with the shapes below. What differs between hosts is hidden in the provider: GitLab calls the same things\n * groups, projects and merge requests; GitHub calls them organisations, repositories and pull requests, and has no groups inside\n * groups (see docs/git-provider.md for how each difference is absorbed).\n *\n * A provider object is also a unit of work: what it creates (namespaces, repositories, files, commits, branches, tags) is remembered,\n * and `rollback()` undoes it, newest first. Make one per operation.\n *\n * Every method takes the user's access `token` first. `id` is the repository id (or its `path`), `namespaceId` the id of a namespace.\n */\n\nexport type Id = number | string\n\nexport interface Repository {\n id: Id\n name: string\n /** Full path as the host shows it: `group/sub/name`, `owner/name`. */\n path: string\n description: string\n webUrl: string\n webIdeUrl: string\n namespaceId: Id | undefined\n /** The namespace that contains this repository's namespace (for a product: the one that is its line). */\n parentNamespaceId?: Id | undefined\n defaultBranch?: string | undefined\n topics: string[]\n /** When the host made it (a host that does not keep it says nothing). */\n createdAt?: string | undefined\n}\n\nexport interface Namespace {\n id: Id\n fullPath: string\n name: string\n /** Made by `createNamespace` but not yet on the host: the repository that follows is what creates it. */\n pending?: boolean\n}\n\nexport interface Member {\n username: string\n /** 10 guest, 20 reporter/read, 30 developer/write, 40 maintainer, 50 owner/admin. */\n accessLevel: number\n}\n\n/** Who has access to a repository, at what level and where the access comes from. */\nexport interface AccessEntry {\n username: string\n /** One of the four levels of LINEA: 20 reporter, 30 developer, 40 maintainer, 50 owner. */\n accessLevel: number\n /** `direct`: set on the repository itself; `inherited`: from the group or organization that holds it. */\n source: 'direct' | 'inherited'\n}\n\n/** A person of a host, as `searchUsers` finds them. */\nexport interface HostUser {\n username: string\n name: string\n avatarUrl: string | null\n}\n\nexport interface RepositoryFile {\n path: string\n name: string\n /** base64 */\n content: string\n encoding: 'base64'\n /** What to quote to say \"I changed this file starting from this version\" (GitLab: last commit id; GitHub: blob sha). */\n revision: string\n}\n\nexport interface CommitSummary {\n shortId: string\n title: string\n authorName: string\n createdAt: string\n webUrl?: string | undefined\n /** The whole message (title, blank line, body), when the host gives it. */\n message?: string | undefined\n}\n\n/** A merge request (GitLab) or a pull request (GitHub). */\nexport interface ChangeRequest {\n number: number\n title: string\n sourceBranch: string\n targetBranch: string\n webUrl: string\n hasConflicts: boolean\n /** `opened`, `merged` or `closed`. Only the lists that ask for every state fill what follows. */\n state?: 'opened' | 'merged' | 'closed' | undefined\n author?: string | undefined\n createdAt?: string | undefined\n mergedAt?: string | null | undefined\n /** The commit at the tip of the source branch: the one its checks are for. */\n headSha?: string | undefined\n}\n\n/** An issue, as every host shows it. `number` is the one of the repository (GitLab `iid`, GitHub `number`). */\n/** The difference between two refs: what `to` brought since it left `from`. */\nexport interface Comparison {\n commits: CommitSummary[]\n files: FileDiff[]\n}\n\nexport interface Issue {\n number: number\n title: string\n /** Markdown. */\n description: string\n state: 'opened' | 'closed'\n author: string | undefined\n assignees: string[]\n labels: string[]\n /** The title of the milestone it belongs to. */\n milestone: string | null\n createdAt: string\n updatedAt: string\n closedAt: string | null\n /** The page of the issue on the host (empty for a host that has no pages). */\n webUrl: string\n commentCount: number\n}\n\n/** One message of the thread of an issue. */\nexport interface Comment {\n id: Id\n author: string | undefined\n /** Markdown. */\n body: string\n createdAt: string\n updatedAt: string\n}\n\n/** A label put on an issue or taken off it: by whom and when. */\nexport interface LabelEvent {\n label: string\n action: 'added' | 'removed'\n author: string | undefined\n createdAt: string\n}\n\n/** A release of a tag: what the host shows as the release notes of a version. `tag` is its key (one release per tag). */\nexport interface Release {\n tag: string\n name: string\n /** Markdown. */\n description: string\n createdAt: string\n /** The page of it on the host (empty for a host that has no pages). */\n url: string\n prerelease: boolean\n}\n\nexport interface ReleaseChanges {\n name?: string\n description?: string\n prerelease?: boolean\n}\n\nexport interface Label {\n name: string\n /** `#rrggbb`, when the host has colours for labels. */\n color?: string | undefined\n}\n\nexport interface Milestone {\n title: string\n state: 'opened' | 'closed'\n dueDate?: string | null | undefined\n}\n\nexport interface IssueFilter {\n /** Default `opened`. */\n state?: 'opened' | 'closed' | 'all'\n author?: string\n assignee?: string\n /** All of them. */\n labels?: string[]\n /** The title of a milestone. */\n milestone?: string\n /** Text in the title or the description. */\n search?: string\n /** From 1. */\n page?: number\n /** Default 20, at most 100. */\n perPage?: number\n}\n\n/** One page of a list. A host does not always know how many there are in all: `hasMore` is what every host can say. */\nexport interface Page<T> {\n items: T[]\n page: number\n perPage: number\n hasMore: boolean\n}\n\nexport interface IssueChanges {\n title?: string\n description?: string\n labels?: string[]\n assignees?: string[]\n /** The title of a milestone; `null` takes the issue out of its milestone. */\n milestone?: string | null\n state?: 'opened' | 'closed'\n}\n\n/**\n * What a host can do beyond the common part. The UI offers only what is `true`, and a call for something that is not is refused with\n * status 400 rather than ignored.\n */\n/** A repository the host is about to delete for good. */\nexport interface PendingDeletion {\n id: Id\n name: string\n /** Where it was, as it was called before the host renamed it for the deletion. */\n path: string\n /** Its page now, with whatever name the host gave it for the deletion: the only address that opens. */\n webUrl: string\n namespaceId: Id | undefined\n /** The namespace that contains this repository's namespace (for a product: the one that is its line). */\n parentNamespaceId?: Id | undefined\n /** The day the host deletes it for good; `null` when the host does not say. */\n deletesOn: string | null\n /** When the host made the repository, if it says. */\n createdAt?: string\n repositoryScheduled: boolean\n namespaceScheduled: boolean\n /** Something above its namespace waits to be deleted: it cannot come back before that does. */\n ancestorScheduled: boolean\n}\n\nexport type TemplateKind = 'issue' | 'mergeRequest'\n\nexport interface Template {\n name: string\n content: string\n}\n\nexport interface Capabilities {\n issues: {\n labels: boolean\n milestones: boolean\n assignees: boolean\n closingWords: boolean\n }\n templates: {\n editable: boolean\n }\n mergeRequests: {\n labels: boolean\n reviewers: boolean\n /** Approvals can be given (and counted). */\n approvals: boolean\n /** A thread of the code can be marked resolved. */\n resolvableThreads: boolean\n /** A merge can leave one commit. */\n squash: boolean\n }\n deletion: {\n namespaceIsRepository: boolean\n delayed: boolean\n }\n releases: {\n /** A release can be marked as a prerelease (GitLab has no such mark: it ignores it and always says `false`). */\n prerelease: boolean\n }\n}\n\n/** A merge request (GitLab) or a pull request (GitHub) as the pages of LINEA show it: more than `ChangeRequest`, which is what the code needs. */\nexport interface MergeRequest {\n number: number\n title: string\n /** Markdown. */\n description: string\n state: 'opened' | 'merged' | 'closed'\n author: string | undefined\n sourceBranch: string\n targetBranch: string\n labels: string[]\n reviewers: string[]\n assignees: string[]\n createdAt: string\n updatedAt: string\n mergedAt: string | null\n /** The page of it on the host (empty for a host that has no pages). */\n webUrl: string\n hasConflicts: boolean\n /** The commit at the tip of the source branch: the one its checks are for. */\n headSha: string | undefined\n /** Messages of people in all its threads. */\n commentCount: number\n /** Who approved it, and how many approvals it asks for (`null`: it does not say). Only on a host that has approvals. */\n approvals?: { required: number | null, given: string[] } | undefined\n}\n\nexport interface MergeRequestFilter {\n /** Default `opened`. */\n state?: 'opened' | 'merged' | 'closed' | 'all'\n author?: string\n reviewer?: string\n labels?: string[]\n search?: string\n sourceBranch?: string\n targetBranch?: string\n page?: number\n perPage?: number\n}\n\n/** One file of the code a merge request proposes. `patch` is the unified diff from the first `@@` on (empty for a file git cannot show, as a binary one). */\nexport interface FileDiff {\n oldPath: string\n newPath: string\n status: 'added' | 'modified' | 'deleted' | 'renamed'\n additions: number\n deletions: number\n patch: string\n}\n\n/** A line of the code of a merge request: of the new version of the file, or (`old`) of the one it replaces. */\nexport interface DiffPosition {\n path: string\n line: number\n side: 'new' | 'old'\n}\n\n/** A conversation of a merge request: a message of its own, or a line of the code with what was said about it. */\nexport interface Thread {\n id: Id\n /** The host can mark it resolved (GitHub can only through an API LINEA does not use). */\n resolvable: boolean\n resolved: boolean\n /** The line it is about; none for a general message. */\n position?: DiffPosition | undefined\n comments: Comment[]\n}\n\nexport interface MergeOptions {\n /** One commit in the target instead of the history of the branch. */\n squash?: boolean\n deleteSourceBranch?: boolean\n /** The message of the commit that is made. */\n message?: string\n}\n\nexport interface MergeRequestChanges {\n title?: string\n description?: string\n labels?: string[]\n reviewers?: string[]\n /** Closing and reopening are `state`. */\n state?: 'opened' | 'closed'\n}\n\nexport interface FileAction {\n action: 'create' | 'update' | 'delete'\n path: string\n content?: string\n /** How `content` is written (default text). */\n encoding?: 'text' | 'base64'\n /** Refuse the change when the file moved on from this revision (status 409). */\n expectedRevision?: string\n}\n\nexport interface Pipeline {\n /** The id the host gives it, for asking about its jobs or running it again. */\n id?: Id\n /** The commit it ran for. */\n sha?: string\n /** `success`, `failed`, `running`, `pending`, `canceled`, `skipped`. */\n status: string\n ref: string\n createdAt: string\n webUrl: string\n}\n\n/** One step of a pipeline (a job of GitLab, a job of a workflow run of GitHub). */\nexport interface PipelineJob {\n id: Id\n name: string\n /** The stage it belongs to (GitHub has none: its jobs are all `jobs`). */\n stage: string\n /** `success`, `failed`, `running`, `pending`, `canceled`, `skipped`. */\n status: string\n /** Seconds, when it has started. */\n duration: number | null\n webUrl: string\n}\n\n/** A runner of the host's CI, as it shows for a repository. */\nexport interface Runner {\n id: Id\n description: string\n online: boolean\n paused: boolean\n /** A runner shared by the whole instance (not one of the repository). */\n shared: boolean\n /** Jobs that ask for none of these tags are not run by it, unless it takes untagged jobs. */\n tags: string[]\n runsUntagged: boolean\n}\n\n/** What the host's CI offers a repository: whether it has runners to take its jobs. */\nexport interface CiRunners {\n /** `false` for a host that runs no pipelines (or whose runners cannot be asked for). */\n supported: boolean\n /** Whether the runners of the whole instance take this repository's jobs (`null`: not asked, or not a thing of this host). */\n instanceRunners: boolean | null\n /** `false` when the host would not list them for this token: `runners` being empty then says nothing. */\n listed?: boolean\n runners: Runner[]\n}\n\nexport interface Tokens {\n accessToken: string\n refreshToken: string | null\n}\n\n/** What the person is shown to approve a sign-in from a machine with no browser (the OAuth device authorization grant). */\nexport interface DeviceAuthorization {\n /** Kept by the client and given back to poll; useless without the host's OAuth app secret on confidential apps. */\n deviceCode: string\n userCode: string\n verificationUri: string\n verificationUriComplete?: string | undefined\n /** Seconds the codes last. */\n expiresIn: number\n /** Seconds to wait between polls. */\n interval: number\n}\n\nexport type DevicePoll =\n | { status: 'pending', interval: number }\n | { status: 'done', tokens: Tokens }\n\nexport interface AuthConfig {\n kind: GitHostKind\n clientId: string | undefined\n redirectUri: string\n /** The address of the host's website. */\n url: string\n /** Where a browser is sent to log in; add `client_id`, `redirect_uri`, `response_type=code`, `scope` and `state`. */\n authorizeUrl: string\n /** What to ask the user to allow. */\n scope: string\n}\n\nexport type GitHostKind = 'local' | 'gitlab' | 'github'\n\nexport interface Delivery {\n headers: Record<string, string | undefined>\n rawBody?: Buffer | string\n secret?: string\n}\n\nexport interface GitProvider {\n readonly kind: GitHostKind\n /** Whether a namespace can hold namespaces (GitLab groups do; a GitHub account cannot). */\n readonly nestsNamespaces: boolean\n readonly webhookPath: string\n\n // Identity\n authConfig(): AuthConfig\n exchangeCode(args: { code: string, redirectUri: string }): Promise<Tokens>\n /** Keeps `accessToken` when the host's tokens do not expire. */\n refreshToken(args: { refreshToken: string | null, accessToken: string }): Promise<Tokens>\n getUser(args: { token: string }): Promise<{ username: string, avatarUrl: string }>\n /**\n * Device authorization: for hosts that have it (GitLab, GitHub), not part of GIT_PROVIDER_METHODS. Rejects with `GitDeviceFlowError`\n * (`unsupported` when the host has no such flow); polling rejects with `expired_token` / `access_denied` when it cannot go on.\n */\n startDeviceAuthorization?(args?: { scope?: string }): Promise<DeviceAuthorization>\n pollDeviceAuthorization?(args: { deviceCode: string, interval?: number }): Promise<DevicePoll>\n\n // Namespaces: the place repositories live in\n /** Where the user may create things. */\n listNamespaces(args: { token: string }): Promise<Namespace[]>\n findNamespace(args: { token: string, fullPath: string }): Promise<Namespace | null>\n createNamespace(args: { token: string, name: string, parentId?: Id | undefined }): Promise<Namespace>\n /** With everything in it. */\n deleteNamespace(args: { token: string, id: Id }): Promise<unknown>\n renameNamespace(args: { token: string, id: Id, name: string }): Promise<unknown>\n\n // Repositories\n createRepository(args: { token: string, name: string, namespaceId?: Id | undefined, topics?: string[], defaultBranch?: string | undefined }): Promise<Repository>\n deleteRepository(args: { token: string, id: Id }): Promise<unknown>\n /** The repositories with this topic the user reaches that wait to be deleted; a host that deletes at once has none. */\n listPendingDeletion(args: { token: string, topic: string }): Promise<PendingDeletion[]>\n restoreRepository(args: { token: string, id: Id }): Promise<unknown>\n restoreNamespace(args: { token: string, id: Id }): Promise<unknown>\n renameRepository(args: { token: string, id: Id, name: string }): Promise<Repository>\n getRepository(args: { token: string, id: Id }): Promise<Repository>\n /** By its full path; `null` when there is none. */\n findRepository(args: { token: string, path: string }): Promise<Repository | null>\n /** The live repositories of the user that have a topic. */\n listRepositories(args: { token: string, topic: string }): Promise<Repository[]>\n addTopic(args: { token: string, id: Id, topic: string }): Promise<void>\n setDefaultBranch(args: { token: string, id: Id, branch: string }): Promise<unknown>\n getMembers(args: { token: string, id: Id }): Promise<Member[]>\n /** The level of the user of `token` on the repository (0: none). */\n getAccessLevel(args: { token: string, id: Id, username: string }): Promise<number>\n /** Everybody with access to the repository, each with the level and where it comes from (needs Maintainer to read the whole list). */\n listAccess(args: { token: string, id: Id }): Promise<AccessEntry[]>\n /** Gives a person a level (20, 30, 40 or 50) on the repository, or changes it. */\n setAccess(args: { token: string, id: Id, username: string, accessLevel: number }): Promise<void>\n /** Takes the access set on the repository itself from a person (one inherited from a group stays: it is the group's). */\n removeAccess(args: { token: string, id: Id, username: string }): Promise<void>\n /** People of the host whose username or name matches `query`. */\n searchUsers(args: { token: string, query: string }): Promise<HostUser[]>\n\n // Files, commits, archives\n getFile(args: { token: string, id: Id, path: string, ref: string }): Promise<RepositoryFile>\n /** Like `getFile`, never remembered for rollback. */\n getFileRevision(args: { token: string, id: Id, path: string, ref: string }): Promise<RepositoryFile>\n /** The bytes, or `null` when there is no such file. */\n readFile(args: { token: string, id: Id, path: string, ref: string }): Promise<Buffer | null>\n /** Every file of a repository at `ref`. */\n listFiles(args: { token: string, id: Id, ref: string }): Promise<string[]>\n createFile(args: { token: string, id: Id, path: string, branch: string, content: string }): Promise<unknown>\n saveFile(args: { token: string, id: Id, path: string, branch: string, content: string }): Promise<unknown>\n commit(args: { token: string, id: Id, branch: string, message: string, actions: FileAction[], track?: boolean }): Promise<{ id: string }>\n /** A zip of the repository at `ref`. */\n downloadArchive(args: { token: string, id: Id, ref?: string }): Promise<NodeJS.ReadableStream>\n getCommits(args: { token: string, id: Id, ref: string, perPage?: number }): Promise<CommitSummary[]>\n /** What `to` has that `from` has not: its commits (newest first) and the files they change, as the host's own comparison shows them. */\n compare(args: { token: string, id: Id, from: string, to: string }): Promise<Comparison>\n\n // Branches and tags\n createBranch(args: { token: string, id: Id, branch: string, ref: string, track?: boolean }): Promise<unknown>\n /** The names of the branches of a repository. */\n listBranches(args: { token: string, id: Id }): Promise<string[]>\n getBranch(args: { token: string, id: Id, branch: string }): Promise<{ name: string, lastCommit: CommitSummary | null }>\n listTags(args: { token: string, id: Id }): Promise<{ name: string }[]>\n /** `message` is the annotation of the tag (null for one that has none): what `createTag` was given. */\n getTag(args: { token: string, id: Id, tag: string }): Promise<{ name: string, commitId: string, message: string | null } | null>\n createTag(args: { token: string, id: Id, tag: string, ref: string, message?: string }): Promise<unknown>\n\n // Releases: one per tag. Creating the release of a tag that has one fails with an \"already exists\" error (`isAlreadyExistsError`) and\n // leaves it as it was; `updateRelease` is the way to change it. A tag that does not exist is refused with status 404.\n /** `name` defaults to the tag. `prerelease` is ignored by a host whose `capabilities().releases.prerelease` is `false`. */\n createRelease(args: { token: string, id: Id, tag: string, name?: string, description?: string, prerelease?: boolean }): Promise<Release>\n /** `null` when the tag has no release. */\n getRelease(args: { token: string, id: Id, tag: string }): Promise<Release | null>\n /** Newest first. */\n listReleases(args: { token: string, id: Id }): Promise<Release[]>\n /** Only what is in `changes` is touched (`prerelease` only where the host has it); status 404 when the tag has no release. */\n updateRelease(args: { token: string, id: Id, tag: string, changes: ReleaseChanges }): Promise<Release>\n\n // Change requests\n createChangeRequest(args: { token: string, id: Id, title: string, sourceBranch: string, targetBranch: string }): Promise<ChangeRequest>\n createOrRenameChangeRequest(args: { token: string, id: Id, title: string, sourceBranch: string, targetBranch?: string }): Promise<ChangeRequest>\n listChangeRequests(args: { token: string, id: Id, state?: 'opened' | 'merged' | 'closed' | 'all', targetBranch?: string }): Promise<ChangeRequest[]>\n /** The pipelines that ran for a change request (its checks), newest first. */\n listChangeRequestPipelines(args: { token: string, id: Id, number: number }): Promise<Pipeline[]>\n /** Merges it when it can; `true` when it has conflicts (or is not open). */\n mergeChangeRequest(args: { token: string, id: Id, number: number, deleteSourceBranch?: boolean }): Promise<boolean>\n\n // Issues\n capabilities(): Capabilities\n listIssues(args: { token: string, id: Id, filter?: IssueFilter }): Promise<Page<Issue>>\n getIssue(args: { token: string, id: Id, number: number }): Promise<Issue>\n createIssue(args: { token: string, id: Id, title: string, description?: string, labels?: string[], assignees?: string[], milestone?: string | null }): Promise<Issue>\n /** Only what is in `changes` is touched. Closing and reopening are `state`. */\n updateIssue(args: { token: string, id: Id, number: number, changes: IssueChanges }): Promise<Issue>\n /** The messages the people wrote, oldest first (what the host writes by itself, \"changed the label\", is left out). */\n listIssueComments(args: { token: string, id: Id, number: number }): Promise<Comment[]>\n /** The labels put on an issue and taken off it, oldest first (those it was opened with too): who and when. */\n listIssueLabelEvents(args: { token: string, id: Id, number: number }): Promise<LabelEvent[]>\n addIssueComment(args: { token: string, id: Id, number: number, body: string }): Promise<Comment>\n listLabels(args: { token: string, id: Id }): Promise<Label[]>\n listMilestones(args: { token: string, id: Id }): Promise<Milestone[]>\n\n listTemplates(args: { token: string, id: Id, kind: TemplateKind }): Promise<Template[]>\n saveTemplate(args: { token: string, id: Id, kind: TemplateKind, name: string, content: string }): Promise<Template>\n deleteTemplate(args: { token: string, id: Id, kind: TemplateKind, name: string }): Promise<void>\n\n // Merge requests (the part of them the pages need; `createChangeRequest` and the rest are what the code needs)\n listMergeRequests(args: { token: string, id: Id, filter?: MergeRequestFilter }): Promise<Page<MergeRequest>>\n getMergeRequest(args: { token: string, id: Id, number: number }): Promise<MergeRequest>\n createMergeRequest(args: { token: string, id: Id, title: string, description?: string, sourceBranch: string, targetBranch: string, labels?: string[], reviewers?: string[] }): Promise<MergeRequest>\n /** Only what is in `changes` is touched. */\n updateMergeRequest(args: { token: string, id: Id, number: number, changes: MergeRequestChanges }): Promise<MergeRequest>\n /** The files it changes, as the target would see them after the merge. */\n getMergeRequestDiff(args: { token: string, id: Id, number: number }): Promise<FileDiff[]>\n /** Every conversation, oldest first: the general messages and the ones about lines of the code. */\n listMergeRequestThreads(args: { token: string, id: Id, number: number }): Promise<Thread[]>\n /** A general message, one about a line (`position`), or an answer in a thread (`threadId`). Answers with the thread it is in. */\n addMergeRequestComment(args: { token: string, id: Id, number: number, body: string, position?: DiffPosition, threadId?: Id }): Promise<Thread>\n setThreadResolved(args: { token: string, id: Id, number: number, threadId: Id, resolved: boolean }): Promise<Thread>\n /** Merges it; `true` when it has conflicts (or is not open), as `mergeChangeRequest`. */\n mergeMergeRequest(args: { token: string, id: Id, number: number, options?: MergeOptions }): Promise<boolean>\n /** Gives the approval of the user of `token` (a host with no approvals refuses with status 400). */\n approveMergeRequest(args: { token: string, id: Id, number: number }): Promise<void>\n\n // CI and hooks\n getLatestPipeline(args: { token: string, id: Id, ref: string }): Promise<Pipeline | null>\n /** The last pipelines of a branch (or of the repository, without `ref`), newest first. */\n listPipelines(args: { token: string, id: Id, ref?: string, perPage?: number }): Promise<Pipeline[]>\n /** The jobs of a pipeline, in the order they run. */\n getPipelineJobs(args: { token: string, id: Id, pipelineId: Id }): Promise<PipelineJob[]>\n /** Runs the failed jobs of a pipeline again. */\n retryPipeline(args: { token: string, id: Id, pipelineId: Id }): Promise<void>\n /** Stops a pipeline that has not finished: its running and waiting jobs are canceled. */\n cancelPipeline(args: { token: string, id: Id, pipelineId: Id }): Promise<void>\n /** Makes sure a repository can run pipelines (a project made with CI/CD switched off gets it switched on). Answers whether it changed anything. */\n enablePipelines(args: { token: string, id: Id }): Promise<boolean>\n /** Turns CI/CD off for a repository; `true` when it had to be changed. A host where that is not the repository's to choose does nothing. */\n disablePipelines(args: { token: string, id: Id }): Promise<boolean>\n /** Whether CI/CD is on for a repository; `null` when the host does not say, or it is not a thing of this host. */\n pipelinesEnabled(args: { token: string, id: Id }): Promise<boolean | null>\n /** Stops one job that has not finished (hosts that cannot cancel a single job say so). */\n cancelJob(args: { token: string, id: Id, jobId: Id }): Promise<void>\n /** The runners that can take the jobs of a repository, and whether the instance's own are turned on for it. */\n getCiRunners(args: { token: string, id: Id }): Promise<CiRunners>\n /** Turns on (or off) the runners of the whole instance for a repository. */\n setInstanceRunners(args: { token: string, id: Id, enabled: boolean }): Promise<void>\n /** The end of what a job printed (the last `lines`). */\n getJobTrace(args: { token: string, id: Id, jobId: Id, lines?: number }): Promise<string>\n ensureWebhook(args: { token: string, id: Id, url: string, secret: string, branch?: string }): Promise<{ status: 'created' | 'already_exists', hookId?: Id | null }>\n verifyWebhook(args: Required<Delivery>): boolean\n parsePushEvent(args: { headers: Record<string, string | undefined>, body: any }): { repositoryId: Id, branch: string } | null\n\n // Unit of work, errors\n rollback(): Promise<void>\n /** The token is expired or revoked. */\n isAuthError(error: unknown): boolean\n /** A branch (or other ref) that exists already. */\n isAlreadyExistsError(error: unknown): boolean\n}\n\n/** The methods a provider has to have: what the contract test checks and what a new host has to fill in. */\nexport const GIT_PROVIDER_METHODS = [\n 'authConfig', 'exchangeCode', 'refreshToken', 'getUser',\n 'listNamespaces', 'findNamespace', 'createNamespace', 'deleteNamespace', 'renameNamespace',\n 'createRepository', 'deleteRepository', 'listPendingDeletion', 'restoreRepository', 'restoreNamespace', 'renameRepository', 'getRepository', 'findRepository', 'listRepositories', 'addTopic',\n 'setDefaultBranch', 'getMembers', 'getAccessLevel', 'listAccess', 'setAccess', 'removeAccess', 'searchUsers',\n 'getFile', 'getFileRevision', 'readFile', 'listFiles', 'createFile', 'saveFile', 'commit', 'downloadArchive', 'getCommits', 'compare',\n 'createBranch', 'listBranches', 'getBranch', 'listTags', 'getTag', 'createTag',\n 'createRelease', 'getRelease', 'listReleases', 'updateRelease',\n 'createChangeRequest', 'createOrRenameChangeRequest', 'listChangeRequests', 'listChangeRequestPipelines', 'mergeChangeRequest',\n 'getLatestPipeline', 'listPipelines', 'getPipelineJobs', 'retryPipeline', 'cancelPipeline', 'cancelJob', 'enablePipelines', 'disablePipelines', 'pipelinesEnabled', 'getCiRunners', 'setInstanceRunners', 'getJobTrace', 'ensureWebhook', 'verifyWebhook', 'parsePushEvent',\n 'listMergeRequests', 'getMergeRequest', 'createMergeRequest', 'updateMergeRequest', 'getMergeRequestDiff', 'listMergeRequestThreads', 'addMergeRequestComment', 'setThreadResolved', 'mergeMergeRequest', 'approveMergeRequest',\n 'capabilities', 'listIssues', 'getIssue', 'createIssue', 'updateIssue', 'listIssueComments', 'listIssueLabelEvents', 'addIssueComment', 'listLabels', 'listMilestones', 'listTemplates', 'saveTemplate', 'deleteTemplate',\n 'rollback', 'isAuthError', 'isAlreadyExistsError'\n] as const\n"]}
@@ -111,6 +111,25 @@ export declare const savePackageFiles: ({ provider, token, kind, id, files, mess
111
111
  paths: string[];
112
112
  committed: boolean;
113
113
  }>;
114
+ export interface PublishPreview {
115
+ /** The version the manifest on `main` has. */
116
+ version: string;
117
+ /** The last version published (null: none yet). */
118
+ latest: string | null;
119
+ /** Why `version` cannot be published (not semver, already published, lower than the last one); null when it can. */
120
+ versionError: string | null;
121
+ /** The bump the commits since `latest` imply. */
122
+ suggestedBump: BumpLevel | null;
123
+ /** How many commits `main` has since `latest` (null when there is no `latest`): what the release's changelog will list. */
124
+ commitsSince: number | null;
125
+ warnings: string[];
126
+ }
127
+ /** What publishing `version` of a package would do, without doing it: whether the version may be published, the bump the commits imply and how much there is to release. */
128
+ export declare const previewPublication: ({ provider, token, kind, id, version }: Host & {
129
+ kind: PackageKind;
130
+ id: Id;
131
+ version: unknown;
132
+ }) => Promise<PublishPreview>;
114
133
  export interface PackageCheck {
115
134
  ok: boolean;
116
135
  diagnostics: readonly Diagnostic[];
@@ -9,7 +9,7 @@ import { locationOf } from '../packages/index.js';
9
9
  import { forgetPackageTags } from '../packages/gitlab-source.js';
10
10
  import { entryFor } from './catalog.js';
11
11
  import { KIND_DEFINITIONS } from './kinds.js';
12
- import { createPackageRelease, preflight, tagOf } from './release.js';
12
+ import { assertPublishable, bumpWarning, createPackageRelease, preflight, publishedVersions, suggestBump, tagOf } from './release.js';
13
13
  /**
14
14
  * The registry of modules and metamodels, on the git host: repositories with the topic `linea-module` or `linea-metamodel`, whose
15
15
  * versions are their `vX.Y.Z` tags. There is no database: the git host is the registry. These are the operations on it; who may do
@@ -216,6 +216,34 @@ export const savePackageFiles = async ({ provider, token, kind, id, files, messa
216
216
  const commit = await upsertFiles({ provider, token, id, message: message ?? `Update ${paths.length === 1 ? paths[0] : `${paths.length} files`}`, files });
217
217
  return { paths, committed: commit !== null };
218
218
  };
219
+ /** What publishing `version` of a package would do, without doing it: whether the version may be published, the bump the commits imply and how much there is to release. */
220
+ export const previewPublication = async ({ provider, token, kind, id, version }) => {
221
+ const file = KIND_DEFINITIONS[kind].manifest;
222
+ const tags = await provider.listTags({ token, id });
223
+ const published = publishedVersions(tags);
224
+ const latest = published[0] ?? null;
225
+ let versionError = null;
226
+ try {
227
+ assertPublishable({ version, published, file });
228
+ }
229
+ catch (error) {
230
+ versionError = error.message;
231
+ }
232
+ const warnings = [];
233
+ let suggested = null;
234
+ let commitsSince = null;
235
+ if (latest !== null) {
236
+ const changes = await generateChangelog({ provider, token, id, from: tagOf(tags, latest), to: 'main' });
237
+ commitsSince = changes.commits.length;
238
+ suggested = suggestBump(changes.commits);
239
+ if (versionError === null) {
240
+ const warning = bumpWarning({ latest, version: version, suggested });
241
+ if (warning)
242
+ warnings.push(warning);
243
+ }
244
+ }
245
+ return { version: String(version), latest, versionError, suggestedBump: suggested, commitsSince, warnings };
246
+ };
219
247
  /**
220
248
  * Publishes the version of `main`: checks that the version is valid semver, higher than the last one published and not already
221
249
  * published, checks the package (with `check`, which is given the location and the manifest), tags it `vX.Y.Z` and creates the release of