> For the complete documentation index, see llms.txt.
Skip to main content

Check out Port for yourself ➜ 

Enrich pull requests using AI

Implement with AI

Send this guide to your coding agent.

Prerequisite: Install Port MCP

Open plan mode if your tool supports it; otherwise present the plan below filled in and wait for my approval. Implement this Port guide in my org via MCP:

https://docs.port.io/guides/all/setup-pr-enricher-ai-agent

Read the raw markdown version at https://docs.port.io/guides/all/setup-pr-enricher-ai-agent.md - it contains every tab and code block without page markup.

Goal: get the guide's core flow working end-to-end in my org; adapting it to fit my existing setup takes priority over matching the guide 1:1.

Plan:
1. Confirm MCP is connected, in the right org, with sufficient permissions.
2. If the guide offers alternative implementation paths (tabs), pick the one matching my installed integrations and tools, confirm it with me, and implement only that path.
3. Diff the guide's data model (blueprints, properties, relations, workflows, actions, agents, automations, integrations, webhook data sources, secrets) against mine.
4. Propose adaptations for gaps, reusing existing blueprints/relations over guide-named duplicates.
5. Flag what needs a UI click, credential, or secret from me, testing MCP capability empirically before ruling anything out. If the guide has a "Set up via API" section, use it for anything MCP can't do before treating a step as UI-only.
6. Stop on any blocker and give me options. Approving this plan authorizes the writes it lists; pause only for writes beyond what's listed.

Build:
- Extend blueprint schema additively when upserting; don't remove or overwrite existing properties, and treat type conflicts as a blocker, not an auto-fix.
- Never print secret values into the chat or logs; ask me to set them in Port, or write them via the secrets API without echoing them back.
- List any mock data in the plan, minimal and labeled mock; once approved, seed it without re-asking, and tell me what you seeded.
- For anything the guide writes downstream (e.g. a webhook target), use a real entity, not a mock.
- For pages/widgets, use the real page identifier from the app URL, not a guessed slug.
- When you hit a UI step confirmed (not assumed) unsupported via MCP and not covered by the guide's API sections, pause, give exact clicks, then resume via MCP.
- Validate and give links after each meaningful step (only a tool-returned URL, no guessed paths); don't proceed if the last run wasn't a success.

Done:
- Run the guide's "Let's test it" steps where possible (e.g. execute a workflow test run) and confirm the expected output exists in Port.
- Summarize adaptations, seeded data, what was mocked or skipped, remaining UI steps, and how to verify.

This guide walks you through setting up a "Pull Request Enricher" using Port workflows and an AI agent.
By the end of this guide, your developers will receive automated, contextual comments on their pull requests to help streamline the review process.

This guide uses a single event-triggered workflow. When a pull request is opened, the workflow invokes an AI agent to analyze it and then dispatches a GitHub Actions workflow to post the agent's response as a comment.

New GitHub pull request triggers Port AI analysis, which posts an enrichment summary back to the pull request

Common use cases

  • Automatically comment on new pull requests with assessments based on PR metadata.
  • Highlight potential areas of concern.
  • Provide context from related Jira tickets directly in the PR comments.
  • Suggest relevant reviewers based on code changes.

Prerequisites

This guide assumes you have:

How it works

The workflow chains three nodes:

  1. An event trigger that fires when a githubPullRequest entity is created with status set to open.
  2. An AI node that invokes the PR Review Assistant agent. The workflow pauses until the AI invocation completes, then exposes the agent's response as an output.
  3. A GitHub dispatch node that triggers a GitHub Actions workflow to post the agent's response as a PR comment.

Set up data model

First, we will create the Pull Request Enricher AI agent in Port.
We will need to configure:

  • The data sources it will use to analyze pull requests.
  • The agent configuration that defines its capabilities.

Configure data source access

For this guide, we will be using GitHub as our data source to provide comprehensive pull request analysis capabilities. Make sure you have Port's GitHub Ocean integration installed and configured.

Additional data sources

