Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 44 additions & 13 deletions .github/workflows/ai-review.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
name: AI Code Review
run-name: Running AI code review on ${{ github.actor }}'s branch
name: AI Command Handler
run-name: Triggering AI review commands on PR #${{ inputs.prId }}

concurrency:
group: ai-command-${{ github.event.inputs.prId || github.event.pull_request.number }}
cancel-in-progress: true

on:
pull_request:
types: [opened, reopened, ready_for_review, synchronize]
issue_comment:
types: [created]
workflow_dispatch:
inputs:
prId:
description: "PR to deploy"
required: false
Comment on lines +11 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The prId input for the workflow_dispatch trigger is currently optional, but it is critical for the workflow to identify the target Pull Request. Without a prId, subsequent jobs and steps that rely on this identifier will fail to operate on the correct PR. Make this input required to ensure the workflow always has the necessary context. [possible issue, importance: 8]

Suggested change
workflow_dispatch:
inputs:
prId:
description: "PR to deploy"
required: false
workflow_dispatch:
inputs:
prId:
description: "PR to deploy"
required: true

repository:
description: "The repository from which the slash command was dispatched"
required: false
comment-id:
description: "The comment-id of the slash command"
required: false
author:
description: "The author that triggered this actions"
required: false

permissions:
contents: write
issues: write
contents: read
pull-requests: write

concurrency:
group: pr-ai-${{ github.event.number || github.event.issue.number }}-${{ github.event.comment.body || 'pr' }}
cancel-in-progress: true

jobs:
getPRHead:
name: Get PR head SHA
Expand All @@ -38,9 +49,8 @@ jobs:
pull_number: parseInt(prId, 10)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The getPRHead job's script for retrieving the PR ID does not account for workflow_dispatch events. When triggered by workflow_dispatch, github.event.number and github.event.issue.number are typically null, causing the PR lookup to fail. Update the script to use inputs.prId when available to ensure correct PR identification. [possible issue, importance: 10]

New proposed code:
-              const prId = ${{ github.event.number ||  github.event.issue.number }};
+              const prId = ${{ inputs.prId || github.event.pull_request.number || github.event.number || github.event.issue.number }};
+              if (!prId) {
+                throw new Error('PR ID not found for workflow run.');
+              }
               const { data: pr } = await github.rest.pulls.get({
                   owner: context.repo.owner,
                   repo: context.repo.repo,
                   pull_number: parseInt(prId, 10)
               });

});
return pr.head.sha;
Comment on lines 49 to 51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The getPRHead job's script incorrectly assumes github.event.number or github.event.issue.number will be available for workflow_dispatch events. For workflow_dispatch, the PR ID must be retrieved from inputs.prId. Update the script to correctly use inputs.prId when triggered by workflow_dispatch to prevent failures. [possible issue, importance: 9]

New proposed code:
 ...
         script: |
-          const prId = ${{ github.event.number ||  github.event.issue.number }};
+          let prId;
+          if (context.eventName === 'workflow_dispatch') {
+              prId = `${{ inputs.prId }}`;
+          } else {
+              prId = `${{ github.event.number || github.event.issue.number }}`;
+          }
+          if (!prId || isNaN(parseInt(prId, 10))) {
+              throw new Error("PR ID is missing or invalid.");
+          }
           const { data: pr } = await github.rest.pulls.get({
               owner: context.repo.owner,
               repo: context.repo.repo,
               pull_number: parseInt(prId, 10)
           });
           return pr.head.sha;


aiCodeReview:
name: Run AI Code Review on the PR
triggerAiReview:
name: Trigger AI Review Commands
runs-on: ubuntu-latest
needs: getPRHead

Expand All @@ -63,6 +73,27 @@ jobs:
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
UNLOAD_ENVIRONMENTS: ci

- name: Post /review command
uses: ./.github/composite/send-message
with:
prId: ${{ inputs.prId || github.event.pull_request.number }}
message: "/review"
token: ${{ env.GH_PAT }}

- name: Post /describe command
uses: ./.github/composite/send-message
with:
prId: ${{ inputs.prId || github.event.pull_request.number }}
message: "/describe"
token: ${{ env.GH_PAT }}

- name: Post /improve command
uses: ./.github/composite/send-message
with:
prId: ${{ inputs.prId || github.event.pull_request.number }}
message: "/improve"
token: ${{ env.GH_PAT }}
Comment on lines +76 to +95
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The workflow is named AI Command Handler but unconditionally posts all three /review, /describe, and /improve commands. To truly act as a handler, add a command input to workflow_dispatch and make these steps conditional based on the provided input, allowing specific commands to be triggered. If no command is specified (e.g., on pull_request events), a default set of commands could be posted. [general, importance: 9]

Suggested change
- name: Post /review command
uses: ./.github/composite/send-message
with:
prId: ${{ inputs.prId || github.event.pull_request.number }}
message: "/review"
token: ${{ env.GH_PAT }}
- name: Post /describe command
uses: ./.github/composite/send-message
with:
prId: ${{ inputs.prId || github.event.pull_request.number }}
message: "/describe"
token: ${{ env.GH_PAT }}
- name: Post /improve command
uses: ./.github/composite/send-message
with:
prId: ${{ inputs.prId || github.event.pull_request.number }}
message: "/improve"
token: ${{ env.GH_PAT }}
on:
pull_request:
types: [opened, reopened, ready_for_review, synchronize]
workflow_dispatch:
inputs:
prId:
description: "PR to deploy"
required: false
repository:
description: "The repository from which the slash command was dispatched"
required: false
comment-id:
description: "The comment-id of the slash command"
required: false
author:
description: "The author that triggered this actions"
required: false
command:
description: "The specific AI command to execute (e.g., /review, /describe, /improve)"
required: false
...
- name: Post /review command
if: ${{ inputs.command == '/review' || (github.event_name == 'pull_request' && inputs.command == '') }}
uses: ./.github/composite/send-message
with:
prId: ${{ inputs.prId || github.event.pull_request.number }}
message: "/review"
token: ${{ env.GH_PAT }}


- name: Run composite workflow
uses: ./.github/composite/notion-checks
id: notion_check
Expand Down
Loading