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

upload annotations in github pull requests #501

Merged
merged 33 commits into from
Jun 2, 2024
Merged

upload annotations in github pull requests #501

merged 33 commits into from
Jun 2, 2024

Conversation

pelikhan
Copy link
Member

@pelikhan pelikhan commented Jun 1, 2024

Add CLI option to upload annotations as pull request comments.

  • 🆕 Added a new CLI option -prr, --pull-request-reviews to create pull request reviews from annotations in docs/src/content/docs/reference/cli/commands.md and packages/cli/src/cli.ts.
  • 🏁 Made the run command the default command in the CLI by adding { isDefault: true } in packages/cli/src/cli.ts.
  • 📝 Modified the runScript function in packages/cli/src/run.ts to support the new pullRequestReviews option.
  • 🚀 Implemented the githubCreatePullRequestReviews function in packages/core/src/github.ts to create pull request reviews based on annotations.
  • 🧹 Cleaned up and refactored the parseAnnotations function in packages/core/src/annotations.ts to prevent duplicate annotations by using a Record instead of an array.
  • 🛠️ Updated githubUpsetPullRequest and githubCreateIssueComment functions in packages/core/src/github.ts to include the new script parameter and append a generated comment with a link to the run URL.
  • 🛂 Added GITHUB_TOKEN constant to packages/core/src/constants.ts for better token management.
  • 🔄 Modified createFetch function in packages/core/src/fetch.ts to return crossFetch directly if retryOn array is empty.
  • ✨ Enhanced githubCreatePullRequestReview in packages/core/src/github.ts to create individual pull request review comments.
  • 📊 Updated runTemplate function in packages/core/src/promptrunner.ts to map annotations to include the line number in the output.
  • 🛠️ Improved relativePath function in packages/core/src/util.ts for better path handling.
  • 📝 Added link function in packages/core/src/markdown.ts to create markdown links.

generated by genaiscript pr-describe

@microsoft microsoft deleted a comment from github-actions bot Jun 1, 2024
@microsoft microsoft deleted a comment from github-actions bot Jun 1, 2024
packages/core/src/github.ts Outdated Show resolved Hide resolved
packages/core/src/github.ts Outdated Show resolved Hide resolved
}
}

// https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#update-a-pull-request
export async function githubUpsetPullRequest(
script: PromptScript,
info: GithubConnectionInfo,
text: string,
commentTag: string
) {
const { apiUrl, repository, issue } = info

Copy link

Choose a reason for hiding this comment

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

The 'GITHUB_TOKEN' constant is being used as a secret key, but it should be using the 'token' from 'GithubConnectionInfo' which is already extracted from the environment.

generated by genaiscript pr-review-commit

const url = `${apiUrl}/repos/${repository}/issues/${issue}/comments`

body = appendGeneratedComment(script, info, body)

if (commentTag) {
const tag = `<!-- genaiscript ${commentTag} -->`
Copy link

Choose a reason for hiding this comment

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

The 'appendGeneratedComment' function is being called without checking if 'info.runUrl' is defined, which could lead to incorrect markdown formatting if 'info.runUrl' is undefined.

generated by genaiscript pr-review-commit

info: GithubConnectionInfo,
body: string,
commentTag?: string
commentTag: string
Copy link

Choose a reason for hiding this comment

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

The 'appendGeneratedComment' function is being called without checking if 'info.runUrl' is defined, which could lead to incorrect markdown formatting if 'info.runUrl' is undefined.

generated by genaiscript pr-review-commit

@@ -66,13 +83,13 @@ export async function githubUpsetPullRequest(
const resGetJson = (await resGet.json()) as { body: string }
let { body } = resGetJson
if (!body) body = ""
Copy link

Choose a reason for hiding this comment

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

The 'appendGeneratedComment' function is being called without checking if 'info.runUrl' is defined, which could lead to incorrect markdown formatting if 'info.runUrl' is undefined.

generated by genaiscript pr-review-commit

Copy link

github-actions bot commented Jun 2, 2024

The pull request introduces several changes across multiple files in a TypeScript project. Here's a high-level review of the changes:

  1. CLI Command Updates: The run command in cli.ts is now set as the default command, and a new option --pull-request-reviews is added to create pull request reviews from annotations.

  2. Functionality Enhancements: In run.ts, the new --pull-request-reviews option is handled to create pull request reviews if there are any annotations. Additionally, the handling of pull request comments and descriptions has been updated to use the new githubCreatePullRequestReviews function.

  3. Annotation Parsing: In annotations.ts, the parsing of annotations has been refactored to use a record object instead of an array, which helps in deduplicating annotations. The relativePath function is now used to handle file paths.

  4. Constants: In constants.ts, a new constant GITHUB_TOKEN is defined, which is likely used for authentication purposes.

  5. Fetch Utility: In fetch.ts, a conditional return is added to bypass the retry wrapper if there are no conditions specified for retrying.

  6. GitHub Integration: The github.ts file sees significant changes with new functions for creating pull request reviews and updating pull request descriptions. There's also improved error handling and verbose logging. The parseGHTokenFromEnv function is expanded to include additional environment variables related to GitHub Actions.

  7. Markdown Utilities: In markdown.ts, a new link function is added to create markdown links.

  8. Prompt Runner: In promptrunner.ts, the CSV to Markdown conversion for annotations now includes the line number directly from the annotation's range.

  9. Utility Functions: In util.ts, the relativePath function is updated for better path handling, and the logError function now conditionally logs additional error details.

Overall, the changes seem to focus on enhancing the CLI tool's integration with GitHub, particularly around handling pull request reviews and comments. The refactoring and addition of new utility functions suggest an improvement in code quality and maintainability.

Concerns:

  • The changes are extensive and touch multiple core functionalities, which could introduce regressions if not thoroughly tested.
  • The reliance on environment variables for GitHub Actions integration means that proper configuration is crucial, and there's a potential for misconfiguration.
  • The changes assume the presence of certain environment variables (GITHUB_TOKEN, GITHUB_COMMIT_SHA, etc.), which may not be set in all environments.

Given the scope of the changes and assuming proper testing and configuration management practices are in place, the pull request looks good to me.

LGTM (Looks Good To Me).

generated by genaiscript pr-review

@@ -12,6 +14,9 @@ export interface GithubConnectionInfo {
ref?: string
sha?: string
issue?: number
runId?: string
runUrl?: string
commitSha?: string
}

export function parseGHTokenFromEnv(
Copy link

Choose a reason for hiding this comment

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

The parseGHTokenFromEnv function has been updated to include runId, runUrl, and commitSha but the corresponding interface GithubConnectionInfo has not been updated to reflect these changes.

generated by genaiscript pr-review-commit

const url = `${apiUrl}/repos/${repository}/issues/${issue}/comments`

body = appendGeneratedComment(script, info, body)

if (commentTag) {
const tag = `<!-- genaiscript ${commentTag} -->`
Copy link

Choose a reason for hiding this comment

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

The githubCreateIssueComment function is using a retryOn array that is empty, which means the fetch will not retry. If retries are intended, this array should include conditions for when to retry.

generated by genaiscript pr-review-commit

@pelikhan pelikhan merged commit 313f6e7 into main Jun 2, 2024
7 of 8 checks passed
@pelikhan pelikhan deleted the ghcannotations branch June 2, 2024 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant