diff --git a/.github/workflows/lgtm.yml b/.github/workflows/lgtm.yml index eec4129..2c14261 100644 --- a/.github/workflows/lgtm.yml +++ b/.github/workflows/lgtm.yml @@ -34,8 +34,6 @@ jobs: needs: check-permission if: needs.check-permission.outputs.has-permission == 'true' runs-on: ubuntu-latest - container: - image: elementsinteractive/lgtm-ai steps: - name: Checkout PR code uses: actions/checkout@v4 @@ -43,9 +41,8 @@ jobs: ref: refs/pull/${{ github.event.issue.number }}/merge - name: Run LGTM Review - run: | - lgtm review \ - --pr-url "https://github.com/${{ github.repository }}/pull/${{ github.event.issue.number }}" \ - --git-api-key "${{ secrets.GITHUB_TOKEN }}" \ - --ai-api-key "${{ secrets.AI_API_TOKEN }}" \ - -vv + uses: ./ + with: + ai-api-key: ${{ secrets.AI_API_TOKEN }} + git-api-key: ${{ secrets.GITHUB_TOKEN }} + pr-number: ${{ github.event.issue.number }} diff --git a/README.md b/README.md index bd76001..f0536e4 100644 --- a/README.md +++ b/README.md @@ -290,7 +290,18 @@ lgtm-review: MR_URL: "${CI_PROJECT_URL}/-/merge_requests/${CI_MERGE_REQUEST_IID}" ``` -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`. +For GitHub, you can use the official LGTM AI GitHub Action: + +```yaml +- name: AI Code Review + uses: elementsinteractive/lgtm-ai@v1 + with: + ai-api-key: ${{ secrets.AI_API_KEY }} + git-api-key: ${{ secrets.GITHUB_TOKEN }} + pr-number: ${{ github.event.issue.number }} +``` + +You can also check out this repo's [lgtm workflow](./.github/workflows/lgtm.yml) for a complete example with comment triggers (`/lgtm review`). ### Configuration diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..0cc39e0 --- /dev/null +++ b/action.yml @@ -0,0 +1,82 @@ +name: "LGTM AI Code Review" +description: "AI-powered code review for pull requests" +author: "Elements Interactive" + +branding: + icon: "moon" + color: "blue" + +inputs: + ai-api-key: + description: "API key for AI service (OpenAI, Anthropic, Google, etc.)" + required: true + + git-api-key: + description: "API key for GitHub (you can use GITHUB_TOKEN)" + required: true + + pr-number: + description: "Pull request number to review" + required: true + + model: + description: "AI model to use (e.g. gpt-4o, claude-3-5-sonnet-latest, gemini-2.0-flash)" + required: false + default: "gpt-5" + + version: + description: "LGTM AI version (latest, v0.7.2, etc.)" + required: false + default: "latest" + + publish: + description: "Whether to publish the review as PR comments" + required: false + default: "true" + + exclude: + description: "File patterns to exclude (e.g. '*.md *.json package-lock.json')" + required: false + default: "" + + config: + description: "Path to lgtm.toml configuration file (e.g. '.lgtm.toml')" + required: false + default: "" + +runs: + using: "composite" + steps: + - name: Run LGTM AI Review + shell: bash + run: | + # Build arguments as an array for safety (avoids word-splitting issues) + ARGS=( + review + --pr-url "https://github.com/${{ github.repository }}/pull/${{ inputs.pr-number }}" + --git-api-key "${{ inputs.git-api-key }}" + --ai-api-key "${{ inputs.ai-api-key }}" + --model "${{ inputs.model }}" + ) + + # Optional flags + if [ "${{ inputs.publish }}" = "true" ]; then + ARGS+=(--publish) + fi + + if [ -n "${{ inputs.exclude }}" ]; then + ARGS+=(--exclude "${{ inputs.exclude }}") + fi + + if [ -n "${{ inputs.config }}" ]; then + ARGS+=(--config "${{ inputs.config }}") + fi + + # Verbose mode + ARGS+=(-v) + + docker run --rm \ + -v "${{ github.workspace }}:/workspace" \ + -w /workspace \ + elementsinteractive/lgtm-ai:${{ inputs.version }} \ + "${ARGS[@]}"