Skip to content

Commit

Permalink
-pr option in run (#729)
Browse files Browse the repository at this point in the history
* break build

* Add pull request option to CLI and refactor GitHub info resolution in scripts
  • Loading branch information
pelikhan authored Sep 26, 2024
1 parent c0269f2 commit 175d331
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/genai-investigator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: compile
run: yarn compile
- name: genaiscript gai
run: node packages/cli/built/genaiscript.cjs run gai -prc --vars "failure_run_id=${{ github.event.workflow_run.id }}" --vars "branch=${{ github.event.workflow_run.head_branch }}" --out-trace $GITHUB_STEP_SUMMARY
run: node packages/cli/built/genaiscript.cjs run gai -pr ${{ github.event.workflow_run.pull_requests[0].number }} -prc --vars "failure_run_id=${{ github.event.workflow_run.id }}" --vars "branch=${{ github.event.workflow_run.head_branch }}" --out-trace $GITHUB_STEP_SUMMARY
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
Expand Down
1 change: 1 addition & 0 deletions docs/src/content/docs/reference/cli/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Options:
-od, --out-data <string> output file for data (.jsonl/ndjson will be aggregated). JSON schema information and validation will be included if available.
-oa, --out-annotations <string> output file for annotations (.csv will be rendered as csv, .jsonl/ndjson will be aggregated)
-ocl, --out-changelog <string> output file for changelogs
-pr, --pull-request <number> pull request identifier
-prc, --pull-request-comment [string] create comment on a pull request with a unique id (defaults to script id)
-prd, --pull-request-description [string] create comment on a pull request description with a unique id (defaults to script id)
-prr, --pull-request-reviews create pull request reviews from annotations
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export async function cli() {
"output file for annotations (.csv will be rendered as csv, .jsonl/ndjson will be aggregated)"
)
.option("-ocl, --out-changelog <string>", "output file for changelogs")
.option("-pr, --pull-request <number>", "pull request identifier")
.option(
"-prc, --pull-request-comment [string]",
"create comment on a pull request with a unique id (defaults to script id)"
Expand Down
17 changes: 13 additions & 4 deletions packages/cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export async function runScript(
const outAnnotations = options.outAnnotations
const failOnErrors = options.failOnErrors
const outChangelogs = options.outChangelogs
const pullRequest = normalizeInt(options.pullRequest)
const pullRequestComment = options.pullRequestComment
const pullRequestDescription = options.pullRequestDescription
const pullRequestReviews = options.pullRequestReviews
Expand Down Expand Up @@ -427,11 +428,19 @@ export async function runScript(
}
}

let ghInfo: GithubConnectionInfo = undefined
let _ghInfo: GithubConnectionInfo = undefined
const resolveGitHubInfo = async () => {
if (!_ghInfo) {
_ghInfo = await githubParseEnv(process.env)
if (pullRequest) _ghInfo.issue = pullRequest
}
return _ghInfo
}
let adoInfo: AzureDevOpsEnv = undefined

if (pullRequestReviews && result.annotations?.length) {
// github action or repo
ghInfo = ghInfo ?? (await githubParseEnv(process.env))
const ghInfo = await resolveGitHubInfo()
if (ghInfo.repository && ghInfo.issue && ghInfo.commitSha) {
await githubCreatePullRequestReviews(
script,
Expand All @@ -443,7 +452,7 @@ export async function runScript(

if (pullRequestComment && result.text) {
// github action or repo
ghInfo = ghInfo ?? (await githubParseEnv(process.env))
const ghInfo = await resolveGitHubInfo()
if (ghInfo.repository && ghInfo.issue) {
await githubCreateIssueComment(
script,
Expand Down Expand Up @@ -473,7 +482,7 @@ export async function runScript(

if (pullRequestDescription && result.text) {
// github action or repo
ghInfo = ghInfo ?? (await githubParseEnv(process.env))
const ghInfo = await resolveGitHubInfo()
if (ghInfo.repository && ghInfo.issue) {
await githubUpdatePullRequestDescription(
script,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/server/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface PromptScriptRunOptions {
outTrace: string
outAnnotations: string
outChangelogs: string
pullRequest: string
pullRequestComment: string | boolean
pullRequestDescription: string | boolean
pullRequestReviews: boolean
Expand Down
4 changes: 2 additions & 2 deletions packages/sample/genaisrc/fs.genai.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
script({
model: "openai:gpt-3.5-turbo",
tools: ["fs"],
tests: {}
tests: {},
})

$`List the cities in the src folder markdown files as a CSV table. The file should contain the word "city".`
$`List the cities in the src folder markdown files as a CSV table. The file should contain the word "city".`

0 comments on commit 175d331

Please sign in to comment.