While this guide uses GitHub, you can enhance the agent's capabilities by adding other data sources like:

  • PagerDuty for checking active incidents.
  • Your context lake services for broader context.

Create the agent configuration

  1. Go to the AI Agents page in Port.

  2. Click on + AI Agent.

  3. Toggle Json mode on.

  4. Copy and paste the following JSON schema:

    Pull Request Enricher agent configuration (Click to expand)
    {
    "identifier": "pr_assistant_ai_agent",
    "title": "PR Review Assistant",
    "description": "AI agent that analyzes pull requests and provides helpful context for reviewers",
    "icon": "Pipeline",
    "properties": {
    "description": "Comment on open PRs with additional context to assist developers",
    "status": "active",
    "tools": [
    "^(list|search|describe|track)_.*"
    ],
    "prompt": "Analyze pull request details and provide a structured review in the following format:\n\nPR Description:\n Summarize the PR description and key properties in one sentence \n\nKey Points:\n{{ List up to 3 key insights about the changes }}\n\nObservations:\nProvide up to 3 observations using 🟢 for low risk, 🟡 for medium risk, and 🔴 for high risk\n\nRecommendations:\nList up to 3 optional recommendations for improvement. Provide this in markdown format",
    "execution_mode": "Automatic"
    },
    "relations": {}
    }
  5. Click on Create to save the agent.

Build the workflow

Now let's create the workflow that ties the trigger, the AI agent, and the comment dispatch together.

The workflow uses an INTEGRATION_ACTION node to dispatch the GitHub Actions workflow. With the GitHub Ocean integration, you do not need to add a GitHub token to Port secrets. The integration handles workflow dispatch authentication.

To build the workflow:

  1. Go to the Workflows page in Port.

  2. Click on the + Workflow button.

  3. Fill out the Create new workflow form, then click Confirm.

  4. click on the workflow you have created.

  5. On the editor page, click the see workflow JSON button ({...}) to open the JSON editor.

  6. Copy and paste the workflow JSON below into the editor to replace the example workflow:

    PR Enricher workflow JSON (Click to expand)
    {
    "identifier": "pr_enricher",
    "title": "PR Enricher",
    "icon": "Pipeline",
    "description": "Analyze newly opened pull requests with an AI agent and post the result as a PR comment",
    "nodes": [
    {
    "identifier": "trigger",
    "title": "On PR opened",
    "icon": "Github",
    "description": "Trigger when a pull request is opened",
    "config": {
    "type": "EVENT_TRIGGER",
    "event": {
    "type": "ENTITY_CREATED",
    "blueprintIdentifier": "githubPullRequest"
    },
    "condition": {
    "type": "JQ",
    "expressions": [
    ".diff.after.properties.status == \"open\""
    ],
    "combinator": "and"
    }
    },
    "variables": {}
    },
    {
    "identifier": "enrich_pr",
    "title": "Analyze PR with AI agent",
    "icon": "AI",
    "description": "Invoke the PR Review Assistant agent",
    "config": {
    "type": "AI_AGENT",
    "agentIdentifier": "pr_assistant_ai_agent",
    "userPrompt": "Analyze pull request with entity identifier '{{ .outputs.trigger.diff.after.identifier }}'"
    },
    "variables": {}
    },
    {
    "identifier": "post_pr_comment",
    "title": "Post PR comment",
    "icon": "Github",
    "description": "Dispatch the GitHub Actions workflow that posts the agent response as a PR comment",
    "config": {
    "type": "INTEGRATION_ACTION",
    "installationId": "<YOUR_GITHUB_OCEAN_INTEGRATION_ID>",
    "integrationProvider": "github-ocean",
    "integrationInvocationType": "dispatch_workflow",
    "integrationActionExecutionProperties": {
    "org": "<YOUR_GITHUB_ORG>",
    "repo": "<YOUR_GITHUB_REPO>",
    "workflow": "post-pr-comment.yml",
    "workflowInputs": {
    "comment": "{{ .outputs.enrich_pr.response }}",
    "pr": "{{ .outputs.trigger.diff.after.properties.prNumber | tostring }}",
    "repo": "{{ (.outputs.trigger.diff.after.properties.link | tostring | split(\"/\"))[3] + \"/\" + ((.outputs.trigger.diff.after.properties.link | tostring | split(\"/\"))[4]) }}"
    },
    "reportWorkflowStatus": true
    }
    },
    "variables": {}
    }
    ],
    "connections": [
    {
    "sourceIdentifier": "trigger",
    "targetIdentifier": "enrich_pr"
    },
    {
    "sourceIdentifier": "enrich_pr",
    "targetIdentifier": "post_pr_comment"
    }
    ]
    }
    Replace placeholders

    Make sure to replace YOUR_GITHUB_OCEAN_INTEGRATION_ID, YOUR_GITHUB_ORG, and YOUR_GITHUB_REPO with your GitHub Ocean integration ID and the organization and repository where your post-pr-comment.yml workflow resides. You can find the integration ID on the Data sources page in Port.

  7. Click Save to save the workflow.

