From 04a5c179bdf7f661d1ae1161c24e92d3e2b9c70b Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Fri, 27 Sep 2024 20:40:16 +0000 Subject: [PATCH] Add branch listing, workflow selection enhancements, and update GitHub client types and methods --- docs/genaisrc/genaiscript.d.ts | 10 ++++-- genaisrc/genaiscript.d.ts | 10 ++++-- packages/auto/genaiscript.d.ts | 10 ++++-- packages/core/src/genaisrc/genaiscript.d.ts | 10 ++++-- packages/core/src/github.ts | 16 +++++++++- packages/core/src/types/prompt_template.d.ts | 10 ++++-- .../sample/genaisrc/blog/genaiscript.d.ts | 10 ++++-- packages/sample/genaisrc/gai.genai.mts | 31 ++++++++++++++----- packages/sample/genaisrc/genaiscript.d.ts | 10 ++++-- .../sample/genaisrc/node/genaiscript.d.ts | 10 ++++-- .../sample/genaisrc/python/genaiscript.d.ts | 10 ++++-- .../sample/genaisrc/style/genaiscript.d.ts | 10 ++++-- packages/sample/src/aici/genaiscript.d.ts | 10 ++++-- packages/sample/src/errors/genaiscript.d.ts | 10 ++++-- packages/sample/src/genaiscript.d.ts | 10 ++++-- packages/sample/src/makecode/genaiscript.d.ts | 10 ++++-- packages/sample/src/tla/genaiscript.d.ts | 10 ++++-- packages/sample/src/vision/genaiscript.d.ts | 10 ++++-- packages/vscode/genaisrc/genaiscript.d.ts | 10 ++++-- slides/genaisrc/genaiscript.d.ts | 10 ++++-- 20 files changed, 183 insertions(+), 44 deletions(-) diff --git a/docs/genaisrc/genaiscript.d.ts b/docs/genaisrc/genaiscript.d.ts index 276d30d862..6d7f4836c5 100644 --- a/docs/genaisrc/genaiscript.d.ts +++ b/docs/genaisrc/genaiscript.d.ts @@ -1372,6 +1372,7 @@ interface GitHubCodeSearchResult { interface GitHubWorkflow { id: number name: string + path: string } interface GitHubPaginationOptions { @@ -1385,6 +1386,11 @@ interface GitHub { */ info(): Promise + /** + * Lists workflows in a GitHub repository + */ + listWorkflows(options?: GitHubPaginationOptions): Promise + /** * Lists workflow runs for a given workflow * @param workflowId @@ -1475,9 +1481,9 @@ interface GitHub { ): Promise /** - * Lists workflows in a GitHub repository + * Lists branches in a GitHub repository */ - listWorkflows(options?: GitHubPaginationOptions): Promise + listBranches(options?: GitHubPaginationOptions): Promise } interface MD { diff --git a/genaisrc/genaiscript.d.ts b/genaisrc/genaiscript.d.ts index 276d30d862..6d7f4836c5 100644 --- a/genaisrc/genaiscript.d.ts +++ b/genaisrc/genaiscript.d.ts @@ -1372,6 +1372,7 @@ interface GitHubCodeSearchResult { interface GitHubWorkflow { id: number name: string + path: string } interface GitHubPaginationOptions { @@ -1385,6 +1386,11 @@ interface GitHub { */ info(): Promise + /** + * Lists workflows in a GitHub repository + */ + listWorkflows(options?: GitHubPaginationOptions): Promise + /** * Lists workflow runs for a given workflow * @param workflowId @@ -1475,9 +1481,9 @@ interface GitHub { ): Promise /** - * Lists workflows in a GitHub repository + * Lists branches in a GitHub repository */ - listWorkflows(options?: GitHubPaginationOptions): Promise + listBranches(options?: GitHubPaginationOptions): Promise } interface MD { diff --git a/packages/auto/genaiscript.d.ts b/packages/auto/genaiscript.d.ts index 276d30d862..6d7f4836c5 100644 --- a/packages/auto/genaiscript.d.ts +++ b/packages/auto/genaiscript.d.ts @@ -1372,6 +1372,7 @@ interface GitHubCodeSearchResult { interface GitHubWorkflow { id: number name: string + path: string } interface GitHubPaginationOptions { @@ -1385,6 +1386,11 @@ interface GitHub { */ info(): Promise + /** + * Lists workflows in a GitHub repository + */ + listWorkflows(options?: GitHubPaginationOptions): Promise + /** * Lists workflow runs for a given workflow * @param workflowId @@ -1475,9 +1481,9 @@ interface GitHub { ): Promise /** - * Lists workflows in a GitHub repository + * Lists branches in a GitHub repository */ - listWorkflows(options?: GitHubPaginationOptions): Promise + listBranches(options?: GitHubPaginationOptions): Promise } interface MD { diff --git a/packages/core/src/genaisrc/genaiscript.d.ts b/packages/core/src/genaisrc/genaiscript.d.ts index 276d30d862..6d7f4836c5 100644 --- a/packages/core/src/genaisrc/genaiscript.d.ts +++ b/packages/core/src/genaisrc/genaiscript.d.ts @@ -1372,6 +1372,7 @@ interface GitHubCodeSearchResult { interface GitHubWorkflow { id: number name: string + path: string } interface GitHubPaginationOptions { @@ -1385,6 +1386,11 @@ interface GitHub { */ info(): Promise + /** + * Lists workflows in a GitHub repository + */ + listWorkflows(options?: GitHubPaginationOptions): Promise + /** * Lists workflow runs for a given workflow * @param workflowId @@ -1475,9 +1481,9 @@ interface GitHub { ): Promise /** - * Lists workflows in a GitHub repository + * Lists branches in a GitHub repository */ - listWorkflows(options?: GitHubPaginationOptions): Promise + listBranches(options?: GitHubPaginationOptions): Promise } interface MD { diff --git a/packages/core/src/github.ts b/packages/core/src/github.ts index a55e17f960..9e4a143485 100644 --- a/packages/core/src/github.ts +++ b/packages/core/src/github.ts @@ -669,6 +669,20 @@ export class GitHubClient implements GitHub { ...(options ?? {}), } ) - return workflows.workflows.map(({ id, name }) => ({ id, name })) + return workflows.workflows.map(({ id, name, path }) => ({ + id, + name, + path, + })) + } + + async listBranches(options?: GitHubPaginationOptions): Promise { + const { client, owner, repo } = await this.client() + const { data: branches } = await client.rest.repos.listBranches({ + owner, + repo, + ...(options ?? {}), + }) + return branches.map(({ name }) => name) } } diff --git a/packages/core/src/types/prompt_template.d.ts b/packages/core/src/types/prompt_template.d.ts index 0e321cc1a9..6b437521b9 100644 --- a/packages/core/src/types/prompt_template.d.ts +++ b/packages/core/src/types/prompt_template.d.ts @@ -1339,6 +1339,7 @@ interface GitHubCodeSearchResult { interface GitHubWorkflow { id: number name: string + path: string } interface GitHubPaginationOptions { @@ -1352,6 +1353,11 @@ interface GitHub { */ info(): Promise + /** + * Lists workflows in a GitHub repository + */ + listWorkflows(options?: GitHubPaginationOptions): Promise + /** * Lists workflow runs for a given workflow * @param workflowId @@ -1442,9 +1448,9 @@ interface GitHub { ): Promise /** - * Lists workflows in a GitHub repository + * Lists branches in a GitHub repository */ - listWorkflows(options?: GitHubPaginationOptions): Promise + listBranches(options?: GitHubPaginationOptions): Promise } interface MD { diff --git a/packages/sample/genaisrc/blog/genaiscript.d.ts b/packages/sample/genaisrc/blog/genaiscript.d.ts index 276d30d862..6d7f4836c5 100644 --- a/packages/sample/genaisrc/blog/genaiscript.d.ts +++ b/packages/sample/genaisrc/blog/genaiscript.d.ts @@ -1372,6 +1372,7 @@ interface GitHubCodeSearchResult { interface GitHubWorkflow { id: number name: string + path: string } interface GitHubPaginationOptions { @@ -1385,6 +1386,11 @@ interface GitHub { */ info(): Promise + /** + * Lists workflows in a GitHub repository + */ + listWorkflows(options?: GitHubPaginationOptions): Promise + /** * Lists workflow runs for a given workflow * @param workflowId @@ -1475,9 +1481,9 @@ interface GitHub { ): Promise /** - * Lists workflows in a GitHub repository + * Lists branches in a GitHub repository */ - listWorkflows(options?: GitHubPaginationOptions): Promise + listBranches(options?: GitHubPaginationOptions): Promise } interface MD { diff --git a/packages/sample/genaisrc/gai.genai.mts b/packages/sample/genaisrc/gai.genai.mts index 54e9256245..73965170c6 100644 --- a/packages/sample/genaisrc/gai.genai.mts +++ b/packages/sample/genaisrc/gai.genai.mts @@ -10,15 +10,32 @@ script({ success_run_id: { type: "number" }, branch: { type: "string" }, }, + system: ["system", "system.files"], }) -const workflow = env.vars.workflow || "build.yml" +let workflow = env.vars.workflow +if (!workflow) { + const workflows = await github.listWorkflows() + workflow = await host.select( + "Select a workflow", + workflows.map(({ path, name }) => ({ value: path, name })) + ) + if (!workflow) cancel("No workflow selected") +} + const ffid = env.vars.failure_run_id const lsid = env.vars.success_run_id -const branch = +const { owner, repo } = await github.info() + +let branch = env.vars.branch || (await host.exec("git branch --show-current")).stdout.trim() -const { owner, repo } = await github.info() +if (!branch) { + const branches = await github.listBranches() + branch = await host.select("Select a branch", branches) + if (!branch) cancel("No branch selected") +} + const runs = await github.listWorkflowRuns(workflow, { branch }) if (!runs.length) cancel("No runs found") @@ -32,10 +49,10 @@ console.log( ` run: ${ff.id}, ${ff.conclusion}, ${ff.created_at}, ${ff.head_sha}, ${ff.html_url}` ) -// first last success const lsi = lsid - ? runs.slice(ffi).findIndex(({ id }) => id === lsid) - : runs.slice(ffi).findIndex(({ conclusion }) => conclusion === "success") + ? runs.findIndex(({ id }) => id === lsid) + : // last success preceding the build + runs.slice(ffi).findIndex(({ conclusion }) => conclusion === "success") const ls = runs[lsi] if (ls) { console.log( @@ -44,7 +61,7 @@ if (ls) { const gitDiff = await host.exec( `git diff ${ls.head_sha} ${ff.head_sha} -- . :!**/genaiscript.d.ts` ) - console.log(`> source diff: ${(gitDiff.stdout.length / 1000) | 0}kb`) + console.log(`> git diff: ${(gitDiff.stdout.length / 1000) | 0}kb`) def("GIT_DIFF", gitDiff, { language: "diff", maxTokens: 10000, diff --git a/packages/sample/genaisrc/genaiscript.d.ts b/packages/sample/genaisrc/genaiscript.d.ts index 276d30d862..6d7f4836c5 100644 --- a/packages/sample/genaisrc/genaiscript.d.ts +++ b/packages/sample/genaisrc/genaiscript.d.ts @@ -1372,6 +1372,7 @@ interface GitHubCodeSearchResult { interface GitHubWorkflow { id: number name: string + path: string } interface GitHubPaginationOptions { @@ -1385,6 +1386,11 @@ interface GitHub { */ info(): Promise + /** + * Lists workflows in a GitHub repository + */ + listWorkflows(options?: GitHubPaginationOptions): Promise + /** * Lists workflow runs for a given workflow * @param workflowId @@ -1475,9 +1481,9 @@ interface GitHub { ): Promise /** - * Lists workflows in a GitHub repository + * Lists branches in a GitHub repository */ - listWorkflows(options?: GitHubPaginationOptions): Promise + listBranches(options?: GitHubPaginationOptions): Promise } interface MD { diff --git a/packages/sample/genaisrc/node/genaiscript.d.ts b/packages/sample/genaisrc/node/genaiscript.d.ts index 276d30d862..6d7f4836c5 100644 --- a/packages/sample/genaisrc/node/genaiscript.d.ts +++ b/packages/sample/genaisrc/node/genaiscript.d.ts @@ -1372,6 +1372,7 @@ interface GitHubCodeSearchResult { interface GitHubWorkflow { id: number name: string + path: string } interface GitHubPaginationOptions { @@ -1385,6 +1386,11 @@ interface GitHub { */ info(): Promise + /** + * Lists workflows in a GitHub repository + */ + listWorkflows(options?: GitHubPaginationOptions): Promise + /** * Lists workflow runs for a given workflow * @param workflowId @@ -1475,9 +1481,9 @@ interface GitHub { ): Promise /** - * Lists workflows in a GitHub repository + * Lists branches in a GitHub repository */ - listWorkflows(options?: GitHubPaginationOptions): Promise + listBranches(options?: GitHubPaginationOptions): Promise } interface MD { diff --git a/packages/sample/genaisrc/python/genaiscript.d.ts b/packages/sample/genaisrc/python/genaiscript.d.ts index 276d30d862..6d7f4836c5 100644 --- a/packages/sample/genaisrc/python/genaiscript.d.ts +++ b/packages/sample/genaisrc/python/genaiscript.d.ts @@ -1372,6 +1372,7 @@ interface GitHubCodeSearchResult { interface GitHubWorkflow { id: number name: string + path: string } interface GitHubPaginationOptions { @@ -1385,6 +1386,11 @@ interface GitHub { */ info(): Promise + /** + * Lists workflows in a GitHub repository + */ + listWorkflows(options?: GitHubPaginationOptions): Promise + /** * Lists workflow runs for a given workflow * @param workflowId @@ -1475,9 +1481,9 @@ interface GitHub { ): Promise /** - * Lists workflows in a GitHub repository + * Lists branches in a GitHub repository */ - listWorkflows(options?: GitHubPaginationOptions): Promise + listBranches(options?: GitHubPaginationOptions): Promise } interface MD { diff --git a/packages/sample/genaisrc/style/genaiscript.d.ts b/packages/sample/genaisrc/style/genaiscript.d.ts index 276d30d862..6d7f4836c5 100644 --- a/packages/sample/genaisrc/style/genaiscript.d.ts +++ b/packages/sample/genaisrc/style/genaiscript.d.ts @@ -1372,6 +1372,7 @@ interface GitHubCodeSearchResult { interface GitHubWorkflow { id: number name: string + path: string } interface GitHubPaginationOptions { @@ -1385,6 +1386,11 @@ interface GitHub { */ info(): Promise + /** + * Lists workflows in a GitHub repository + */ + listWorkflows(options?: GitHubPaginationOptions): Promise + /** * Lists workflow runs for a given workflow * @param workflowId @@ -1475,9 +1481,9 @@ interface GitHub { ): Promise /** - * Lists workflows in a GitHub repository + * Lists branches in a GitHub repository */ - listWorkflows(options?: GitHubPaginationOptions): Promise + listBranches(options?: GitHubPaginationOptions): Promise } interface MD { diff --git a/packages/sample/src/aici/genaiscript.d.ts b/packages/sample/src/aici/genaiscript.d.ts index 276d30d862..6d7f4836c5 100644 --- a/packages/sample/src/aici/genaiscript.d.ts +++ b/packages/sample/src/aici/genaiscript.d.ts @@ -1372,6 +1372,7 @@ interface GitHubCodeSearchResult { interface GitHubWorkflow { id: number name: string + path: string } interface GitHubPaginationOptions { @@ -1385,6 +1386,11 @@ interface GitHub { */ info(): Promise + /** + * Lists workflows in a GitHub repository + */ + listWorkflows(options?: GitHubPaginationOptions): Promise + /** * Lists workflow runs for a given workflow * @param workflowId @@ -1475,9 +1481,9 @@ interface GitHub { ): Promise /** - * Lists workflows in a GitHub repository + * Lists branches in a GitHub repository */ - listWorkflows(options?: GitHubPaginationOptions): Promise + listBranches(options?: GitHubPaginationOptions): Promise } interface MD { diff --git a/packages/sample/src/errors/genaiscript.d.ts b/packages/sample/src/errors/genaiscript.d.ts index 276d30d862..6d7f4836c5 100644 --- a/packages/sample/src/errors/genaiscript.d.ts +++ b/packages/sample/src/errors/genaiscript.d.ts @@ -1372,6 +1372,7 @@ interface GitHubCodeSearchResult { interface GitHubWorkflow { id: number name: string + path: string } interface GitHubPaginationOptions { @@ -1385,6 +1386,11 @@ interface GitHub { */ info(): Promise + /** + * Lists workflows in a GitHub repository + */ + listWorkflows(options?: GitHubPaginationOptions): Promise + /** * Lists workflow runs for a given workflow * @param workflowId @@ -1475,9 +1481,9 @@ interface GitHub { ): Promise /** - * Lists workflows in a GitHub repository + * Lists branches in a GitHub repository */ - listWorkflows(options?: GitHubPaginationOptions): Promise + listBranches(options?: GitHubPaginationOptions): Promise } interface MD { diff --git a/packages/sample/src/genaiscript.d.ts b/packages/sample/src/genaiscript.d.ts index 276d30d862..6d7f4836c5 100644 --- a/packages/sample/src/genaiscript.d.ts +++ b/packages/sample/src/genaiscript.d.ts @@ -1372,6 +1372,7 @@ interface GitHubCodeSearchResult { interface GitHubWorkflow { id: number name: string + path: string } interface GitHubPaginationOptions { @@ -1385,6 +1386,11 @@ interface GitHub { */ info(): Promise + /** + * Lists workflows in a GitHub repository + */ + listWorkflows(options?: GitHubPaginationOptions): Promise + /** * Lists workflow runs for a given workflow * @param workflowId @@ -1475,9 +1481,9 @@ interface GitHub { ): Promise /** - * Lists workflows in a GitHub repository + * Lists branches in a GitHub repository */ - listWorkflows(options?: GitHubPaginationOptions): Promise + listBranches(options?: GitHubPaginationOptions): Promise } interface MD { diff --git a/packages/sample/src/makecode/genaiscript.d.ts b/packages/sample/src/makecode/genaiscript.d.ts index 276d30d862..6d7f4836c5 100644 --- a/packages/sample/src/makecode/genaiscript.d.ts +++ b/packages/sample/src/makecode/genaiscript.d.ts @@ -1372,6 +1372,7 @@ interface GitHubCodeSearchResult { interface GitHubWorkflow { id: number name: string + path: string } interface GitHubPaginationOptions { @@ -1385,6 +1386,11 @@ interface GitHub { */ info(): Promise + /** + * Lists workflows in a GitHub repository + */ + listWorkflows(options?: GitHubPaginationOptions): Promise + /** * Lists workflow runs for a given workflow * @param workflowId @@ -1475,9 +1481,9 @@ interface GitHub { ): Promise /** - * Lists workflows in a GitHub repository + * Lists branches in a GitHub repository */ - listWorkflows(options?: GitHubPaginationOptions): Promise + listBranches(options?: GitHubPaginationOptions): Promise } interface MD { diff --git a/packages/sample/src/tla/genaiscript.d.ts b/packages/sample/src/tla/genaiscript.d.ts index 276d30d862..6d7f4836c5 100644 --- a/packages/sample/src/tla/genaiscript.d.ts +++ b/packages/sample/src/tla/genaiscript.d.ts @@ -1372,6 +1372,7 @@ interface GitHubCodeSearchResult { interface GitHubWorkflow { id: number name: string + path: string } interface GitHubPaginationOptions { @@ -1385,6 +1386,11 @@ interface GitHub { */ info(): Promise + /** + * Lists workflows in a GitHub repository + */ + listWorkflows(options?: GitHubPaginationOptions): Promise + /** * Lists workflow runs for a given workflow * @param workflowId @@ -1475,9 +1481,9 @@ interface GitHub { ): Promise /** - * Lists workflows in a GitHub repository + * Lists branches in a GitHub repository */ - listWorkflows(options?: GitHubPaginationOptions): Promise + listBranches(options?: GitHubPaginationOptions): Promise } interface MD { diff --git a/packages/sample/src/vision/genaiscript.d.ts b/packages/sample/src/vision/genaiscript.d.ts index 276d30d862..6d7f4836c5 100644 --- a/packages/sample/src/vision/genaiscript.d.ts +++ b/packages/sample/src/vision/genaiscript.d.ts @@ -1372,6 +1372,7 @@ interface GitHubCodeSearchResult { interface GitHubWorkflow { id: number name: string + path: string } interface GitHubPaginationOptions { @@ -1385,6 +1386,11 @@ interface GitHub { */ info(): Promise + /** + * Lists workflows in a GitHub repository + */ + listWorkflows(options?: GitHubPaginationOptions): Promise + /** * Lists workflow runs for a given workflow * @param workflowId @@ -1475,9 +1481,9 @@ interface GitHub { ): Promise /** - * Lists workflows in a GitHub repository + * Lists branches in a GitHub repository */ - listWorkflows(options?: GitHubPaginationOptions): Promise + listBranches(options?: GitHubPaginationOptions): Promise } interface MD { diff --git a/packages/vscode/genaisrc/genaiscript.d.ts b/packages/vscode/genaisrc/genaiscript.d.ts index 276d30d862..6d7f4836c5 100644 --- a/packages/vscode/genaisrc/genaiscript.d.ts +++ b/packages/vscode/genaisrc/genaiscript.d.ts @@ -1372,6 +1372,7 @@ interface GitHubCodeSearchResult { interface GitHubWorkflow { id: number name: string + path: string } interface GitHubPaginationOptions { @@ -1385,6 +1386,11 @@ interface GitHub { */ info(): Promise + /** + * Lists workflows in a GitHub repository + */ + listWorkflows(options?: GitHubPaginationOptions): Promise + /** * Lists workflow runs for a given workflow * @param workflowId @@ -1475,9 +1481,9 @@ interface GitHub { ): Promise /** - * Lists workflows in a GitHub repository + * Lists branches in a GitHub repository */ - listWorkflows(options?: GitHubPaginationOptions): Promise + listBranches(options?: GitHubPaginationOptions): Promise } interface MD { diff --git a/slides/genaisrc/genaiscript.d.ts b/slides/genaisrc/genaiscript.d.ts index 276d30d862..6d7f4836c5 100644 --- a/slides/genaisrc/genaiscript.d.ts +++ b/slides/genaisrc/genaiscript.d.ts @@ -1372,6 +1372,7 @@ interface GitHubCodeSearchResult { interface GitHubWorkflow { id: number name: string + path: string } interface GitHubPaginationOptions { @@ -1385,6 +1386,11 @@ interface GitHub { */ info(): Promise + /** + * Lists workflows in a GitHub repository + */ + listWorkflows(options?: GitHubPaginationOptions): Promise + /** * Lists workflow runs for a given workflow * @param workflowId @@ -1475,9 +1481,9 @@ interface GitHub { ): Promise /** - * Lists workflows in a GitHub repository + * Lists branches in a GitHub repository */ - listWorkflows(options?: GitHubPaginationOptions): Promise + listBranches(options?: GitHubPaginationOptions): Promise } interface MD {