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

Setting up a new Github Action Application for AI Support #3

Merged
merged 96 commits into from
Jun 5, 2024

Conversation

DarrellRichards
Copy link
Collaborator

@DarrellRichards DarrellRichards commented Jun 3, 2024

Summary of Changes

Workflow Updates

  • GitHub Actions Workflow:
    • Updated from setup-node@v2 to setup-node@v4.
    • Specified Node.js version to 18.
    • Added steps to install dependencies (npm install) and build the code (npm run build).

Input Modifications

  • Custom Action Inputs Modifications:
    • Updated github_token, openai_api_key, and openai_model values.
    • Added excluded_files input to exclude files such as node_modules, package.json, package-lock.json.
    • Changed github-token to github_token for naming consistency.
    • Removed pr-number input and added excluded_files input with a default of node_modules, package-lock.json, yarn.lock.

New Inputs

  • New Inputs in action.yml:
    • generate_summary: Generates a Pull Request summary based on git diff and code changes. Defaults to false.
    • overall_code_review: Allows for an overall code review to be made as a comment. Defaults to false.

Dependency Updates

  • Dependencies Updated in package-lock.json:
    • Removed @tandil/diffparse.
    • Added @octokit/types and parse-diff.

Code Modifications

  • package-lock.json Modifications:

    • Removed @tandil/diffparse version 0.2.0.
    • Added parse-diff version 0.11.1.
  • index.ts Updates:

    • Replaced the previous parser module with parse-diff.
    • Introduced multiple imports for GitHub Actions and AI services.
    • Implemented functions for validating pull requests (validatePullRequest), code (validateCode), and overall code reviews (validateOverallCodeReview).
    • Main function updated to handle actions like opened and synchronize and call appropriate validation functions.
    • Updated diff data handling to exclude specified files.

New Service Files

  • src/services/ai.ts:

    • Integrates OpenAI's API for functionalities like creating messages, generating PR summaries, feedback, and validating code.
    • Functions: createMessage, prSummaryCreation, obtainFeedback, summaryOfAllFeedback, summaryAllMessages, validateCodeViaAI.
  • src/services/github.ts:

    • Facilitates interactions with GitHub's API using the @octokit/rest library.

Copy link

github-actions bot commented Jun 3, 2024

Pull Request: Enhancements and Refactoring for GitHub Actions Workflow with AI Support

Overview

This pull request introduces multiple updates and enhancements to the GitHub Actions workflow configuration file .github/workflows/action.yml. The aim is to improve the code checkout and build process, set up a Node environment, install dependencies, build the code, and run custom actions with updated configurations. Major changes include updating input parameters, dependency management, and the introduction of functionality for AI support.

Updates and Enhancements

Workflow Configuration

  • Enhanced the GitHub Actions workflow for a more logical and modular setup.
  • Updated setup-node@v2 to setup-node@v4 with Node version 18 to use the latest tools.
  • Added npm install and npm run build commands to ensure dependencies are installed and code is built before custom action runs.
  • Changed from secrets.OPENAI_API_KEY to secrets.OPEN_AI_KEY to align with current naming conventions.

Action Input Parameters

  • Renamed input parameters in action.yml: github-token to github_token and pr-number to excluded_files.
  • Introduced new input parameters: generate_summary and overall_code_review for AI support.
  • Updated parameter descriptions for better clarity and consistency.

Dependency Updates

  • Replaced @tandil/diffparse with @octokit/types in package.json to utilize more standardized tools for interacting with the GitHub API.
  • Added new dependency parse-diff for parsing diff data, assisting in analyzing changes in pull requests and commits.

Code Enhancements

  • Introduced a robust approach to handling pull request events in src/index.ts.
  • Extensively used services for GitHub operations and AI validations, resulting in cleaner and more modular code.
  • Added multiple input options for enhanced workflow control: excluded_files, generate_summary, review_code, and overall_code_review.
  • Improved readability by using template literals for message creation.

Recommendations

Correct Naming Conventions

  • Change github_token back to github-token to conform to GitHub actions input naming conventions.
  • Fix the typo gpt-4o to gpt-4 for the OpenAI model parameter.
  • Correct the spelling of expluded_files to excluded_files.

Added Documentation and Clarity

  • Ensure consistency in renaming github-token to github_token across all scripts and configurations.
  • Provide detailed descriptions and examples for new input parameters to ensure user clarity.
  • Include documentation on how excluded_files should be used and its impact on the workflow.
  • Update README or contributing documents to reflect new dependencies and provide context for the switch from @tandil/diffparse to parse-diff.

Error Handling and Unit Testing

  • Add comprehensive error handling for all asynchronous calls, especially for interactions with the OpenAI and GitHub APIs.
  • Implement more informative logging to help trace execution flow and potential issues.
  • Include unit tests for new functions to ensure they work correctly and handle edge cases.
  • Refactor repetitive mapping logic into helper functions to reduce redundancy.
  • Ensure functions like createMessage, prSummaryCreation, obtainFeedback, summaryOfAllFeedback, summaryAllMessages, and validateCodeViaAI have error handling and logging.

TypeScript Improvements

  • Avoid using any by defining types for repo in the Event interface and repository in PRDetails.
  • Address TypeScript issues by defining types for chunk.changes instead of using @ts-expect-error.

Conclusion

The proposed updates enhance the workflow for the AI support application via GitHub Actions. Addressing the minor errors, enhancing clarity, and adding robust error handling and documentation will help solidify the setup and ensure smooth execution. Overall, these changes represent a significant step towards an improved and flexible GitHub Action for AI support.

.github/workflows/action.yml Outdated Show resolved Hide resolved
.github/workflows/action.yml Show resolved Hide resolved
.github/workflows/action.yml Outdated Show resolved Hide resolved
.github/workflows/action.yml Outdated Show resolved Hide resolved
action.yml Show resolved Hide resolved
src/services/github.ts Show resolved Hide resolved
src/services/github.ts Show resolved Hide resolved
src/services/github.ts Show resolved Hide resolved
src/services/github.ts Show resolved Hide resolved
src/services/github.ts Outdated Show resolved Hide resolved
openai_model: 'gpt-4'
github_token: ${{ secrets.GITHUB_TOKEN }}
openai_api_key: ${{ secrets.OPEN_AI_KEY }}
openai_model: "gpt-4o"
review_code: true
Copy link

Choose a reason for hiding this comment

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

There appears to be a typo here. The input key should be excluded_files instead of expluded_files.

src/index.ts Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
src/services/github.ts Show resolved Hide resolved
src/services/github.ts Show resolved Hide resolved
src/services/github.ts Show resolved Hide resolved
src/services/github.ts Show resolved Hide resolved
src/services/github.ts Show resolved Hide resolved
openai_model: 'gpt-4'
github_token: ${{ secrets.GITHUB_TOKEN }}
openai_api_key: ${{ secrets.OPEN_AI_KEY }}
openai_model: "gpt-4o"
Copy link
Member

Choose a reason for hiding this comment

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

@DarrellRichards make this configurable but defaulted to this model

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Already completed (:

src/index.ts Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
action.yml Show resolved Hide resolved
action.yml Show resolved Hide resolved
action.yml Show resolved Hide resolved
@DarrellRichards DarrellRichards merged commit dfbdf77 into main Jun 5, 2024
1 check passed
@DarrellRichards DarrellRichards deleted the testing branch June 5, 2024 02:38
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.

2 participants