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

git helpers #741

Merged
merged 21 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
574fb12
Add Git interface for file selection and declare git variable for rep…
pelikhan Sep 30, 2024
3b19e95
wiring up globlas
pelikhan Sep 30, 2024
adcdd8c
Add git helper functions for branch and file modifications detection
pelikhan Sep 30, 2024
81f2cb5
Use `--porcelain` format in git status to ignore deleted files
pelikhan Sep 30, 2024
682c2d3
Refactor GitClient to use a unified exec method for executing git com…
pelikhan Sep 30, 2024
6897762
Refactor GitClient for scope handling and add diff method with filters
pelikhan Sep 30, 2024
c074fad
Refactor git diff command to use object-based parameters and exclude …
pelikhan Sep 30, 2024
7b9a8e2
Refactor diff parsing and update GitClient to handle excluded paths c…
pelikhan Oct 1, 2024
521cfed
Refactor git diff commands to use new API methods for consistency and…
pelikhan Oct 1, 2024
0f8b13d
refactor: replace host.exec with git.diff and git.exec for cleaner code
pelikhan Oct 1, 2024
822c9e8
Refactor git diff argument handling for clarity and correctness
pelikhan Oct 1, 2024
8b2d555
Enhance chat output by applying prettifyMarkdown function
pelikhan Oct 1, 2024
d58d623
Add verbose logging for default branch retrieval and console output i…
pelikhan Oct 1, 2024
754cca9
Update defaultBranch method to use 'remote show' and add setDefaultBr…
pelikhan Oct 1, 2024
71b3aaa
Change `findModifiedFiles` argument from "branch" to "base" for bette…
pelikhan Oct 1, 2024
c2d5d07
Make glob input dynamic and add prompts for missing variables
pelikhan Oct 1, 2024
145921b
Add askStageOnEmpty option to GitClient and update scripts to use git…
pelikhan Oct 1, 2024
37aa561
Add documentation and refactor diff handling logic in core and vscode…
pelikhan Oct 1, 2024
e1aa1d6
Add trace filename logging and return it from setupTraceWriting function
pelikhan Oct 1, 2024
9a3211d
Refactor git diff execution to use git library and improve context de…
pelikhan Oct 1, 2024
775a5fb
Update git.findModifiedFiles to use "base" instead of "branch"
pelikhan Oct 1, 2024
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
53 changes: 53 additions & 0 deletions docs/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { FileTree } from "@astrojs/starlight/components"
import { Image } from "astro:assets"
import { Code } from "@astrojs/starlight/components"
import prDescribeSrc from "../../../../../packages/sample/genaisrc/pr-describe.genai.js?raw"
import prDescribeSrc from "../../../../../packages/sample/genaisrc/pr-describe.genai.mjs?raw"

Check failure on line 13 in docs/src/content/docs/getting-started/automating-scripts.mdx

View workflow job for this annotation

GitHub Actions / build

The import statement for 'prDescribeSrc' has an incorrect file extension. It should be '.js' instead of '.mjs'.
Copy link

Choose a reason for hiding this comment

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

The import statement for 'prDescribeSrc' has an incorrect file extension. It should be '.js' instead of '.mjs'.

generated by pr-docs-review-commit incorrect_extension

Copy link

Choose a reason for hiding this comment

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

The file extension for the imported script should be .js instead of .mjs to maintain consistency with the existing codebase.

generated by pr-docs-review-commit incorrect_file_extension


Once you have a script that you are happy with, you can automate it using the [command line interface](/genaiscript/reference/cli).

Expand Down
16 changes: 16 additions & 0 deletions docs/src/content/docs/reference/scripts/git.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: Git
description: git helpers
sidebar:
order: 51
---