Create the GitHub workflow

Now let's create the workflow file that contains the logic to post the comment.

Dedicated Workflows Repository

We recommend creating a dedicated repository for the workflows that are used by Port actions.

Choose the authentication method that best fits your setup:

This approach uses your personal GitHub account to comment on pull requests. It's simpler to set up but comments will appear from your personal account.

In your dedicated workflow repository, ensure you have a .github/workflows directory.

  1. Create a new file named post-pr-comment.yml.

  2. Copy and paste the following snippet:

    Post PR comment workflow using PAT (Click to expand)
    name: Comment on PR

    on:
    workflow_dispatch:
    inputs:
    comment:
    description: 'The comment text to post'
    required: true
    type: string
    repo:
    description: 'Repository in "owner/repo" format (e.g., port-labs/puddle-integrations)'
    required: true
    type: string
    pr:
    description: 'Pull request number'
    required: true
    type: string

    jobs:
    comment:
    runs-on: ubuntu-latest
    steps:
    - name: Comment on PR using PAT
    env:
    GITHUB_TOKEN: ${{ secrets.PORT_GITHUB_TOKEN }}
    COMMENT: ${{ github.event.inputs.comment }}
    REPO: ${{ github.event.inputs.repo }}
    PR_NUMBER: ${{ github.event.inputs.pr }}
    run: |
    # Split repo into owner and name
    OWNER=$(echo "$REPO" | cut -d'/' -f1)
    REPO_NAME=$(echo "$REPO" | cut -d'/' -f2)

    # Post comment to PR using GitHub CLI
    echo "$COMMENT" | gh pr comment "$PR_NUMBER" --repo "$OWNER/$REPO_NAME" --body-file -
    Required GitHub Secrets

    For this workflow to function properly, you need to add the following secret to your GitHub repository:

    • PORT_GITHUB_TOKEN: Your Personal Access Token with Read and Write permissions for Pull requests. Follow GitHub's guide to create one.
  3. Commit and push the changes to your repository.

Choosing the right approach
  • Personal Access Token: Simpler setup, comments appear from your personal account, suitable for smaller teams or personal projects.
  • GitHub App: More professional, comments appear from a dedicated app account, better for larger organizations and provides more granular permissions.

Example response

The PR Enricher workflow will automatically comment on new pull requests with information like:

GitHub comment from Port PR Enricher with change summary, risk analysis, and reviewer guidance

Best practices

To get the most out of your PR Enricher workflow:

  1. Ensure PR-Jira Linking: Verify that your Port setup correctly establishes relations between githubPullRequest entities and jiraIssue entities.

  2. Start with basic assessment: Begin with simple risk assessment and gradually add more context as you see how the agent performs.

  3. Monitor responses: Regularly review the agent's comments to ensure they're helpful and accurate. You may refine the agent's prompt based on the quality of responses and specific needs of your team.

  4. Troubleshoot: If you're not getting the expected results, check our troubleshooting guide for common issues and solutions.