Skip to content
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
8 changes: 2 additions & 6 deletions .github/workflows/genai-linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ concurrency:
group: linters-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
GENAISCRIPT_DEFAULT_REASONING_MODEL: ${{ vars.GENAISCRIPT_DEFAULT_REASONING_MODEL }}
GENAISCRIPT_DEFAULT_REASONING_SMALL_MODEL: ${{ vars.GENAISCRIPT_DEFAULT_REASONING_SMALL_MODEL }}
GENAISCRIPT_DEFAULT_MODEL: ${{ vars.GENAISCRIPT_DEFAULT_MODEL }}
GENAISCRIPT_DEFAULT_SMALL_MODEL: ${{ vars.GENAISCRIPT_DEFAULT_SMALL_MODEL }}
GENAISCRIPT_DEFAULT_VISION_MODEL: ${{ vars.GENAISCRIPT_DEFAULT_VISION_MODEL }}
GENAISCRIPT_MODEL_LINTER: ${{ vars.GENAISCRIPT_MODEL_LINTER }}
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -38,7 +34,7 @@ jobs:
- name: git stuff
run: git fetch origin && git pull origin dev:dev
- name: genaiscript
run: node packages/cli/built/genaiscript.cjs run linters --out ./temp/genai/linters -prc -m reasoning --out-trace $GITHUB_STEP_SUMMARY --vars defaultBranch=dev
run: node packages/cli/built/genaiscript.cjs run linters --out ./temp/genai/linters -prr -m linter --out-trace $GITHUB_STEP_SUMMARY --vars defaultBranch=dev
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
10 changes: 3 additions & 7 deletions .github/workflows/genai-pr-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ concurrency:
group: pr-review-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
GENAISCRIPT_DEFAULT_REASONING_MODEL: ${{ vars.GENAISCRIPT_DEFAULT_REASONING_MODEL }}
GENAISCRIPT_DEFAULT_REASONING_SMALL_MODEL: ${{ vars.GENAISCRIPT_DEFAULT_REASONING_SMALL_MODEL }}
GENAISCRIPT_DEFAULT_MODEL: ${{ vars.GENAISCRIPT_DEFAULT_MODEL }}
GENAISCRIPT_DEFAULT_SMALL_MODEL: ${{ vars.GENAISCRIPT_DEFAULT_SMALL_MODEL }}
GENAISCRIPT_DEFAULT_VISION_MODEL: ${{ vars.GENAISCRIPT_DEFAULT_VISION_MODEL }}
GENAISCRIPT_MODEL_REVIEW: ${{ vars.GENAISCRIPT_MODEL_REVIEW }}
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -41,11 +37,11 @@ jobs:
run: git fetch origin && git pull origin dev:dev
- name: genaiscript pr-describe
continue-on-error: true
run: node packages/cli/built/genaiscript.cjs run pr-describe --out ./temp/genai/pr-describe -prd -m reasoning --out-trace $GITHUB_STEP_SUMMARY --vars defaultBranch=dev
run: node packages/cli/built/genaiscript.cjs run pr-describe --out ./temp/genai/pr-describe -prd -m review --out-trace $GITHUB_STEP_SUMMARY --vars defaultBranch=dev
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: genaiscript pr-review
run: node packages/cli/built/genaiscript.cjs run pr-review --out ./temp/genai/pr-review -prc -m reasoning --out-trace $GITHUB_STEP_SUMMARY --vars defaultBranch=dev
run: node packages/cli/built/genaiscript.cjs run pr-review --out ./temp/genai/pr-review -prc -m review --out-trace $GITHUB_STEP_SUMMARY --vars defaultBranch=dev
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
30 changes: 16 additions & 14 deletions packages/core/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export class GitClient implements Git {
readonly cwd: string
readonly git = "git" // Git command identifier
private _defaultBranch: string // Stores the default branch name
private _branch: string // Stores the current branch name

constructor(cwd: string) {
this.cwd = cwd || process.cwd()
Expand Down Expand Up @@ -72,12 +71,14 @@ export class GitClient implements Git {
* @returns {Promise<string>} The default branch name.
*/
async defaultBranch(): Promise<string> {
if (!this._defaultBranch) {
if (this._defaultBranch === undefined) {
dbg(`fetching default branch from remote`)
const res = await this.exec(["remote", "show", "origin"], {})
this._defaultBranch = /^\s*HEAD branch:\s+(?<name>.+)\s*$/m.exec(
res
)?.groups?.name
const res = await this.exec(["remote", "show", "origin"], {
valueOnError: "",
})
this._defaultBranch =
/^\s*HEAD branch:\s+(?<name>.+)\s*$/m.exec(res)?.groups?.name ||
""
}
return this._defaultBranch
}
Expand All @@ -87,17 +88,16 @@ export class GitClient implements Git {
* @returns
*/
async branch(): Promise<string> {
if (!this._branch) {
dbg(`fetching current branch`)
const res = await this.exec(["branch", "--show-current"])
this._branch = res.trim()
}
return this._branch
dbg(`fetching current branch`)
const res = await this.exec(["branch", "--show-current"], {
valueOnError: "",
})
return res.trim()
}

async listBranches(): Promise<string[]> {
dbg(`listing all branches`)
const res = await this.exec(["branch", "--list"])
const res = await this.exec(["branch", "--list"], { valueOnError: "" })
return res
.split("\n")
.map((b) => b.trim())
Expand All @@ -112,8 +112,9 @@ export class GitClient implements Git {
*/
async exec(
args: string | string[],
options?: { label?: string }
options?: { label?: string; valueOnError?: string }
): Promise<string> {
const { valueOnError } = options || {}
const opts: ShellOptions = {
...(options || {}),
cwd: this.cwd,
Expand All @@ -128,6 +129,7 @@ export class GitClient implements Git {
if (res.stdout) dbg(res.stdout)
if (res.exitCode !== 0) {
dbg(`error: ${res.stderr}`)
if (valueOnError !== undefined) return valueOnError
throw new Error(res.stderr)
}
return res.stdout
Copy link
Member Author

Choose a reason for hiding this comment

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

The member '_defaultBranch' is marked as 'private' but is also accessed without accessor methods, and its usage changes from "undefined" to empty string. As a best practice, use 'private' members cautiously and prefer using getters/setters for consistency and encapsulation. See: https://www.typescriptlang.org/docs/handbook/classes.html#member-visibility

AI-generated content by prr member_visibility may be incorrect. Use πŸ‘πŸ‘Ž to eval.

Copy link
Member Author

Choose a reason for hiding this comment

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

In both 'defaultBranch()' and 'branch()', an error from git now returns "", which is indistinguishable from a valid empty branch name. This can silently mask runtime git errors (e.g. detached HEAD, no remote 'origin'). Consider properly handling or surfacing such errors. See: https://git-scm.com/docs/git-branch

AI-generated content by prr unhandled_empty_default_branch may be incorrect. Use πŸ‘πŸ‘Ž to eval.

Copy link
Member Author

Choose a reason for hiding this comment

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

In 'exec()', the new 'valueOnError' option can silently swallow all git command errors, potentially leading to incorrect or inconsistent states if not carefully managed at every call site. Best practice is to fail fast on errors unless a very specific fallback is required and communicated to the caller. See: https://nodejs.org/api/errors.html#errors_propagation-and-interception

AI-generated content by prr swallowing_errors_exec may be incorrect. Use πŸ‘πŸ‘Ž to eval.

Expand Down
Loading