Request icon
ChatCompletion icon
Webhook icon

Automatically Review GitHub Pull Requests with OpenAI GPT-4o and Post Comments

Automatically review GitHub pull requests with OpenAI GPT-4o on Kestra. Fetch the diff, generate a structured, severity-rated review, and post it as a PR comment.

Categories
AIInfrastructure

Automate first-pass GitHub pull request code review with OpenAI GPT-4o. This blueprint fetches the PR diff and metadata from the GitHub REST API, sends them to GPT-4o together with your custom coding guidelines, and posts a structured, severity-rated review back onto the pull request as a comment. It solves the bottleneck of slow, inconsistent, manual code review: every PR gets immediate, standards-aligned feedback before a human reviewer ever opens it, cutting review latency and enforcing the same rules on every change.

How it works

  1. The github_webhook trigger (io.kestra.plugin.core.trigger.Webhook) starts the flow on demand, secured by a webhook key, so GitHub Actions, an external CI step, or a manual call can launch a review.
  2. fetch_pr_diff (io.kestra.plugin.core.http.Request) calls the GitHub pulls/{number}/files endpoint to retrieve every changed file and its diff.
  3. fetch_pr_metadata (io.kestra.plugin.core.http.Request) pulls the PR title and description for additional context.
  4. generate_review (io.kestra.plugin.openai.ChatCompletion) sends the diff, metadata, and your review_guidelines input to GPT-4o (model: gpt-4o, maxTokens: 2000), which returns a Summary, severity-tagged Issues Found (CRITICAL, MAJOR, MINOR), Suggestions, and a final Verdict.
  5. post_review_comment (io.kestra.plugin.core.http.Request) POSTs the review to the GitHub Issues comments endpoint so it appears directly on the PR.

What you get

  • Consistent, guideline-driven review feedback on every pull request.
  • Severity-rated findings (CRITICAL, MAJOR, MINOR) plus a clear approve or changes-requested verdict.
  • Faster review cycles: AI feedback lands before a human reviewer starts.
  • A fully auditable run history of every review in the Kestra UI.

Who it's for

  • Engineering teams wanting consistent first-pass coverage across all PRs.
  • Open source maintainers facing high PR volume and limited bandwidth.
  • Solo developers who want an AI pair reviewer before human review.
  • Platform teams that must enforce custom security, style, or API-contract rules.

Why orchestrate this with Kestra

GitHub and the OpenAI API have no shared scheduler that can chain diff retrieval, an LLM call, and a comment post into one observable, retryable pipeline. Kestra fills that gap: the event-driven Webhook trigger reacts to PR activity in real time, declarative YAML keeps the whole review logic version-controlled and reviewable, each HTTP and ChatCompletion task can carry independent retries against API rate limits or timeouts, and every execution is captured with inputs, outputs, and logs for full lineage and replay.

Prerequisites

  • A GitHub repository and a token with permission to read pull requests and post comments.
  • An OpenAI API key with access to GPT-4o.

Secrets

  • GITHUB_TOKEN: GitHub token used to read the PR diff and metadata and to post the review comment.
  • OPENAI_API_KEY: OpenAI API key for the GPT-4o ChatCompletion call.
  • WEBHOOK_KEY: secret value securing the webhook trigger URL.

Quick start

  1. Add GITHUB_TOKEN, OPENAI_API_KEY, and WEBHOOK_KEY as secrets in your Kestra instance.
  2. Set the repo_owner, repo_name, and pull_number inputs (or wire them into the webhook payload).
  3. Adjust the review_guidelines input to match your team's standards.
  4. Execute the flow manually, or call the webhook URL to trigger a review and check the comment on your PR.

How to extend

  • Load review_guidelines dynamically from a database, Git file, or Notion page.
  • Add a GitHub label such as "AI-reviewed" after the comment posts.
  • Escalate CRITICAL findings to a Slack channel or open a follow-up issue.
  • Swap the model or add a second pass that comments inline on specific lines.

Links

Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.