n2b 0.4.0 โ†’ 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58382cb632f67e6ad3ca031c71a2c53bd5cd477ea32963d89f0d253d8b43bbeb
4
- data.tar.gz: facb990aad05d93cac662fdbf60075ad3606dd43083f408a8e0d60d5940df359
3
+ metadata.gz: d512a4b43acc8a3adac6fe3fd60d05605abef697b36e0beb2e896371c6ae94c0
4
+ data.tar.gz: 140274359582046b03b89521d143e7efc498c07ee85c6cd200de821191b0b0db
5
5
  SHA512:
6
- metadata.gz: 8dd53c35513bf7071c5aecb7f724ebc44f522a166ef1ca8dc4aecfda3f9cd801dd7d85bce6762a4fc8bd5e1a98aa87eaa9e8080db3302a17d5875f8010b90867
7
- data.tar.gz: 866846f2c517fe7dcee27172640151b1d6e567161b473a7c5a39c3894df15ea25b43e2278b24fd783f93c5eac8f507e7d331a85ef5fc5084990f89c227c19485
6
+ metadata.gz: '0184eb2ae93e21a1a389f7445c5e1d3532f645f5164df29ba7acc77ce67e163b8a273767aadc7a3b1ccab8483ae62d7e75b691331cb9145f4075a5a3aa3777ae'
7
+ data.tar.gz: d12e12c75dc2e6b161fb9f169de0a2dd7a8760bdcdf49b915c217407937516cffca31fb5649c5b65e33b81f7c02d688c7695c9c7cf4f5c638d837756c3ce97e5
data/README.md CHANGED
@@ -1,29 +1,92 @@
1
- # N2B - Natural Language to Bash & Ruby
1
+ # N2B - AI-Powered Code Analysis & Jira Integration
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/n2b.svg)](https://badge.fury.io/rb/n2b)
4
4
 
5
- N2B (Natural Language to Bash & Ruby) is a Ruby gem that leverages AI to convert natural language instructions into bash commands and Ruby code.
5
+ **Transform your development workflow with intelligent code analysis and seamless Jira integration.** N2B is an AI-powered development tool that revolutionizes code review, requirements compliance, and project management through automated analysis and smart ticket integration.
6
6
 
7
- ## Features
7
+ ## ๐Ÿš€ **Key Features**
8
8
 
9
- - **๐Ÿค– Natural Language to Commands**: Convert natural language to bash commands
10
- - **๐Ÿ’Ž Ruby Code Generation**: Generate Ruby code from natural language instructions
11
- - **๐Ÿ” AI-Powered Diff Analysis**: Analyze git/hg diffs with comprehensive code review
12
- - **๐Ÿ“‹ Requirements Compliance**: Check if code changes meet specified requirements
13
- - **๐Ÿงช Test Coverage Assessment**: Evaluate test coverage for code changes
14
- - **๐ŸŒฟ Branch Comparison**: Compare changes against any branch (main/master/default)
15
- - **๐Ÿ› ๏ธ VCS Support**: Full support for both Git and Mercurial repositories
16
- - **๐Ÿ“Š Errbit Integration**: Analyze Errbit errors and generate detailed reports
17
- - **๐ŸŽซ Scrum Tickets**: Create formatted Scrum tickets from errors
9
+ ### ๐ŸŽฏ **Smart Jira Integration**
10
+ - **Automated Ticket Analysis**: Fetch requirements from Jira tickets and analyze code changes against them
11
+ - **Intelligent Updates**: Post beautifully formatted analysis results directly to Jira with collapsible sections
12
+ - **Requirements Extraction**: Automatically identify acceptance criteria, tasks, and requirements from tickets and comments
13
+ - **Real-time Feedback**: Get instant compliance checking and implementation guidance
18
14
 
19
- ### ๐Ÿ†• **New in v0.4.0: Flexible Model Configuration**
15
+ ### ๐Ÿ” **AI-Powered Code Analysis**
16
+ - **Context-Aware Diff Review**: Intelligent analysis of git/hg changes with comprehensive insights
17
+ - **Requirements Compliance**: Automated verification against project requirements and acceptance criteria
18
+ - **Test Coverage Assessment**: Evaluate test completeness and suggest improvements
19
+ - **Security & Quality Insights**: Identify potential issues, risks, and improvement opportunities
20
20
 
21
- - **๐ŸŽฏ Multiple LLM Providers**: Claude, OpenAI, Gemini, OpenRouter, Ollama
22
- - **๐Ÿ”ง Custom Models**: Use any model name - fine-tunes, beta models, custom deployments
23
- - **๐Ÿ“‹ Suggested Models**: Curated lists of latest models with easy selection
24
- - **๐Ÿš€ Latest Models**: OpenAI O3/O4 series, Gemini 2.5, updated OpenRouter models
25
- - **๐Ÿ”„ Backward Compatible**: Existing configurations continue working seamlessly
26
- - **โšก No Restrictions**: Direct API model names accepted without validation
21
+ ### ๐Ÿค– **Flexible AI Support**
22
+ - **Multiple LLM Providers**: Claude, OpenAI, Gemini, OpenRouter, Ollama
23
+ - **Latest Models**: OpenAI O3/O4 series, Gemini 2.5, Claude Sonnet 4.0
24
+ - **Custom Models**: Support for fine-tuned models, beta releases, and custom deployments
25
+
26
+ ### ๐Ÿ’ป **Development Workflow**
27
+ - **Natural Language Commands**: Convert descriptions to executable bash commands
28
+ - **Ruby Code Generation**: Generate Ruby code from natural language instructions
29
+ - **VCS Integration**: Full Git and Mercurial support with branch comparison
30
+ - **Errbit Integration**: Analyze errors and generate actionable reports
31
+
32
+ ## ๐ŸŽฏ **Jira Integration - Get Started in 2 Minutes**
33
+
34
+ Transform your development workflow with intelligent Jira integration:
35
+
36
+ ### Quick Setup
37
+
38
+ ```bash
39
+ # Install and configure
40
+ gem install n2b
41
+ n2b --advanced-config # Set up Jira credentials
42
+
43
+ # Test your connection
44
+ n2b-test-jira
45
+
46
+ # Analyze code against ticket requirements
47
+ n2b --diff --jira PROJ-123 --jira-update
48
+ ```
49
+
50
+ ### What You Get
51
+
52
+ 1. **๐Ÿ“ฅ Smart Ticket Analysis**: Automatically fetches requirements, acceptance criteria, and comments from Jira
53
+ 2. **๐Ÿ” Intelligent Code Review**: AI analyzes your changes against ticket requirements
54
+ 3. **๐Ÿ“ค Structured Updates**: Posts beautifully formatted analysis back to Jira with collapsible sections
55
+ 4. **โœ… Requirements Compliance**: Clear status on what's implemented, partially done, or missing
56
+
57
+ ### Example Workflow
58
+
59
+ ```bash
60
+ # Working on ticket PROJ-123
61
+ git add .
62
+ n2b --diff --jira PROJ-123 --jira-update
63
+ ```
64
+
65
+ **Result**: Your Jira ticket gets updated with a professional analysis comment showing implementation progress, technical insights, and compliance status.
66
+
67
+ ## ๐Ÿ” **AI-Powered Code Analysis**
68
+
69
+ Get comprehensive code review and insights:
70
+
71
+ ```bash
72
+ # Analyze uncommitted changes
73
+ n2b --diff
74
+
75
+ # Compare against specific branch with requirements
76
+ n2b --diff --branch main --requirements requirements.md
77
+
78
+ # Full workflow with Jira integration
79
+ n2b --diff --jira PROJ-123 --requirements specs.md
80
+ ```
81
+
82
+ ## ๐Ÿ†• **What's New in v0.5.0**
83
+
84
+ - **๐ŸŽฏ Full Jira Integration**: Real API integration with ticket fetching and automated updates
85
+ - **๐Ÿ“ Structured Comments**: Beautifully formatted Jira comments with collapsible sections
86
+ - **๐Ÿ” Smart Requirements Extraction**: AI identifies requirements from tickets and comments
87
+ - **๐Ÿงช Connection Testing**: Built-in `n2b-test-jira` utility for troubleshooting
88
+ - **๐Ÿ“‹ Permission Validation**: Verifies all required Jira API permissions
89
+ - **โšก Enhanced Analysis**: Improved code review with better context and insights
27
90
 
28
91
  ## Installation
29
92
 
@@ -31,7 +94,39 @@ N2B (Natural Language to Bash & Ruby) is a Ruby gem that leverages AI to convert
31
94
  gem install n2b
32
95
  ```
33
96
 
34
- ## Usage
97
+ ## Quick Start
98
+
99
+ ### ๐ŸŽฏ **For Jira Users** (Most Popular)
100
+
101
+ ```bash
102
+ # Set up Jira integration
103
+ n2b --advanced-config
104
+
105
+ # Analyze code changes against ticket
106
+ n2b --diff --jira PROJ-123 --jira-update
107
+ ```
108
+
109
+ ### ๐Ÿ” **For Code Review**
110
+
111
+ ```bash
112
+ # AI-powered diff analysis
113
+ n2b --diff
114
+
115
+ # Compare against main branch with requirements
116
+ n2b --diff --branch main --requirements specs.md
117
+ ```
118
+
119
+ ### ๐Ÿ’ป **For Command Generation**
120
+
121
+ ```bash
122
+ # Generate bash commands
123
+ n2b "create a new git repo and push to github"
124
+
125
+ # Execute commands directly
126
+ n2b -x "backup all .rb files to backup folder"
127
+ ```
128
+
129
+ ## Detailed Usage
35
130
 
36
131
  ### In IRB/Rails Console
37
132
 
@@ -232,7 +327,11 @@ Options:
232
327
  - `-d` or `--diff`: Analyze git/hg diff with AI-powered code review
233
328
  - `-b` or `--branch [BRANCH]`: Compare against specific branch (auto-detects main/master/default)
234
329
  - `-r` or `--requirements FILE`: Requirements file for compliance checking
330
+ - `-j` or `--jira TICKET`: Jira ticket ID or URL for context and updates
331
+ - `--jira-update`: Automatically update Jira ticket with analysis (no prompt)
332
+ - `--jira-no-update`: Skip Jira ticket update (analyze only)
235
333
  - `-c` or `--config`: Reconfigure the tool
334
+ - `--advanced-config`: Advanced configuration including Jira setup
236
335
  - `-h` or `--help`: Display help information
237
336
 
238
337
  Examples:
@@ -326,6 +425,115 @@ Requirements Evaluation:
326
425
  - **Git**: Full support with auto-detection of main/master branches
327
426
  - **Mercurial (hg)**: Full support with auto-detection of default branch
328
427
 
428
+ ## ๐ŸŽฏ Jira Integration
429
+
430
+ N2B provides seamless integration with Jira for automated ticket analysis and updates.
431
+
432
+ ### Setup
433
+
434
+ Configure Jira integration using the advanced configuration:
435
+
436
+ ```bash
437
+ n2b --advanced-config
438
+ ```
439
+
440
+ You'll need:
441
+ - **Jira Domain**: Your Atlassian domain (e.g., `company.atlassian.net`)
442
+ - **Email**: Your Jira account email
443
+ - **API Token**: Generate from [Atlassian Account Settings](https://id.atlassian.com/manage-profile/security/api-tokens)
444
+
445
+ ### Required Jira Permissions
446
+
447
+ Your API token needs these permissions:
448
+ - **Browse Projects** - Access project list
449
+ - **Browse Issues** - Read ticket details
450
+ - **View Comments** - Read ticket comments
451
+ - **Add Comments** - Post analysis results
452
+
453
+ ### Usage
454
+
455
+ ```bash
456
+ # Analyze code changes against Jira ticket requirements
457
+ n2b --diff --jira PROJ-123
458
+
459
+ # Use full Jira URL
460
+ n2b --diff --jira https://company.atlassian.net/browse/PROJ-123
461
+
462
+ # Auto-update ticket without prompt
463
+ n2b --diff --jira PROJ-123 --jira-update
464
+
465
+ # Analyze only (no ticket update)
466
+ n2b --diff --jira PROJ-123 --jira-no-update
467
+ ```
468
+
469
+ ### What It Does
470
+
471
+ 1. **Fetches Ticket Details**: Downloads ticket description and comments
472
+ 2. **Extracts Requirements**: Automatically identifies requirements, acceptance criteria, and tasks
473
+ 3. **Analyzes Code Changes**: Compares your diff against ticket requirements
474
+ 4. **Updates Ticket**: Posts structured analysis comment with:
475
+ - Implementation summary (what you accomplished)
476
+ - Technical analysis findings
477
+ - Potential issues and suggestions
478
+ - Test coverage assessment
479
+ - Requirements compliance check
480
+
481
+ ### Example Jira Comment
482
+
483
+ ```
484
+ *N2B Code Analysis Report*
485
+ =========================
486
+
487
+ *Implementation Summary:*
488
+ Implemented user authentication with JWT tokens, password validation,
489
+ and session management as specified in the ticket requirements.
490
+
491
+ ---
492
+
493
+ *Automated Analysis Findings:*
494
+
495
+ *Technical Changes:*
496
+ Added authentication middleware, JWT token generation, and password
497
+ hashing with bcrypt. Updated user model with authentication methods.
498
+
499
+ *Potential Issues/Risks:*
500
+ โ€ข No rate limiting on login attempts
501
+ โ€ข Password validation could be stronger
502
+
503
+ *Suggested Improvements:*
504
+ โ€ข Add rate limiting middleware
505
+ โ€ข Implement password strength requirements
506
+ โ€ข Add two-factor authentication support
507
+
508
+ *Test Coverage Assessment:*
509
+ Good: Basic authentication flow tested. Missing: Edge cases, security
510
+ scenarios, and JWT expiration handling tests.
511
+
512
+ *Requirements Evaluation:*
513
+ โœ… IMPLEMENTED: User login/logout functionality
514
+ โœ… IMPLEMENTED: Password hashing and validation
515
+ โš ๏ธ PARTIALLY IMPLEMENTED: Session management (basic implementation)
516
+ โŒ NOT IMPLEMENTED: Two-factor authentication
517
+ ```
518
+
519
+ ### Testing Jira Connection
520
+
521
+ Test your Jira API connection and permissions:
522
+
523
+ ```bash
524
+ # Test basic connection
525
+ n2b-test-jira
526
+
527
+ # Test specific ticket access
528
+ n2b-test-jira PROJ-123
529
+ ```
530
+
531
+ This will verify:
532
+ - Network connectivity to Jira
533
+ - Authentication with your API token
534
+ - Required permissions
535
+ - Specific ticket access (if provided)
536
+
329
537
  n2r in ruby or rails console
330
538
  n2r "your question", files:['file1.rb', 'file2.rb'], exception: AnError
331
539
  only question is mandatory
@@ -385,6 +593,27 @@ Contributions are welcome! Please feel free to submit a Pull Request.
385
593
 
386
594
  This project is licensed under the MIT License.
387
595
 
596
+ ## Version History
597
+
598
+ ### ๐Ÿš€ **v0.5.0 - Jira Integration & Enhanced Analysis**
599
+ - Full Jira API integration with real ticket fetching and comment posting
600
+ - Structured Jira comments using ADF with collapsible sections
601
+ - Smart requirements extraction from ticket descriptions and comments
602
+ - Built-in connection testing with `n2b-test-jira` utility
603
+ - Enhanced configuration validation and error handling
604
+
605
+ ### ๐Ÿ”ง **v0.4.0 - Flexible Model Configuration**
606
+ - Multiple LLM providers: Claude, OpenAI, Gemini, OpenRouter, Ollama
607
+ - Custom model support for fine-tunes and beta releases
608
+ - Latest models: OpenAI O3/O4 series, Gemini 2.5, Claude Sonnet 4.0
609
+ - Backward compatible configuration system
610
+
611
+ ### ๐Ÿ” **v0.3.0 - AI-Powered Diff Analysis**
612
+ - Git/Mercurial diff analysis with context extraction
613
+ - Requirements compliance checking
614
+ - Test coverage assessment
615
+ - Branch comparison with auto-detection
616
+
388
617
  ## Support
389
618
 
390
619
  If you encounter any issues or have questions, please file an issue on the GitHub repository.
@@ -413,4 +642,4 @@ The generated tickets include:
413
642
  - Acceptance criteria
414
643
  - Story point estimate
415
644
  - Priority level
416
- - Reference to the original Errbit URL# Test change
645
+ - Reference to the original Errbit URL
data/bin/n2b-test-jira ADDED
@@ -0,0 +1,273 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
6
+ require 'base64'
7
+ require 'yaml'
8
+
9
+ # Jira API connection tester for N2B
10
+ # Tests authentication, permissions, and specific ticket access
11
+ class JiraConnectionTester
12
+ def initialize
13
+ @config_file = File.expand_path('~/.n2b/config.yml')
14
+ load_config
15
+ end
16
+
17
+ def load_config
18
+ unless File.exist?(@config_file)
19
+ puts "โŒ Config file not found: #{@config_file}"
20
+ puts "Please run 'n2b --advanced-config' to set up Jira integration first."
21
+ exit 1
22
+ end
23
+
24
+ @config = YAML.load_file(@config_file)
25
+ @jira_config = @config['jira']
26
+
27
+ unless @jira_config && @jira_config['domain'] && @jira_config['email'] && @jira_config['api_key']
28
+ puts "โŒ Jira configuration incomplete in #{@config_file}"
29
+ puts "Missing: domain, email, or api_key"
30
+ puts "Please run 'n2b --advanced-config' to configure Jira."
31
+ exit 1
32
+ end
33
+
34
+ # Handle domain that may or may not include protocol
35
+ domain = @jira_config['domain'].to_s.strip
36
+ if domain.start_with?('http://') || domain.start_with?('https://')
37
+ @base_url = "#{domain.chomp('/')}/rest/api/3"
38
+ else
39
+ @base_url = "https://#{domain.chomp('/')}/rest/api/3"
40
+ end
41
+
42
+ puts "โœ… Config loaded successfully"
43
+ puts " Domain: #{@jira_config['domain']}"
44
+ puts " Email: #{@jira_config['email']}"
45
+ puts " API Key: #{@jira_config['api_key'][0..10]}..." # Show only first part for security
46
+ puts " Base URL: #{@base_url}"
47
+ puts
48
+ end
49
+
50
+ def test_connection
51
+ puts "๐Ÿ” Testing Jira API connection..."
52
+ puts "=" * 50
53
+
54
+ # Test 1: Basic API connectivity
55
+ test_basic_connectivity
56
+
57
+ # Test 2: Authentication
58
+ test_authentication
59
+
60
+ # Test 3: Permissions
61
+ test_permissions
62
+
63
+ # Test 4: Specific ticket access (if provided)
64
+ if ARGV[0]
65
+ test_ticket_access(ARGV[0])
66
+ else
67
+ puts "๐Ÿ’ก To test specific ticket access, run: ruby test_jira_connection.rb TICKET-123"
68
+ end
69
+ end
70
+
71
+ private
72
+
73
+ def test_basic_connectivity
74
+ puts "1๏ธโƒฃ Testing basic connectivity to Jira..."
75
+
76
+ begin
77
+ uri = URI.parse(@base_url)
78
+ puts " Connecting to: #{uri.host}:#{uri.port}"
79
+
80
+ http = Net::HTTP.new(uri.host, uri.port)
81
+ http.use_ssl = (uri.scheme == 'https')
82
+ http.open_timeout = 10
83
+ http.read_timeout = 10
84
+
85
+ # Simple GET to the API root
86
+ request = Net::HTTP::Get.new('/rest/api/3/')
87
+ response = http.request(request)
88
+
89
+ puts " โœ… Connection successful (HTTP #{response.code})"
90
+ puts
91
+ rescue => e
92
+ puts " โŒ Connection failed: #{e.message}"
93
+ puts " Check your network connection and domain configuration."
94
+ exit 1
95
+ end
96
+ end
97
+
98
+ def test_authentication
99
+ puts "2๏ธโƒฃ Testing authentication..."
100
+
101
+ begin
102
+ response = make_api_request('GET', '/myself')
103
+
104
+ if response['accountId']
105
+ puts " โœ… Authentication successful"
106
+ puts " Account ID: #{response['accountId']}"
107
+ puts " Display Name: #{response['displayName']}"
108
+ puts " Email: #{response['emailAddress']}"
109
+ puts
110
+ else
111
+ puts " โš ๏ธ Authentication response unexpected:"
112
+ puts " #{response}"
113
+ puts
114
+ end
115
+ rescue => e
116
+ puts " โŒ Authentication failed: #{e.message}"
117
+ puts " Check your email and API token."
118
+ puts " API token should be generated from: https://id.atlassian.com/manage-profile/security/api-tokens"
119
+ exit 1
120
+ end
121
+ end
122
+
123
+ def test_permissions
124
+ puts "3๏ธโƒฃ Testing required permissions..."
125
+
126
+ begin
127
+ # Test 1: Project access (Browse Projects permission)
128
+ response = make_api_request('GET', '/project')
129
+
130
+ if response.is_a?(Array) && response.length > 0
131
+ puts " โœ… Browse Projects: Can access #{response.length} projects"
132
+ response.first(3).each do |project|
133
+ puts " - #{project['key']}: #{project['name']}"
134
+ end
135
+ puts " ... (showing first 3)" if response.length > 3
136
+
137
+ # Test 2: Issue access (Browse Issues permission)
138
+ test_project = response.first
139
+ puts " ๐Ÿ” Testing issue access in project: #{test_project['key']}"
140
+
141
+ begin
142
+ issues_response = make_api_request('GET', "/search?jql=project=#{test_project['key']}&maxResults=1")
143
+ if issues_response['issues'] && issues_response['issues'].length > 0
144
+ puts " โœ… Browse Issues: Can access issues in #{test_project['key']}"
145
+
146
+ # Test 3: Comment access (if we found an issue)
147
+ test_issue = issues_response['issues'].first
148
+ begin
149
+ comments_response = make_api_request('GET', "/issue/#{test_issue['key']}/comment")
150
+ puts " โœ… View Comments: Can access comments on #{test_issue['key']}"
151
+ rescue => e
152
+ puts " โŒ View Comments: Cannot access comments (#{e.message})"
153
+ end
154
+
155
+ # Test 4: Add comment permission (we won't actually add, just check the endpoint)
156
+ puts " โ„น๏ธ Add Comments: Will be tested when actually posting comments"
157
+ else
158
+ puts " โš ๏ธ No issues found in #{test_project['key']} to test comment permissions"
159
+ end
160
+ rescue => e
161
+ puts " โŒ Browse Issues: Cannot search issues (#{e.message})"
162
+ end
163
+
164
+ puts
165
+ else
166
+ puts " โŒ Browse Projects: No projects accessible"
167
+ puts " Your API token needs 'Browse Projects' permission"
168
+ puts
169
+ end
170
+ rescue => e
171
+ puts " โŒ Permission test failed: #{e.message}"
172
+ puts " Your API token might not have sufficient permissions."
173
+ puts
174
+ end
175
+
176
+ puts " ๐Ÿ“‹ Required Jira Permissions for N2B:"
177
+ puts " โ€ข Browse Projects - to access project list"
178
+ puts " โ€ข Browse Issues - to read ticket details"
179
+ puts " โ€ข View Comments - to read ticket comments"
180
+ puts " โ€ข Add Comments - to post analysis results"
181
+ puts
182
+ end
183
+
184
+ def test_ticket_access(ticket_key)
185
+ puts "4๏ธโƒฃ Testing access to specific ticket: #{ticket_key}..."
186
+
187
+ begin
188
+ # Test ticket access
189
+ response = make_api_request('GET', "/issue/#{ticket_key}")
190
+
191
+ puts " โœ… Ticket access successful"
192
+ puts " Key: #{response['key']}"
193
+ puts " Summary: #{response.dig('fields', 'summary')}"
194
+ puts " Status: #{response.dig('fields', 'status', 'name')}"
195
+ puts " Assignee: #{response.dig('fields', 'assignee', 'displayName') || 'Unassigned'}"
196
+ puts
197
+
198
+ # Test comments access
199
+ comments_response = make_api_request('GET', "/issue/#{ticket_key}/comment")
200
+ comment_count = comments_response.dig('comments')&.length || 0
201
+ puts " โœ… Comments access successful (#{comment_count} comments)"
202
+ puts
203
+
204
+ rescue => e
205
+ puts " โŒ Ticket access failed: #{e.message}"
206
+
207
+ if e.message.include?('404')
208
+ puts " Possible causes:"
209
+ puts " - Ticket doesn't exist"
210
+ puts " - You don't have permission to view this ticket"
211
+ puts " - Ticket is in a project you can't access"
212
+ elsif e.message.include?('401')
213
+ puts " Authentication issue - check your API token"
214
+ elsif e.message.include?('403')
215
+ puts " Permission denied - your account can't access this ticket"
216
+ end
217
+ puts
218
+ end
219
+ end
220
+
221
+ def make_api_request(method, path, body = nil)
222
+ full_url = "#{@base_url}#{path}"
223
+ uri = URI.parse(full_url)
224
+
225
+ http = Net::HTTP.new(uri.host, uri.port)
226
+ http.use_ssl = (uri.scheme == 'https')
227
+ http.read_timeout = 30
228
+ http.open_timeout = 10
229
+
230
+ request = case method.upcase
231
+ when 'GET'
232
+ Net::HTTP::Get.new(uri.request_uri)
233
+ when 'POST'
234
+ req = Net::HTTP::Post.new(uri.request_uri)
235
+ req.body = body.to_json if body
236
+ req
237
+ else
238
+ raise "Unsupported HTTP method: #{method}"
239
+ end
240
+
241
+ request['Authorization'] = "Basic #{Base64.strict_encode64("#{@jira_config['email']}:#{@jira_config['api_key']}")}"
242
+ request['Content-Type'] = 'application/json'
243
+ request['Accept'] = 'application/json'
244
+
245
+ response = http.request(request)
246
+
247
+ unless response.is_a?(Net::HTTPSuccess)
248
+ error_message = "Jira API Error: #{response.code} #{response.message}"
249
+ error_message += " - #{response.body}" if response.body && !response.body.empty?
250
+ raise error_message
251
+ end
252
+
253
+ response.body.empty? ? {} : JSON.parse(response.body)
254
+ rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
255
+ Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, Errno::ECONNREFUSED => e
256
+ raise "Jira API request failed: #{e.class} - #{e.message}"
257
+ end
258
+ end
259
+
260
+ # Run the test
261
+ if __FILE__ == $0
262
+ puts "๐Ÿงช Jira API Connection Tester"
263
+ puts "=" * 50
264
+ puts
265
+
266
+ tester = JiraConnectionTester.new
267
+ tester.test_connection
268
+
269
+ puts "๐ŸŽ‰ Test completed!"
270
+ puts
271
+ puts "If all tests passed, your Jira integration should work correctly."
272
+ puts "If any tests failed, check the error messages above for guidance."
273
+ end