Skip to content

Commit 8658bc2

Browse files
committed
improve on docs
1 parent 0a76eba commit 8658bc2

File tree

1 file changed

+117
-27
lines changed

1 file changed

+117
-27
lines changed

docs/guides/all/track-ai-driven-pull-requests.md

Lines changed: 117 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ displayed_sidebar: null
33
description: Learn how to track and monitor AI-driven pull requests in your development workflow using Port's software catalog and automation capabilities.
44
---
55

6+
import Tabs from "@theme/Tabs"
7+
import TabItem from "@theme/TabItem"
8+
69
# Track AI-driven pull requests
710

811
As engineering teams integrate AI coding agents like GitHub Copilot, Claude, and Devin into their workflows, they face the challenge of managing an increased volume of pull requests. Tracking and reviewing these AI-generated contributions can be overwhelming without a centralized system. Port's AI control center addresses this issue by identifying pull requests originating from coding agents and displaying them in real-time, allowing you to efficiently monitor and act upon them.
@@ -29,6 +32,57 @@ This guide assumes you're using GitHub to manage your code. However, the princip
2932
:::
3033

3134

35+
## Identifying AI-driven pull requests
36+
37+
Before tracking statuses, we need to identify whether a PR was created or influenced by an AI coding agent.
38+
This logic differs depending on the agent:
39+
40+
<Tabs>
41+
<TabItem value="copilot" label="GitHub Copilot" default>
42+
43+
**How we detect it**
44+
- Copilot PRs are usually authored by the GitHub Copilot bot (`github-copilot[bot]`).
45+
- They often start as **draft PRs** or use `"WIP"` in the title.
46+
- Commits are signed with the Copilot signature.
47+
48+
**Example**
49+
- PR title: `"WIP: Initial refactor"`.
50+
- Author: `github-copilot[bot]`.
51+
- Draft: `true`.
52+
53+
</TabItem>
54+
55+
56+
<TabItem value="claude" label="Claude Code">
57+
58+
**How we detect it**
59+
- PRs can be authored by either the **human user** or Claude itself. When authored by a human, Claude’s comments reveal its involvement.
60+
- Claude typically adds **long, structured review comments**, often in a blockquote style or with headers like **“Here’s what I changed”**.
61+
- No `draft` or `"WIP"` markers are added automatically when authored by Claude.
62+
63+
**Example**
64+
- Author: `janedoe` (human) or `claude-bot`.
65+
- Comment by Claude Code: `“Here are the changes I made for better error handling…”`.
66+
67+
</TabItem>
68+
69+
70+
<TabItem value="devin" label="Devin">
71+
72+
**How we detect it**
73+
- Devin usually opens a regular PR (not draft, no WIP).
74+
- Commits are authored by a **dedicated GitHub user** configured for Devin.
75+
- Commit messages often follow a **concise, imperative style** (e.g., `Fix API error handling`).
76+
77+
**Example**
78+
- PR: opened by `devin-bot` (or the GitHub user assigned to Devin).
79+
- Commits: `author: Devin <bot@devin.ai>`.
80+
- No draft/WIP markers.
81+
82+
</TabItem>
83+
</Tabs>
84+
85+
3286
## Data model setup
3387

3488
We will create and configure blueprints to support tracking AI-driven pull requests. This includes setting up the AI coding agent blueprint and enhancing the existing pull request blueprint.
@@ -112,6 +166,10 @@ This blueprint will represent all known coding agents in your system.
112166

113167
5. Click `Create` to save the blueprint.
114168

169+
:::note Populate Coding Agents
170+
Ensure that this blueprint is populated with the names of coding agents such as Copilot, Claude, Devin, etc. This will help in accurately tracking and managing AI-driven pull requests.
171+
:::
172+
115173

116174
### Update pull request blueprint
117175

@@ -123,7 +181,7 @@ When installing Port's GitHub app, the `Service` and `Pull request` blueprints a
123181
4. Add the following property to the `properties` section:
124182

125183
<details>
126-
<summary><b>Draft property (Click to expand)</b></summary>
184+
<summary><b>Draft and coding agent status property (Click to expand)</b></summary>
127185

