n2b 0.4.0 โ 0.5.1
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 +4 -4
- data/README.md +250 -21
- data/bin/n2b-test-jira +273 -0
- data/lib/n2b/base.rb +171 -54
- data/lib/n2b/cli.rb +206 -18
- data/lib/n2b/irb.rb +1 -1
- data/lib/n2b/jira_client.rb +753 -0
- data/lib/n2b/llm/ollama.rb +1 -1
- data/lib/n2b/model_config.rb +33 -6
- data/lib/n2b/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58ed8c5277d383ecd58f83b79a90e2328161c1cb45dfa70551facef28641d3f1
|
4
|
+
data.tar.gz: 109d222d1867e76458a6b720c2afe3196c37fcab0648773d0311157c04c63086
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c623f7a497b81bec3edf136d18d4ef2f64578bf347334e91dec4feaf01a43dc0deb374d5da74aa0e513b669f55315a835b7c36588e82221dde8d62c8a7728746
|
7
|
+
data.tar.gz: d4687399cf5e2e9d62fca484616bbd48d9c74b03f6c5266e31362978efb44ea4c13fa44708c5097704c9ca63e0616693b016eb79aa97da2bf664f6e18ff7d431
|
data/README.md
CHANGED
@@ -1,29 +1,92 @@
|
|
1
|
-
# N2B -
|
1
|
+
# N2B - AI-Powered Code Analysis & Jira Integration
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/n2b)
|
4
4
|
|
5
|
-
|
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
|
-
|
10
|
-
-
|
11
|
-
-
|
12
|
-
-
|
13
|
-
-
|
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
|
-
###
|
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
|
-
|
22
|
-
-
|
23
|
-
-
|
24
|
-
-
|
25
|
-
|
26
|
-
|
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
|
-
##
|
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
|
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
|