Skip to content

Commit 29be02e

Browse files
committed
feat: add github action
1 parent 5e5666d commit 29be02e

File tree

3 files changed

+99
-9
lines changed

3 files changed

+99
-9
lines changed

.github/workflows/lgtm.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,15 @@ jobs:
3434
needs: check-permission
3535
if: needs.check-permission.outputs.has-permission == 'true'
3636
runs-on: ubuntu-latest
37-
container:
38-
image: elementsinteractive/lgtm-ai
3937
steps:
4038
- name: Checkout PR code
4139
uses: actions/checkout@v4
4240
with:
4341
ref: refs/pull/${{ github.event.issue.number }}/merge
4442

4543
- name: Run LGTM Review
46-
run: |
47-
lgtm review \
48-
--pr-url "https://github.com/${{ github.repository }}/pull/${{ github.event.issue.number }}" \
49-
--git-api-key "${{ secrets.GITHUB_TOKEN }}" \
50-
--ai-api-key "${{ secrets.AI_API_TOKEN }}" \
51-
-vv
44+
uses: ./
45+
with:
46+
ai-api-key: ${{ secrets.AI_API_TOKEN }}
47+
git-api-key: ${{ secrets.GITHUB_TOKEN }}
48+
pr-number: ${{ github.event.issue.number }}

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,18 @@ lgtm-review:
290290
MR_URL: "${CI_PROJECT_URL}/-/merge_requests/${CI_MERGE_REQUEST_IID}"
291291
```
292292
293-
For GitHub, we plan to provide a GitHub action soon. In the meantime, check out this repo's [lgtm workflow](./.github/workflows/lgtm.yml), with which you can trigger reviews in PRs by commenting `/lgtm review`.
293+
For GitHub, you can use the official LGTM AI GitHub Action:
294+
295+
```yaml
296+
- name: AI Code Review
297+
uses: elementsinteractive/lgtm-ai@v1
298+
with:
299+
ai-api-key: ${{ secrets.AI_API_KEY }}
300+
git-api-key: ${{ secrets.GITHUB_TOKEN }}
301+
pr-number: ${{ github.event.issue.number }}
302+
```
303+
304+
You can also check out this repo's [lgtm workflow](./.github/workflows/lgtm.yml) for a complete example with comment triggers (`/lgtm review`).
294305

295306
### Configuration
296307

action.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: "LGTM AI Code Review"
2+
description: "AI-powered code review for pull requests"
3+
author: "Elements Interactive"
4+
5+
branding:
6+
icon: "moon"
7+
color: "blue"
8+
9+
inputs:
10+
ai-api-key:
11+
description: "API key for AI service (OpenAI, Anthropic, Google, etc.)"
12+
required: true
13+
14+
git-api-key:
15+
description: "API key for GitHub (you can use GITHUB_TOKEN)"
16+
required: true
17+
18+
pr-number:
19+
description: "Pull request number to review"
20+
required: true
21+
22+
model:
23+
description: "AI model to use (e.g. gpt-4o, claude-3-5-sonnet-latest, gemini-2.0-flash)"
24+
required: false
25+
default: "gpt-5"
26+
27+
version:
28+
description: "LGTM AI version (latest, v0.7.2, etc.)"
29+
required: false
30+
default: "latest"
31+
32+
publish:
33+
description: "Whether to publish the review as PR comments"
34+
required: false
35+
default: "true"
36+
37+
exclude:
38+
description: "File patterns to exclude (e.g. '*.md *.json package-lock.json')"
39+
required: false
40+
default: ""
41+
42+
config:
43+
description: "Path to lgtm.toml configuration file (e.g. '.lgtm.toml')"
44+
required: false
45+
default: ""
46+
47+
runs:
48+
using: "composite"
49+
steps:
50+
- name: Run LGTM AI Review
51+
shell: bash
52+
run: |
53+
# Build arguments as an array for safety (avoids word-splitting issues)
54+
ARGS=(
55+
review
56+
--pr-url "https://github.com/${{ github.repository }}/pull/${{ inputs.pr-number }}"
57+
--git-api-key "${{ inputs.git-api-key }}"
58+
--ai-api-key "${{ inputs.ai-api-key }}"
59+
--model "${{ inputs.model }}"
60+
)
61+
62+
# Optional flags
63+
if [ "${{ inputs.publish }}" = "true" ]; then
64+
ARGS+=(--publish)
65+
fi
66+
67+
if [ -n "${{ inputs.exclude }}" ]; then
68+
ARGS+=(--exclude "${{ inputs.exclude }}")
69+
fi
70+
71+
if [ -n "${{ inputs.config }}" ]; then
72+
ARGS+=(--config "${{ inputs.config }}")
73+
fi
74+
75+
# Verbose mode
76+
ARGS+=(-v)
77+
78+
docker run --rm \
79+
-v "${{ github.workspace }}:/workspace" \
80+
-w /workspace \
81+
elementsinteractive/lgtm-ai:${{ inputs.version }} \
82+
"${ARGS[@]}"

0 commit comments

Comments
 (0)