The `git` helper provides a thin wrapper around invoking the [git](https://git-scm.com/) executable.

Choose a reason for hiding this comment

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

Consider providing an example of how to invoke the git helper for clarity.

generated by pr-docs-review-commit documentation_content


## defaultBranch

Resolve the default branch, typically `main` or `master` in the repository.

```js
const df = await git.defaultBranch()

Choose a reason for hiding this comment

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

The code snippet is missing the function call to execute the git.defaultBranch method. It should be git.defaultBranch() instead of await git.defaultBranch(). The await keyword is used with asynchronous functions, and there is no indication that git.defaultBranch is an asynchronous function in this context. If it is asynchronous, the function should be called within an async function or a thenable context.::

generated by pr-docs-review-commit missing_function_call

Choose a reason for hiding this comment

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

The variable df is not descriptive; consider using a more descriptive variable name like defaultBranch.

generated by pr-docs-review-commit variable_naming

Copy link

Choose a reason for hiding this comment

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

The await keyword is used without an async function context. The code snippet should be inside an async function or the documentation should mention that it needs to be used within one.

generated by pr-docs-review-commit await_usage

Copy link

Choose a reason for hiding this comment

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

Missing 'await' keyword before 'git.defaultBranch()' function call.

generated by pr-docs-review-commit missing_await

```

Check failure on line 16 in docs/src/content/docs/reference/scripts/git.md

View workflow job for this annotation

GitHub Actions / build

The code example for 'git.defaultBranch' is incomplete. It should include the import statement and possibly more context for clarity.
Copy link

Choose a reason for hiding this comment

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

The code snippet is missing the declaration for the 'git' variable. It should show how to import or require the 'git' helper module.

generated by pr-docs-review-commit missing_variable_declaration

Copy link

Choose a reason for hiding this comment

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

The code snippet is missing the function declaration for git.defaultBranch. It should be preceded by an import statement or a function declaration to provide context.

generated by pr-docs-review-commit missing_function_declaration

Copy link

Choose a reason for hiding this comment

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

The code example for 'git.defaultBranch' is incomplete. It should include the import statement and possibly more context for clarity.

generated by pr-docs-review-commit missing_code_example

4 changes: 2 additions & 2 deletions genaisrc/commit-msg.genai.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const msgContent = msg.content
if (msgContent) cancel("commit message already exists")

// Check for staged changes and stage all changes if none are staged
let diff = await host.exec("git diff --cached")
const diff = await git.diff({ staged: true, askStageOnEmpty: true })

if (!diff.stdout) cancel("no staged changes")
if (!diff) cancel("no staged changes")
// Generate commit message
const res = await runPrompt(
(_) => {
Expand Down
53 changes: 53 additions & 0 deletions genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions packages/auto/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions packages/cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
const content = trace.content
writeFileSync(filename, content, { encoding: "utf-8" })
})
return filename
}

export async function runScriptWithExitCode(
Expand Down Expand Up @@ -179,12 +180,13 @@
if (removeOut) await emptyDir(out)
await ensureDir(out)
}
let outTraceFilename
if (outTrace && !/^false$/i.test(outTrace) && trace)

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

View workflow job for this annotation

GitHub Actions / build

Missing semicolon
Copy link

Choose a reason for hiding this comment

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

Missing semicolon

generated by pr-review-commit missing_semi

await setupTraceWriting(trace, outTrace)
outTraceFilename = await setupTraceWriting(trace, outTrace)
if (out && trace) {
const ofn = join(out, "res.trace.md")
if (ofn !== outTrace) {
await setupTraceWriting(trace, ofn)
outTraceFilename = await setupTraceWriting(trace, ofn)
}
}

Expand Down Expand Up @@ -521,6 +523,7 @@
if (failOnErrors && result.annotations?.some((a) => a.severity === "error"))
return fail("error annotations found", ANNOTATION_ERROR_CODE)

if (outTraceFilename) logVerbose(`trace: ${outTraceFilename}`)
logVerbose("genaiscript: done\n")
return { exitCode: 0, result }
}
4 changes: 2 additions & 2 deletions packages/core/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
renderShellOutput,
} from "./chatrender"
import { promptParametersSchemaToJSONSchema } from "./parameters"
import { fenceMD } from "./markdown"
import { fenceMD, prettifyMarkdown } from "./markdown"
Copy link

Choose a reason for hiding this comment

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

The function prettifyMarkdown is imported but it is not defined in the ./markdown module.

generated by pr-review-commit missing_import

import { YAMLStringify } from "./yaml"

export function toChatCompletionUserMessage(
Expand Down Expand Up @@ -647,6 +647,6 @@ export async function executeChatSession(

export function tracePromptResult(trace: MarkdownTrace, resp: RunPromptResult) {
const { json, text } = resp
trace.details(`🔠 output`, text, { expanded: true })
trace.details(`🔠 output`, prettifyMarkdown(text), { expanded: true })
Copy link

Choose a reason for hiding this comment

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

The function prettifyMarkdown is called but it is not defined in the ./markdown module.

generated by pr-review-commit undefined_function

if (resp.json) trace.detailsFenced("📩 JSON (parsed)", json, "json")
}
Loading