Skip to content

Commit

Permalink
Add branch listing, workflow selection enhancements, and update GitHu…
Browse files Browse the repository at this point in the history
…b client types and methods
  • Loading branch information
pelikhan committed Sep 27, 2024
1 parent 3779d6b commit 04a5c17
Show file tree
Hide file tree
Showing 20 changed files with 183 additions and 44 deletions.
10 changes: 8 additions & 2 deletions docs/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions packages/auto/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions packages/core/src/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion packages/core/src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]> {
const { client, owner, repo } = await this.client()
const { data: branches } = await client.rest.repos.listBranches({
owner,
repo,
...(options ?? {}),
})
return branches.map(({ name }) => name)
}
}
10 changes: 8 additions & 2 deletions packages/core/src/types/prompt_template.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,7 @@ interface GitHubCodeSearchResult {
interface GitHubWorkflow {
id: number
name: string
path: string
}

interface GitHubPaginationOptions {
Expand All @@ -1352,6 +1353,11 @@ interface GitHub {
*/
info(): Promise<GitHubOptions | undefined>

/**
* Lists workflows in a GitHub repository
*/
listWorkflows(options?: GitHubPaginationOptions): Promise<GitHubWorkflow[]>

/**
* Lists workflow runs for a given workflow
* @param workflowId
Expand Down Expand Up @@ -1442,9 +1448,9 @@ interface GitHub {
): Promise<GitHubCodeSearchResult[]>

/**
* Lists workflows in a GitHub repository
* Lists branches in a GitHub repository
*/
listWorkflows(options?: GitHubPaginationOptions): Promise<GitHubWorkflow[]>
listBranches(options?: GitHubPaginationOptions): Promise<string[]>
}

interface MD {
Expand Down
10 changes: 8 additions & 2 deletions packages/sample/genaisrc/blog/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 24 additions & 7 deletions packages/sample/genaisrc/gai.genai.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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(
Expand All @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions packages/sample/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions packages/sample/genaisrc/node/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions packages/sample/genaisrc/python/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 04a5c17

Please sign in to comment.