Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-pr option in run #729

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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".`
Loading