128186
```json showLineNumbers
129187
"draft": {
@@ -197,7 +255,6 @@ Now we will update the GitHub integration configuration to ensure that the new p
197255
properties:
198256
status: .status
199257
closedAt: .closed_at
200-
creata: .user.login
201258
updatedAt: .updated_at
202259
mergedAt: .merged_at
203260
createdAt: .created_at
@@ -241,25 +298,37 @@ Now we will update the GitHub integration configuration to ensure that the new p
241298
:::
242299
</details>
243300

301+
:::tip Alternative mapping for Claude/Devin PRs
302+
The default `workStatus` mapping is optimized for **GitHub Copilot**, which usually opens **draft PRs** or adds **"WIP"** to titles.
244303

245-
## Set up automations
304+
For **Claude or Devin**, PRs are typically created as *regular, non-draft PRs* with no WIP indicators.
305+
In that case, you can use this simplified mapping that relies only on **reviewers** and **merge status**:
246306

247-
We will create several automations to help track the status of coding agents. To figure out if a coding agent participated in a PR creation, we need to look into its comments and commits.
307+
<details>
308+
<summary><b>Alternative mapping for Claude/Devin PRs (Click to expand)</b></summary>
248309

249-
The automation flow works as follows:
250-
1. **Ingest PRs** via Port's GitHub app
251-
2. **Run automation** that gets commits or comments for each PR update
252-
3. **Run second automation** that extracts and looks for names of coding agents
253-
254-
:::tip Avoid Recursive Updates
255-
To prevent recursive updates and entity overwrites caused by two automations being triggered for each pull request update, ensure that the comment automation is executed only after the commit automation has completed. This sequential execution avoids simultaneous runs and potential conflicts.
310+
```yaml showLineNumbers
311+
workStatus: >-
312+
if ((.requested_reviewers // []) | length) > 0 then
313+
"Awaiting review"
314+
elif ((.requested_reviewers // []) | length) == 0 then
315+
"In Progress"
316+
else
317+
"Unknown"
318+
end
319+
```
320+
</details>
256321
:::
257322

323+
## Set up automations
324+
325+
To effectively track the status of coding agents, we will create several automations. You have the flexibility to determine if a coding agent participated in a PR creation by examining its comments, commits, or both, depending on your specific needs. This allows you to tailor the tracking process to best fit your requirements.
326+
258327
### Add Port secrets
259328

260-
To securely integrate GitHub REST API with your portal, you need to add secrets that will allow access to necessary data.
329+
Before setting up the automations, ensure you have added the necessary secrets to securely interact with the GitHub REST API within your portal. This is essential for accessing the required data.
261330

262-
To add this secret to your portal:
331+
To add the secret to your portal:
263332

264333
1. Click on the `...` button in the top right corner of your Port application.
265334
2. Click on **Credentials**.
@@ -268,10 +337,22 @@ To add this secret to your portal:
268337

269338
- `GITHUB_TOKEN` - Your [GitHub fine-grained access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token) with access to read repository commits and comments.
270339

340+
Once the secret is added, you can proceed with setting up the automations based on your chosen method of tracking AI participation:
341+
342+
<Tabs groupId="ai-participation">
343+
<TabItem value="commits" label="Commits (AI wrote code)">
344+
345+
### Commits Automation Flow
346+
347+
This flow identifies AI involvement in code writing by analyzing commit data.
348+
349+
1. **Run automation** to fetch commits for each PR update.
350+
2. **Run second automation** to extract and identify coding agent names from commits.
271351

272-
### Automation 1: Get commits on PR updated
273352

274-
This automation only runs when the `ai_coding_agent` relation is null (before and after) to ensure that it only processes pull requests that have not yet been associated with an AI coding agent, preventing redundant operations.
353+
<h4> Automation 1: Get commits on PR updated </h4>
354+
355+
This automation only runs when the `ai_coding_agent` relation is null (before and after) to ensure that it only processes pull requests that have not yet been associated with an AI coding agent.
275356

276357
1. Go to the [Automations](https://app.getport.io/settings/automations) page of your portal.
277358
2. Click on `+ Automation`.
@@ -325,7 +406,7 @@ This automation only runs when the `ai_coding_agent` relation is null (before an
325406
4. Click `Create` to save the automation.
326407

327408

328-
### Automation 2: Update PR with AI coding agent (commit-based)
409+
<h4> Automation 2: Update PR with AI coding agent (commit-based) </h4>
329410

330411
This automation only runs if the commits response contains a match for AI agents, ensuring that only relevant pull requests are updated with AI coding agent information.
331412

@@ -374,12 +455,19 @@ This automation only runs if the commits response contains a match for AI agents
374455

375456
4. Click `Create` to save the automation.
376457

458+
</TabItem>
459+
<TabItem value="comments" label="Comments (AI reviewed code)">
377460

378-
### Automation 3: Get comments on PR updated
461+
### Comments Automation Flow
379462

380-
This automation runs only after the commits automation and only if commits returned no AI agent, ensuring that the system checks for AI involvement through comments when it is not detected in commits.
463+
This flow identifies AI involvement in code review by analyzing comment data.
381464

382-
1. Go back to the [Automations](https://app.getport.io/settings/automations) page of your portal.
465+
1. **Run automation** to fetch comments for each PR update.
466+
2. **Run second automation** to extract and identify coding agent names from comments.
467+
468+
<h4> Automation 1: Get comments on PR updated </h4>
469+
470+
1. Go to the [Automations](https://app.getport.io/settings/automations) page of your portal.
383471
2. Click on `+ Automation`.
384472
3. Copy and paste the following JSON schema:
385473

@@ -389,8 +477,8 @@ This automation runs only after the commits automation and only if commits retur
389477
```json showLineNumbers
390478
{
391479
"identifier": "get_comments_on_pr_updated",
392-
"title": "Get Comments on PR Updated (after commits check)",
393-
"description": "Fetch PR comments only if commit scan returned no AI agent",
480+
"title": "Get Comments on PR Updated",
481+
"description": "Fetch PR comments upon PR updates",
394482
"icon": "GitPullRequest",
395483
"trigger": {
396484
"type": "automation",
@@ -401,15 +489,15 @@ This automation runs only after the commits automation and only if commits retur
401489
"condition": {
402490
"type": "JQ",
403491
"expressions": [
404-
".diff.after.status == \"SUCCESS\"",
405-
".diff.before.response | [ .[] | (.commit.author.name // \"\") | select(test(\"(?i)copilot|claude|devin\")) ] | length == 0"
492+
".diff.before.relations.ai_coding_agent == null",
493+
".diff.after.relations.ai_coding_agent == null"
406494
],
407495
"combinator": "and"
408496
}
409497
},
410498
"invocationMethod": {
411499
"type": "WEBHOOK",
412-
"url": "{{ .event.diff.before.payload.headers.Pr-Link | sub(\"https://github.com/\"; \"https://api.github.com/repos/\") | sub(\"/pull/\"; \"/issues/\") + \"/comments\" }}",
500+
"url": "{{ .event.diff.after.properties.link | sub(\"https://github.com/\"; \"https://api.github.com/repos/\") | sub(\"/pull/\"; \"/issues/\") + \"/comments\" }}",
413501
"agent": false,
414502
"synchronized": true,
415503
"method": "GET",
@@ -418,7 +506,7 @@ This automation runs only after the commits automation and only if commits retur
418506
"Authorization": "Bearer {{ .secrets.GITHUB_TOKEN }}",
419507
"X-GitHub-Api-Version": "2022-11-28",
420508
"Content-Type": "application/json",
421-
"Identifier": "{{ .event.diff.before.payload.headers.Identifier | tostring }}"
509+
"Identifier": "{{ .event.context.entityIdentifier | tostring }}"
422510
},
423511
"body": {}
424512
},
@@ -429,8 +517,7 @@ This automation runs only after the commits automation and only if commits retur
429517

430518
4. Click `Create` to save the automation.
431519

432-
433-
### Automation 4: Update PR with AI coding agent (comment-based)
520+
<h4> Automation 2: Update PR with AI coding agent (comment-based) </h4>
434521

435522
This automation only runs if the comments response contains a match for AI agents, ensuring that the PR is updated only when relevant AI activity is detected.
436523

@@ -479,6 +566,9 @@ This automation only runs if the comments response contains a match for AI agent
479566

480567
4. Click `Create` to save the automation.
481568

569+
</TabItem>
570+
</Tabs>
571+
482572

483573
## Create dashboard
484574

0 commit comments

Comments
 (0)