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

Add title and description to GitHub Action Investigator script #730

Merged
merged 4 commits into from
Sep 27, 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
6 changes: 2 additions & 4 deletions packages/cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,8 @@

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

Check failure on line 434 in packages/cli/src/run.ts

View workflow job for this annotation

GitHub Actions / build

The `pullRequest` variable is not checked for `undefined` or `null` before being used. This could lead to unexpected behavior if `pullRequest` is `undefined` or `null`. Please add a check for `pullRequest` before using it. 😊

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pullRequest variable is not checked for undefined or null before being used. This could lead to unexpected behavior if pullRequest is undefined or null. Please add a check for pullRequest before using it. 😊

generated by pr-review-commit missing_check

return _ghInfo
}
let adoInfo: AzureDevOpsEnv = undefined
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
}

export async function githubParseEnv(
env: Record<string, string>
env: Record<string, string>,
options?: { issue?: number }
): Promise<GithubConnectionInfo> {
const res = githubFromEnv(env)
try {
Expand All @@ -76,6 +77,7 @@
res.owner = owner.login
res.repository = res.owner + "/" + res.repo
}
if (!isNaN(options?.issue)) res.issue = options.issue

Check failure on line 80 in packages/core/src/github.ts

View workflow job for this annotation

GitHub Actions / build

The `options?.issue` is not checked for `undefined` or `null` before being used. This could lead to unexpected behavior if `options?.issue` is `undefined` or `null`. Please add a check for `options?.issue` before using it. 😊

Check failure on line 80 in packages/core/src/github.ts

View workflow job for this annotation

GitHub Actions / build

The use of `isNaN(options?.issue)` could lead to type coercion and unexpected behavior. Consider using `Number.isNaN(Number(options?.issue))` for a safer check. 😊

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The options?.issue is not checked for undefined or null before being used. This could lead to unexpected behavior if options?.issue is undefined or null. Please add a check for options?.issue before using it. 😊

generated by pr-review-commit missing_check

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of isNaN(options?.issue) could lead to type coercion and unexpected behavior. Consider using Number.isNaN(Number(options?.issue)) for a safer check. 😊

generated by pr-review-commit type_coercion

if (!res.issue) {
const { number: issue } = JSON.parse(
(
Expand Down
8 changes: 6 additions & 2 deletions packages/sample/genaisrc/gai.genai.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { Octokit } from "octokit"
import { createPatch } from "diff"

script({
title: "GitHub Action Investigator",
description:
"Analyze GitHub Action runs to find the root cause of a failure",
parameters: {
workflow: { type: "string" },
failure_run_id: { type: "number" },
Expand Down Expand Up @@ -92,11 +95,12 @@ Analyze the diff in LOG_DIFF and provide a summary of the root cause of the fail

If you cannot find the root cause, stop.

Generate a diff with suggested fixes. Use a diff format.`
Generate a diff with suggested fixes. Use a diff format.
- If you cannot locate the error, do not generate a diff.`

writeText(
`## Investigator report
- [run first failure](${ff.html_url})
- [run failure](${ff.html_url})
- [run last success](${ls.html_url})
- [commit diff](https://github.com/${owner}/${repo}/compare/${ls.head_sha}...${ff.head_sha})

Expand Down