github-integration.mdx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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: Create Cline Instance
  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. # Create instance and capture output
  81. INSTANCE_OUTPUT=$(cline instance new 2>&1)
  82. # Parse address from output (format: " Address: 127.0.0.1:36733")
  83. CLINE_ADDRESS=$(echo "$INSTANCE_OUTPUT" | grep "Address:" | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}:[0-9]+')
  84. echo "CLINE_ADDRESS=$CLINE_ADDRESS" >> $GITHUB_ENV
  85. # Configure API key
  86. cline config set open-router-api-key=$OPENROUTER_API_KEY --address $CLINE_ADDRESS -v
  87. - name: Download analyze script
  88. if: steps.detect.outputs.hit == 'true'
  89. run: |
  90. export GITORG="YOUR-GITHUB-ORG"
  91. export GITREPO="YOUR-GITHUB-REPO"
  92. curl -L https://raw.githubusercontent.com/${GITORG}/${GITREPO}/refs/heads/main/git-scripts/analyze-issue.sh -o analyze-issue.sh
  93. chmod +x analyze-issue.sh
  94. - name: Run analysis
  95. if: steps.detect.outputs.hit == 'true'
  96. id: analyze
  97. env:
  98. ISSUE_URL: ${{ steps.detect.outputs.issue_url }}
  99. COMMENT: ${{ steps.detect.outputs.comment_body }}
  100. CLINE_ADDRESS: ${{ env.CLINE_ADDRESS }}
  101. run: |
  102. set -euo pipefail
  103. RESULT=$(./analyze-issue.sh "${ISSUE_URL}" "Analyze this issue. The user asked: ${COMMENT}" "$CLINE_ADDRESS")
  104. {
  105. echo 'result<<EOF'
  106. printf "%s\n" "$RESULT"
  107. echo 'EOF'
  108. } >> "$GITHUB_OUTPUT"
  109. - name: Post response
  110. if: steps.detect.outputs.hit == 'true'
  111. uses: actions/github-script@v7
  112. env:
  113. ISSUE_NUMBER: ${{ steps.detect.outputs.issue_number }}
  114. RESULT: ${{ steps.analyze.outputs.result }}
  115. with:
  116. script: |
  117. await github.rest.issues.createComment({
  118. owner: context.repo.owner,
  119. repo: context.repo.repo,
  120. issue_number: Number(process.env.ISSUE_NUMBER),
  121. body: process.env.RESULT || "(no output)"
  122. });
  123. ```
  124. </Accordion>
  125. <Warning>
  126. **You MUST edit the workflow file before committing!**
  127. 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:
  128. ```yaml
  129. export GITORG="YOUR-GITHUB-ORG" # Change this!
  130. export GITREPO="YOUR-GITHUB-REPO" # Change this!
  131. ```
  132. **Example:** If your repository is `github.com/acme/myproject`, set:
  133. ```yaml
  134. export GITORG="acme"
  135. export GITREPO="myproject"
  136. ```
  137. This tells the workflow where to download the analysis script from your repository after you commit it in step 3.
  138. </Warning>
  139. The workflow will look for new or updated issues, check for `@cline` mentions, and then
  140. start up an instance of the Cline CLI to dig into the issue, providing feedback
  141. as a reply to the issue.
  142. ### 2. Configure API Keys
  143. Add your AI provider API keys as repository secrets:
  144. 1. Go to your GitHub repository
  145. 2. Navigate to **Settings** → **Environment** and Add a new environment.
  146. <Frame>
  147. <img src="https://storage.googleapis.com/cline_public_images/ss01-environment.png" alt="Navigate to Actions secrets" width="600" />
  148. </Frame>
  149. Make sure to name it "cline-actions" so that it matches the `environment`
  150. value at the top of the `cline-responder.yml` file.
  151. 3. Click **New repository secret**
  152. 4. Add a secret for the `OPENROUTER_API_KEY` with a value of an API key from
  153. [openrouter.com](https://openrouter.com).
  154. <Frame>
  155. <img src="https://storage.googleapis.com/cline_public_images/ss02-api-key.png" alt="Add API key secret" width="600" />
  156. </Frame>
  157. 5. Verify your secret is configured:
  158. <Frame>
  159. <img src="https://storage.googleapis.com/cline_public_images/ss03-ready.png" alt="API key configured" width="600" />
  160. </Frame>
  161. Now you're ready to supply Cline with the credentials it needs in a GitHub Action.
  162. ### 3. Add Analysis Script
  163. 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:
  164. **Option A: Download directly (Recommended)**
  165. ```bash
  166. # In your repository root, create the directory and download the script
  167. mkdir -p git-scripts
  168. curl -o git-scripts/analyze-issue.sh https://raw.githubusercontent.com/cline/cline/main/src/samples/cli/github-issue-rca/analyze-issue.sh
  169. chmod +x git-scripts/analyze-issue.sh
  170. ```
  171. **Option B: Manual copy-paste**
  172. Create the directory and file manually, then paste the script content:
  173. ```bash
  174. # In your repository root
  175. mkdir -p git-scripts
  176. # Create and edit the file with your preferred editor
  177. nano git-scripts/analyze-issue.sh # or use vim, code, etc.
  178. ```
  179. <Accordion title="Click to view the complete analyze-issue.sh script">
  180. ```bash
  181. #!/bin/bash
  182. # Analyze a GitHub issue using Cline CLI
  183. if [ -z "$1" ]; then
  184. echo "Usage: $0 <github-issue-url> [prompt] [address]"
  185. echo "Example: $0 https://github.com/owner/repo/issues/123"
  186. echo "Example: $0 https://github.com/owner/repo/issues/123 'What is the root cause of this issue?'"
  187. echo "Example: $0 https://github.com/owner/repo/issues/123 'What is the root cause of this issue?' 127.0.0.1:46529"
  188. exit 1
  189. fi
  190. # Gather the args
  191. ISSUE_URL="$1"
  192. PROMPT="${2:-What is the root cause of this issue?}"
  193. if [ -n "$3" ]; then
  194. ADDRESS="--address $3"
  195. fi
  196. # Ask Cline for its analysis, showing only the summary
  197. cline -y "$PROMPT: $ISSUE_URL" --mode act $ADDRESS -F json | \
  198. sed -n '/^{/,$p' | \
  199. jq -r 'select(.say == "completion_result") | .text' | \
  200. sed 's/\\n/\n/g'
  201. ```
  202. After pasting the script content, make it executable:
  203. ```bash
  204. chmod +x git-scripts/analyze-issue.sh
  205. ```
  206. </Accordion>
  207. This analysis script calls Cline to execute a prompt on a GitHub issue,
  208. summarizing the output to populate the reply to the issue.
  209. ### 4. Commit and Push
  210. ```bash
  211. git add .github/workflows/cline-responder.yml
  212. git add git-scripts/analyze-issue.sh
  213. git commit -m "Add Cline issue assistant workflow"
  214. git push
  215. ```
  216. ## Usage
  217. Once set up, simply mention `@cline` in any issue comment:
  218. ```
  219. @cline what's causing this error?
  220. @cline analyze the root cause
  221. @cline what are the security implications?
  222. ```
  223. GitHub Actions will:
  224. 1. Detect the `@cline` mention
  225. 2. Start a Cline CLI instance
  226. 3. Download the analysis script
  227. 4. Analyze the issue using act mode with yolo (fully autonomous)
  228. 5. Post Cline's analysis as a new comment
  229. **Note**: The workflow only triggers on issue comments, not pull request
  230. comments.
  231. ## How It Works
  232. The workflow (`cline-responder.yml`):
  233. 1. **Triggers** on issue comments (created or edited)
  234. 2. **Detects** `@cline` mentions (case-insensitive)
  235. 3. **Installs** Cline CLI globally using npm
  236. 4. **Creates** a Cline instance using `cline instance new`
  237. 5. **Configures** authentication using `cline config set open-router-api-key=...
  238. --address ...`
  239. 6. **Downloads** the reusable `analyze-issue.sh` script from the
  240. `github-issue-rca` sample
  241. 7. **Runs** analysis with the instance address
  242. 8. **Posts** the analysis result as a comment
  243. ## Related Samples
  244. - **[github-issue-rca](./github-issue-rca)**: The reusable script that powers this integration