github-integration.mdx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. ---
  2. title: "GitHub Actions Integration"
  3. description: "Automatically respond to GitHub issues by mentioning @cline in comments using Cline CLI in GitHub Actions."
  4. ---
  5. # GitHub Integration Sample
  6. Automate GitHub issue analysis with AI. Mention `@cline` in any issue comment to trigger an autonomous investigation that reads files, analyzes code, and provides actionable insights - all running automatically in GitHub Actions.
  7. <Note>
  8. **New to Cline CLI?** This sample assumes you understand Cline CLI basics and have completed the [Installation Guide](https://docs.cline.bot/cline-cli/installation). If you're new to Cline CLI, we recommend starting with the [GitHub RCA sample](./github-issue-rca) first, as it's simpler and will help you understand the fundamentals before setting up GitHub Actions.
  9. </Note>
  10. ## The Workflow
  11. Trigger Cline by mentioning `@cline` in any issue comment:
  12. <Frame>
  13. <img src="https://storage.googleapis.com/cline_public_images/ss0a-comment.png" alt="Issue comment with @cline mention" width="600" />
  14. </Frame>
  15. Cline's automated analysis appears as a new comment, with insights drawn from your actual codebase:
  16. <Frame>
  17. <img src="https://storage.googleapis.com/cline_public_images/ss0b-final.png" alt="Automated analysis response from Cline" width="600" />
  18. </Frame>
  19. The entire investigation runs autonomously in GitHub Actions - from file exploration to posting results.
  20. Let's configure your repository.
  21. ## Prerequisites
  22. Before you begin, you'll need:
  23. - **Cline CLI knowledge** - Completed the [Installation Guide](https://docs.cline.bot/cline-cli/installation) and understand basic usage
  24. - **GitHub repository** - With admin access to configure Actions and secrets
  25. - **GitHub Actions familiarity** - Basic understanding of workflows and CI/CD
  26. - **API provider account** - OpenRouter, Anthropic, or similar with API key
  27. ## Setup
  28. ### 1. Copy the Workflow File
  29. Copy the workflow file from this sample to your repository. The workflow file must be placed in the `.github/workflows/` directory in your repository root for GitHub Actions to detect and run it. In this case, we'll name it `cline-responder.yml`.
  30. ```bash
  31. # In your repository root
  32. mkdir -p .github/workflows
  33. curl -o .github/workflows/cline-responder.yml https://raw.githubusercontent.com/cline/cline/main/src/samples/cli/github-integration/cline-responder.yml
  34. ```
  35. Alternatively, you can copy the full workflow file directly into `.github/workflows/cline-responder.yml`:
  36. <Accordion title="Click to view the complete cline-responder.yml workflow">
  37. ```yaml
  38. name: Cline Issue Assistant
  39. on:
  40. issue_comment:
  41. types: [created, edited]
  42. permissions:
  43. issues: write
  44. jobs:
  45. respond:
  46. runs-on: ubuntu-latest
  47. environment: cline-actions
  48. steps:
  49. - name: Check for @cline mention
  50. id: detect
  51. uses: actions/github-script@v7
  52. with:
  53. script: |
  54. const body = context.payload.comment?.body || "";
  55. const isPR = !!context.payload.issue?.pull_request;
  56. const hit = body.toLowerCase().includes("@cline");
  57. core.setOutput("hit", (!isPR && hit) ? "true" : "false");
  58. core.setOutput("issue_number", String(context.payload.issue?.number || ""));
  59. core.setOutput("issue_url", context.payload.issue?.html_url || "");
  60. core.setOutput("comment_body", body);
  61. - name: Checkout repository
  62. if: steps.detect.outputs.hit == 'true'
  63. uses: actions/checkout@v4
  64. # Node v20 is needed for Cline CLI on GitHub Actions Linux
  65. - name: Setup Node.js
  66. uses: actions/setup-node@v4
  67. with:
  68. node-version: '20'
  69. - name: Setup Cline CLI
  70. if: steps.detect.outputs.hit == 'true'
  71. run: |
  72. # Install the Cline CLI
  73. sudo npm install -g cline
  74. - name: Configure Cline CLI
  75. if: steps.detect.outputs.hit == 'true'
  76. env:
  77. OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
  78. CLINE_DIR: ${{ runner.temp }}/cline
  79. run: |
  80. # Configure API key
  81. cline config set open-router-api-key=$OPENROUTER_API_KEY -v
  82. - name: Download analyze script
  83. if: steps.detect.outputs.hit == 'true'
  84. run: |
  85. export GITORG="YOUR-GITHUB-ORG"
  86. export GITREPO="YOUR-GITHUB-REPO"
  87. curl -L https://raw.githubusercontent.com/${GITORG}/${GITREPO}/refs/heads/main/git-scripts/analyze-issue.sh -o analyze-issue.sh
  88. chmod +x analyze-issue.sh
  89. - name: Run analysis
  90. if: steps.detect.outputs.hit == 'true'
  91. id: analyze
  92. env:
  93. ISSUE_URL: ${{ steps.detect.outputs.issue_url }}
  94. COMMENT: ${{ steps.detect.outputs.comment_body }}
  95. CLINE_ADDRESS: ${{ env.CLINE_ADDRESS }}
  96. run: |
  97. set -euo pipefail
  98. RESULT=$(./analyze-issue.sh "${ISSUE_URL}" "Analyze this issue. The user asked: ${COMMENT}")
  99. {
  100. echo 'result<<EOF'
  101. printf "%s\n" "$RESULT"
  102. echo 'EOF'
  103. } >> "$GITHUB_OUTPUT"
  104. - name: Post response
  105. if: steps.detect.outputs.hit == 'true'
  106. uses: actions/github-script@v7
  107. env:
  108. ISSUE_NUMBER: ${{ steps.detect.outputs.issue_number }}
  109. RESULT: ${{ steps.analyze.outputs.result }}
  110. with:
  111. script: |
  112. await github.rest.issues.createComment({
  113. owner: context.repo.owner,
  114. repo: context.repo.repo,
  115. issue_number: Number(process.env.ISSUE_NUMBER),
  116. body: process.env.RESULT || "(no output)"
  117. });
  118. ```
  119. </Accordion>
  120. <Warning>
  121. **You MUST edit the workflow file before committing!**
  122. Open `.github/workflows/cline-responder.yml` and update the "Download analyze script" step within the workflow to specify your GitHub organization and repository where the analysis script is stored:
  123. ```yaml
  124. export GITORG="YOUR-GITHUB-ORG" # Change this!
  125. export GITREPO="YOUR-GITHUB-REPO" # Change this!
  126. ```
  127. **Example:** If your repository is `github.com/acme/myproject`, set:
  128. ```yaml
  129. export GITORG="acme"
  130. export GITREPO="myproject"
  131. ```
  132. This tells the workflow where to download the analysis script from your repository after you commit it in step 3.
  133. </Warning>
  134. The workflow will look for new or updated issues, check for `@cline` mentions, and then
  135. start up the Cline CLI to dig into the issue, providing feedback as a reply to the issue.
  136. ### 2. Configure API Keys
  137. Add your AI provider API keys as repository secrets:
  138. 1. Go to your GitHub repository
  139. 2. Navigate to **Settings** → **Environment** and Add a new environment.
  140. <Frame>
  141. <img src="https://storage.googleapis.com/cline_public_images/ss01-environment.png" alt="Navigate to Actions secrets" width="600" />
  142. </Frame>
  143. Make sure to name it "cline-actions" so that it matches the `environment`
  144. value at the top of the `cline-responder.yml` file.
  145. 3. Click **New repository secret**
  146. 4. Add a secret for the `OPENROUTER_API_KEY` with a value of an API key from
  147. [openrouter.com](https://openrouter.com).
  148. <Frame>
  149. <img src="https://storage.googleapis.com/cline_public_images/ss02-api-key.png" alt="Add API key secret" width="600" />
  150. </Frame>
  151. 5. Verify your secret is configured:
  152. <Frame>
  153. <img src="https://storage.googleapis.com/cline_public_images/ss03-ready.png" alt="API key configured" width="600" />
  154. </Frame>
  155. Now you're ready to supply Cline with the credentials it needs in a GitHub Action.
  156. ### 3. Add Analysis Script
  157. Add the analysis script from the `github-issue-rca` sample to your repository. **First, you'll need to create a `git-scripts` directory in your repository root where the script will be located.** Choose one of these options:
  158. **Option A: Download directly (Recommended)**
  159. ```bash
  160. # In your repository root, create the directory and download the script
  161. mkdir -p git-scripts
  162. curl -o git-scripts/analyze-issue.sh https://raw.githubusercontent.com/cline/cline/main/src/samples/cli/github-issue-rca/analyze-issue.sh
  163. chmod +x git-scripts/analyze-issue.sh
  164. ```
  165. **Option B: Manual copy-paste**
  166. Create the directory and file manually, then paste the script content:
  167. ```bash
  168. # In your repository root
  169. mkdir -p git-scripts
  170. # Create and edit the file with your preferred editor
  171. nano git-scripts/analyze-issue.sh # or use vim, code, etc.
  172. ```
  173. <Accordion title="Click to view the complete analyze-issue.sh script">
  174. ```bash
  175. #!/bin/bash
  176. # Analyze a GitHub issue using Cline CLI
  177. if [ -z "$1" ]; then
  178. echo "Usage: $0 <github-issue-url> [prompt] [address]"
  179. echo "Example: $0 https://github.com/owner/repo/issues/123"
  180. echo "Example: $0 https://github.com/owner/repo/issues/123 'What is the root cause of this issue?'"
  181. echo "Example: $0 https://github.com/owner/repo/issues/123 'What is the root cause of this issue?'"
  182. exit 1
  183. fi
  184. # Gather the args
  185. ISSUE_URL="$1"
  186. PROMPT="${2:-What is the root cause of this issue?}"
  187. # Ask Cline for its analysis, showing only the summary
  188. cline -y "$PROMPT: $ISSUE_URL" --mode act -F json | \
  189. sed -n '/^{/,$p' | \
  190. jq -r 'select(.say == "completion_result") | .text' | \
  191. sed 's/\\n/\n/g'
  192. ```
  193. After pasting the script content, make it executable:
  194. ```bash
  195. chmod +x git-scripts/analyze-issue.sh
  196. ```
  197. </Accordion>
  198. This analysis script calls Cline to execute a prompt on a GitHub issue,
  199. summarizing the output to populate the reply to the issue.
  200. ### 4. Commit and Push
  201. ```bash
  202. git add .github/workflows/cline-responder.yml
  203. git add git-scripts/analyze-issue.sh
  204. git commit -m "Add Cline issue assistant workflow"
  205. git push
  206. ```
  207. ## Usage
  208. Once set up, simply mention `@cline` in any issue comment:
  209. ```
  210. @cline what's causing this error?
  211. @cline analyze the root cause
  212. @cline what are the security implications?
  213. ```
  214. GitHub Actions will:
  215. 1. Detect the `@cline` mention
  216. 2. Start a Cline CLI instance
  217. 3. Download the analysis script
  218. 4. Analyze the issue using act mode with yolo (fully autonomous)
  219. 5. Post Cline's analysis as a new comment
  220. **Note**: The workflow only triggers on issue comments, not pull request
  221. comments.
  222. ## How It Works
  223. The workflow (`cline-responder.yml`):
  224. 1. **Triggers** on issue comments (created or edited)
  225. 2. **Detects** `@cline` mentions (case-insensitive)
  226. 3. **Installs** Cline CLI globally using npm
  227. 4. **Configures** authentication using `cline config set open-router-api-key=...`
  228. 6. **Downloads** the reusable `analyze-issue.sh` script from the
  229. `github-issue-rca` sample
  230. 7. **Runs** analysis in Cline CLI
  231. 8. **Posts** the analysis result as a comment
  232. ## Related Samples
  233. - **[github-issue-rca](./github-issue-rca)**: The reusable script that powers this integration