Skip to content

Commit

Permalink
store pull request head sha
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Jun 1, 2024
1 parent 13fc5c8 commit 3e9055e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/genai-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
run: node packages/cli/built/genaiscript.cjs run pr-review --out ./temp/pr-review -prc pr-review -prr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_PULL_REQUEST_HEAD_SHA: ${{ github.event.pull_request.head.sha}}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_API_TYPE: ${{ secrets.OPENAI_API_TYPE }}
OPENAI_API_BASE: ${{ secrets.OPENAI_API_BASE }}
2 changes: 1 addition & 1 deletion packages/cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ ${Array.from(files)

if (pullRequestReviews && res.annotations?.length) {
const info = parseGHTokenFromEnv(process.env)
if (info.repository && info.issue && info.sha)
if (info.repository && info.issue)
await githubCreatePullRequestReviews(script, info, res.annotations)
}

Expand Down
16 changes: 12 additions & 4 deletions packages/core/src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface GithubConnectionInfo {
issue?: number
runId?: string
runUrl?: string
pullRequestHeadSha?: string
}

export function parseGHTokenFromEnv(
Expand All @@ -29,6 +30,7 @@ export function parseGHTokenFromEnv(
const [owner, repo] = repository?.split("/", 2) || [undefined, undefined]
const ref = env.GITHUB_REF
const sha = env.GITHUB_SHA
const pullRequestHeadSha = env.GITHUB_PULL_REQUEST_HEAD_SHA
const runId = env.GITHUB_RUN_ID
const serverUrl = env.GITHUB_SERVER_URL
const runUrl =
Expand All @@ -50,6 +52,7 @@ export function parseGHTokenFromEnv(
issue,
runId,
runUrl,
pullRequestHeadSha,
}
}

Expand Down Expand Up @@ -209,13 +212,13 @@ async function githubCreatePullRequestReview(
annotation: Diagnostic
) {
assert(token)
const { apiUrl, repository, issue, sha } = info
const { apiUrl, repository, issue, pullRequestHeadSha } = info
const fetch = await createFetch()
const url = `${apiUrl}/repos/${repository}/pulls/${issue}/comments`
logVerbose(url)
const body = {
body: appendGeneratedComment(script, info, annotation.message),
commit_id: sha,
commit_id: pullRequestHeadSha,
path: annotation.filename,
line: annotation.range?.[0]?.[0],
side: "RIGHT",
Expand All @@ -238,8 +241,13 @@ async function githubCreatePullRequestReview(
html_url: resp.html_url,
}
if (!r.created)
logError(`commit ${sha} comment creation failed, ${r.statusText}`)
else logVerbose(`commit ${sha} comment created at ${r.html_url}`)
logError(
`commit ${pullRequestHeadSha} comment creation failed, ${r.statusText}`
)
else
logVerbose(
`commit ${pullRequestHeadSha} comment created at ${r.html_url}`
)
return r
}

Expand Down

0 comments on commit 3e9055e

Please sign in to comment.