2
0

github-issue-rca.mdx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. ---
  2. title: "GitHub Issue RCA Sample"
  3. description: "Automated GitHub issue analysis using Cline CLI to identify root causes."
  4. ---
  5. # GitHub Root Cause Analysis
  6. Automated GitHub issue analysis using Cline CLI. This script uses Cline's autonomous AI capabilities to fetch, analyze, and identify root causes of GitHub issues, outputting clean, parseable results that can be easily integrated into your development workflows.
  7. <Note>
  8. **New to Cline CLI?** This sample assumes you have already completed the [Installation Guide](https://docs.cline.bot/cline-cli/installation) and authenticated with `cline auth`. If you haven't set up Cline CLI yet, please start there first.
  9. </Note>
  10. <Frame>
  11. <img src="https://storage.googleapis.com/cline_public_images/cli-rca.gif" alt="CLI Root Cause Analysis Demo" width="600" />
  12. </Frame>
  13. ## Prerequisites
  14. This sample assumes you have already:
  15. - **Cline CLI** installed and authenticated ([Installation Guide](https://docs.cline.bot/cline-cli/installation))
  16. - **At least one AI model provider** configured (e.g., OpenRouter, Anthropic, OpenAI)
  17. - **Basic familiarity** with Cline CLI commands
  18. Additionally, you'll need:
  19. - **GitHub CLI** (`gh`) installed and authenticated
  20. - **jq** installed for JSON parsing
  21. - **bash** shell (or compatible shell)
  22. ### Installation Instructions
  23. #### macOS
  24. <Note>
  25. These instructions require [Homebrew](https://brew.sh/) to be installed. If you don't have Homebrew, install it first by running:
  26. ```bash
  27. /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  28. ```
  29. </Note>
  30. ```bash
  31. # Install GitHub CLI
  32. brew install gh
  33. # Install jq
  34. brew install jq
  35. # Authenticate with GitHub
  36. gh auth login
  37. ```
  38. #### Linux
  39. ```bash
  40. # Install GitHub CLI (Debian/Ubuntu)
  41. sudo apt install gh
  42. # Or for other Linux distributions, see: https://cli.github.com/manual/installation
  43. # Install jq (Debian/Ubuntu)
  44. sudo apt install jq
  45. # Authenticate with GitHub
  46. gh auth login
  47. ```
  48. ## Getting the Script
  49. **Option 1: Download directly with curl**
  50. ```bash
  51. curl -O https://raw.githubusercontent.com/cline/cline/main/src/samples/cli/github-issue-rca/analyze-issue.sh
  52. ```
  53. **Option 2: Copy the full script**
  54. <Accordion title="Click to view the complete analyze-issue.sh script">
  55. ```bash
  56. #!/bin/bash
  57. # Analyze a GitHub issue using Cline CLI
  58. if [ -z "$1" ]; then
  59. echo "Usage: $0 <github-issue-url> [prompt] [address]"
  60. echo "Example: $0 https://github.com/owner/repo/issues/123"
  61. echo "Example: $0 https://github.com/owner/repo/issues/123 'What is the root cause of this issue?'"
  62. echo "Example: $0 https://github.com/owner/repo/issues/123 'What is the root cause of this issue?' 127.0.0.1:46529"
  63. exit 1
  64. fi
  65. # Gather the args
  66. ISSUE_URL="$1"
  67. PROMPT="${2:-What is the root cause of this issue?}"
  68. if [ -n "$3" ]; then
  69. ADDRESS="--address $3"
  70. fi
  71. # Ask Cline for its analysis, showing only the summary
  72. cline -y "$PROMPT: $ISSUE_URL" --mode act $ADDRESS -F json | \
  73. sed -n '/^{/,$p' | \
  74. jq -r 'select(.say == "completion_result") | .text' | \
  75. sed 's/\\n/\n/g'
  76. ```
  77. </Accordion>
  78. <Note>
  79. **After downloading or creating the script**, make it executable by running:
  80. ```bash
  81. chmod +x analyze-issue.sh
  82. ```
  83. </Note>
  84. ## Quick Usage Examples
  85. ### Basic Usage
  86. Run this command in your terminal from the directory where you saved the script to analyze an issue with the default root cause prompt:
  87. ```bash
  88. ./analyze-issue.sh https://github.com/owner/repo/issues/123
  89. ```
  90. This will:
  91. - Fetch issue #123 from the repository
  92. - Analyze the issue to identify root causes
  93. - Provide detailed analysis with recommendations
  94. ### Custom Analysis Prompt
  95. Ask specific questions about the issue:
  96. ```bash
  97. ./analyze-issue.sh https://github.com/owner/repo/issues/456 "What is the security impact?"
  98. ```
  99. ### Using Specific Cline Instance
  100. Target a particular Cline instance by address:
  101. ```bash
  102. ./analyze-issue.sh https://github.com/owner/repo/issues/123 \
  103. "What is the root cause of this issue?" \
  104. 127.0.0.1:46529
  105. ```
  106. <Warning>
  107. This is useful when:
  108. - Running multiple Cline instances
  109. - Using a remote Cline server
  110. - Testing with specific configurations
  111. </Warning>
  112. <Note>
  113. The script will automatically handle everything: fetching the issue, analyzing it with Cline, and displaying the results. The analysis typically takes 30-60 seconds depending on the issue complexity.
  114. </Note>
  115. ## How It Works
  116. Let's analyze each component of the script to understand how it works.
  117. ### Argument Validation
  118. The script validates input and provides usage instructions:
  119. ```bash
  120. if [ -z "$1" ]; then
  121. echo "Usage: $0 <github-issue-url> [prompt] [address]"
  122. echo "Example: $0 https://github.com/owner/repo/issues/123"
  123. echo "Example: $0 https://github.com/owner/repo/issues/123 'What is the root cause?'"
  124. echo "Example: $0 https://github.com/owner/repo/issues/123 'Analyze security impact' 127.0.0.1:46529"
  125. exit 1
  126. fi
  127. ```
  128. **Key Points:**
  129. - Validates required GitHub issue URL
  130. - Shows clear usage examples
  131. - Supports optional custom prompt
  132. - Supports optional Cline instance address
  133. ### Argument Parsing
  134. The script extracts and sets up the arguments:
  135. ```bash
  136. # Gather the args
  137. ISSUE_URL="$1"
  138. PROMPT="${2:-What is the root cause of this issue?}"
  139. if [ -n "$3" ]; then
  140. ADDRESS="--address $3"
  141. fi
  142. ```
  143. **Explanation:**
  144. - `ISSUE_URL="$1"` - First argument is always the issue URL
  145. - `PROMPT="${2:-...}"` - Second argument is optional, defaults to root cause analysis
  146. - `ADDRESS` - Third argument is optional, only set if provided
  147. ### The Core Analysis Pipeline
  148. This is where the magic happens:
  149. ```bash
  150. # Ask Cline for his analysis, showing only the summary
  151. cline -y "$PROMPT: $ISSUE_URL" --mode act $ADDRESS -F json | \
  152. sed -n '/^{/,$p' | \
  153. jq -r 'select(.say == "completion_result") | .text' | \
  154. sed 's/\\n/\n/g'
  155. ```
  156. <Accordion title="Pipeline Breakdown: Understanding Each Component">
  157. **1. `cline -y "$PROMPT: $ISSUE_URL"`**
  158. - `-y` enables yolo mode (no user interaction)
  159. - Constructs prompt with issue URL
  160. **2. `--mode act`**
  161. - Enables act mode for active investigation
  162. - Allows Cline to use tools (read files, run commands, etc.)
  163. **3. `$ADDRESS`**
  164. - Optional address flag for specific instance
  165. - Expands to `--address <ip:port>` if set
  166. **4. `-F json`**
  167. - Outputs in JSON format for parsing
  168. **5. `sed -n '/^{/,$p'`**
  169. - Extracts JSON from output
  170. - Skips any non-JSON prefix lines
  171. **6. `jq -r 'select(.say == "completion_result") | .text'`**
  172. - Filters for completion result messages
  173. - Extracts the text field
  174. - `-r` outputs raw strings (no JSON quotes)
  175. **7. `sed 's/\\n/\n/g'`**
  176. - Converts escaped newlines to actual newlines
  177. - Makes output readable
  178. </Accordion>
  179. ## Sample Output
  180. Here's an example analyzing a real Flutter issue:
  181. ```bash
  182. $ ./analyze-issue.sh https://github.com/csells/flutter_counter/issues/2
  183. ```
  184. **Output:**
  185. ```markdown
  186. **Root Cause Analysis of Issue #2: "setState isn't cutting it"**
  187. After examining the GitHub issue and analyzing the Flutter counter codebase,
  188. I've identified the root cause of why setState() is insufficient for this
  189. project's needs:
  190. ## Current Implementation Problems
  191. The current Flutter counter app uses setState() for state management, which
  192. has several limitations:
  193. 1. **Local State Only**: setState() only works within a single widget, making
  194. it difficult to share state across the app
  195. 2. **Rebuild Overhead**: Every setState() call rebuilds the entire widget tree,
  196. causing performance issues with complex UIs
  197. 3. **No State Persistence**: State is lost when the widget is disposed
  198. 4. **Testing Challenges**: setState-based logic is tightly coupled to the UI,
  199. making unit testing difficult
  200. ## Why This Matters
  201. As the app grows beyond a simple counter, these limitations become critical:
  202. - Multiple screens need to access the count
  203. - State needs to persist across navigation
  204. - Business logic should be testable independently
  205. - UI should only rebuild when necessary
  206. ## Recommended Solutions
  207. The issue mentions "Provider or Bloc" - both are excellent alternatives:
  208. 1. **Provider**: Simple, lightweight state management using InheritedWidget
  209. - Easy migration path from setState
  210. - Good for small to medium apps
  211. - Official Flutter recommendation
  212. 2. **Bloc**: More structured approach with clear separation between events,
  213. states, and business logic
  214. - Better for complex apps
  215. - Excellent testability
  216. - Clear architectural patterns
  217. 3. **Riverpod**: Modern alternative to Provider with better performance and
  218. developer experience
  219. - Compile-time safety
  220. - Better testing support
  221. - More flexible than Provider
  222. 4. **GetX**: Full-featured solution with state management, routing, and
  223. dependency injection
  224. - Minimal boilerplate
  225. - Fast and lightweight
  226. - All-in-one solution
  227. ## Next Steps
  228. The current codebase needs refactoring to implement proper state management
  229. architecture to handle more complex state scenarios effectively. Provider
  230. would be the easiest migration path while Bloc provides better long-term
  231. scalability.
  232. ```
  233. ## When to Use This Pattern
  234. This script pattern is ideal for various development scenarios where automated GitHub issue analysis can accelerate your workflow.
  235. ### Bug Investigation
  236. Quickly analyze bug reports and identify root causes without manual code exploration:
  237. ```bash
  238. ./analyze-issue.sh https://github.com/project/repo/issues/123 \
  239. "What is the root cause of this bug?"
  240. ```
  241. ### Feature Request Analysis
  242. Understand context and implications of feature requests:
  243. ```bash
  244. ./analyze-issue.sh https://github.com/project/repo/issues/456 \
  245. "What are the implementation challenges?"
  246. ```
  247. ### Security Audits
  248. Assess security implications of reported issues:
  249. ```bash
  250. ./analyze-issue.sh https://github.com/project/repo/issues/789 \
  251. "What are the security implications?"
  252. ```
  253. ### Documentation Generation
  254. Generate detailed technical documentation from issues:
  255. ```bash
  256. ./analyze-issue.sh https://github.com/project/repo/issues/654 \
  257. "Provide detailed technical documentation for this issue"
  258. ```
  259. ### Code Review Assistance
  260. Get second opinions on proposed changes:
  261. ```bash
  262. ./analyze-issue.sh https://github.com/project/repo/issues/987 \
  263. "Review the proposed solution approach"
  264. ```
  265. ## Conclusion
  266. This sample demonstrates how to build an autonomous GitHub issue analysis tool using Cline CLI:
  267. 1. **Building autonomous CLI tools** using Cline's capabilities
  268. 2. **Parsing structured JSON output** from Cline CLI
  269. 3. **Creating flexible automation scripts** with custom prompting
  270. 4. **Integrating with GitHub** for issue analysis
  271. 5. **Handling command-line arguments** effectively
  272. This pattern can be adapted for many other automation scenarios, from pull request reviews to documentation generation to code quality analysis.
  273. ## Related Resources
  274. - [CLI Installation Guide](https://docs.cline.bot/cline-cli/installation)
  275. - [CLI Reference Documentation](https://docs.cline.bot/cline-cli/cli-reference)
  276. - [Three Core Flows](https://docs.cline.bot/cline-cli/three-core-flows)