How aidar-freeed/ai-codereviewer works
Main Components
• GitHub Repository – This represents the overall project storage which contains code, configuration, and documentation.
• GitHub Workflows – Located in the ".github/workflows" directory (e.g., code_review.yml), these automate the trigger process on pull requests.
• Action Definition – The action.yml file defines how the GitHub Action operates and integrates with workflows.
• Source Code – The "src/main.ts" file holds the core logic of the action. It is compiled using TypeScript (configured by tsconfig.json) and output to the "dist" directory.
• Build Process – Use package.json (and related scripts) along with build steps (as in “yarn build” and “yarn package”) to compile source code.
• External API – OpenAI’s GPT-4 API is the external service that processes code chunks and returns review comments.
• GitHub PR and API Integration – This interacts with GitHub’s pull request API (using github token) to fetch diffs, post review comments, and manage file filtering (e.g., excluding JSON or Markdown files).
Relationships & Interactions
• Pull Request Event: When a pull request is opened or updated, GitHub triggers the workflow defined in the .github/workflows folder.
• Workflow Runner: The runner checks out the repo then invokes the GitHub Action defined by action.yml.
• Action Invocation: This action invokes the code in “src/main.ts” (already built and prepared in the “dist” folder).
• Code Processing: The action processes the PR diff, filters excluded files as specified, and batches code chunks.
• External Integration: The code makes API calls to OpenAI’s GPT-4 to generate code review suggestions.
• Response Handling: The AI-generated comments are then posted back to the pull request via the GitHub API using the provided token.
• Feedback Loop: The final outcome – review comments – appears on the original pull request for developers to view.
Architectural Patterns & Design Principles
• Separation of Concerns: Notice the clear division between the GitHub Actions (trigger and workflow definitions) and the core review logic (implemented in the source code).
• Modular Design: The structure separates build artifacts (“dist”) from source code (“src”), making it easier to maintain and extend.
• External Dependency Integration: The clear boundary of communication with the OpenAI API encapsulates external service interaction.
• CI/CD Integration: Use of GitHub Actions workflows emphasizes continuous integration and delivery of AI-based code review feedback.
Relevant Technologies & Frameworks
• TypeScript for robust and strongly typed code in “src/main.ts”.
• Node.js as the runtime (implied by package.json and build scripts).
• GitHub Actions and related YAML configuration files.
• OpenAI GPT-4 API for generating review insights.
• GitHub API for fetching pull request data and posting review comments.