How dicodingacademy/senpai-action works
Project type and purpose
• From the file tree and README, this is an open‑source GitHub Action (“SenpAI”) that runs automated, AI‑powered code reviews using Google’s Gemini model. It’s not a web app or full‑stack project, but rather a CLI‑style action that plugs into GitHub’s workflow engine, reads diffs, queries Gemini, and posts comments back to PRs.
File structure
• Top‑level:
• .github/workflows/*.yml – workflow definitions that trigger the action.
• action.yml – action metadata (inputs, outputs, runs).
• src/index.js – the entry point.
• src/lib/ – helper modules:
– config.js (reads inputs, sets defaults)
– diff-parser.js (extracts changed lines)
– comment-parser.js (builds comment payloads)
– gemini-client.js (wraps HTTP calls to Google Gemini)
– github-client.js (wraps GitHub REST API calls)
• dist/index.js – built/bundled code delivered to npm.
• eslint.config.mjs, package.json – linting and dependencies.
• README.md – overview & usage.
README for additional insights
• Describes triggers (pull_request, issue_comment), required secrets (GEMINI_API_KEY), and customization inputs (model, exclusions, tone).
• Workflow example shows how to integrate the action step.
Main components & relationships
a. Components:
1. GitHub Platform – hosts repo, emits events, hosts Actions runner.
2. Workflow Definition (.github/workflows) – listens for PRs or comments.
3. SenpAI Action (action.yml + dist/index.js) – the packaged action.
4. Internal Modules (at runtime in the Action container):
• Config Loader
• Diff Parser
• Gemini Client (external API)
• Comment Parser
• GitHub Client
5. External Service – Google Gemini API
6. GitHub REST API
b. Interactions / Data Flow:
1. PR opened or /review comment → GitHub emits event → Workflow triggers.
2. Actions runner checks out code.
3. SenpAI action starts (dist/index.js):
• Load inputs/secrets (config).
• Read PR diff (diff-parser).
• Call Google Gemini API with code snippets (gemini-client).
• Receive analysis & feedback from Gemini.
• Build line‑by‑line comments (comment-parser).
• Post comments to GitHub PR via GitHub API (github-client).
c. Architectural patterns & design principles:
• Modular library pattern: each concern (config, parsing, external calls) is isolated.
• Single‑responsibility modules.
• Facade/wrapper around external services (Gemini, GitHub) to simplify error handling and retries.
• Event‑driven flow (GitHub events trigger the action).
d. Key technologies/frameworks:
• Node.js
• GitHub Actions toolkit (action.yml conventions)
• Google Gemini REST API
• GitHub REST API v3
• Inside “Action Container,” chain: Config → Diff Parser → Gemini Client → Comment Parser → GitHub Client.
• Triggers entering the flow from the top (GitHub Event → Checkout → Action).
• Use consistent iconography (GitHub octocat, Google Gemini logo) to improve readability.