A robust Python tool for automating the creation of Jira issues and subtasks from CSV data. Features comprehensive error handling, validation, retry logic, and a command-line interface.
- CSV Data Processing: Read and validate CSV files with automatic error detection
- Jira Integration: Create main issues and subtasks with proper linking
- Error Handling: Comprehensive error handling with retry logic and exponential backoff
- Input Validation: Validate CSV structure and data using Pydantic models
- Configuration Management: Environment-based configuration with validation
- Logging: Detailed logging with configurable levels
- CLI Interface: Easy-to-use command-line interface with multiple commands
- Testing: Comprehensive test suite with mocking
-
Clone the repository:
git clone https://github.com/star7js/jira-upload-csv.git cd jira-upload-csv
-
Create a virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
Create a .env
file in the project root with your Jira credentials:
# Copy the example file
cp env.example .env
# Edit .env with your actual values
Required environment variables:
Variable | Description | Example |
---|---|---|
JIRA_BASE_URL |
Your Jira instance URL | https://your-company.atlassian.net |
JIRA_USERNAME |
Your Jira email address | user@example.com |
JIRA_API_TOKEN |
Your Jira API token | your-api-token-here |
Optional environment variables:
Variable | Description | Default |
---|---|---|
LOG_LEVEL |
Logging level (DEBUG, INFO, WARNING, ERROR) | INFO |
DEFAULT_CSV_PATH |
Default CSV file path | data/main_and_subtasks_multiple.csv |
BATCH_SIZE |
Number of issues to process in batch | 10 |
RETRY_ATTEMPTS |
Number of retry attempts for failed requests | 3 |
RETRY_DELAY |
Base delay between retries (seconds) | 5 |
- Go to Atlassian Account Settings
- Click "Create API token"
- Give it a name (e.g., "CSV Upload Tool")
- Copy the generated token to your
.env
file
The tool provides a comprehensive CLI with multiple commands:
# Upload using default CSV file
python cli.py upload
# Upload using specific CSV file
python cli.py upload --csv-file path/to/your/file.csv
# Upload with debug logging
python cli.py upload --log-level DEBUG
# Test Jira connection and configuration
python cli.py test
# Display current configuration
python cli.py config
# Validate CSV file structure and data
python cli.py validate --csv-file path/to/your/file.csv
# Generate a template CSV file
python cli.py template
from src.main import main
# Upload using default CSV file
success = main()
# Upload using specific CSV file
success = main('path/to/your/file.csv')
if success:
print("Upload completed successfully!")
else:
print("Upload failed. Check logs for details.")
The tool expects CSV files with the following structure:
Column | Required | Description |
---|---|---|
ID |
Yes | Unique identifier for grouping related rows |
Project Key |
Yes | Jira project key (e.g., "PROJ") |
Summary |
Yes* | Issue summary (required for main issues) |
Description |
Yes* | Issue description (required for main issues) |
Issue Type |
Yes* | Issue type (required for main issues) |
Subtask Summary |
No | Subtask summary |
Subtask Description |
No | Subtask description |
ID,Project Key,Summary,Description,Issue Type,Subtask Summary,Subtask Description
1,PROJ1,Main Issue 1,This is the first main issue,Task,Subtask 1.1,This is the first subtask for Main Issue 1
1,PROJ1,,,,Subtask 1.2,This is the second subtask for Main Issue 1
2,PROJ1,Main Issue 2,This is the second main issue,Task,Subtask 2.1,This is the first subtask for Main Issue 2
Notes:
- Rows with the same
ID
are grouped together - Each group must have exactly one row with main issue data (Summary, Description, Issue Type)
- Additional rows in the same group can contain subtask data
- Empty subtask fields are ignored
Handles Jira API interactions with retry logic and error handling.
from src.jira_client import JiraClient
client = JiraClient()
success = client.test_connection()
issue = client.create_issue(issue_data)
subtask = client.create_subtask(subtask_data)
Processes and validates CSV files.
from src.csv_processor import CSVProcessor
processor = CSVProcessor('path/to/file.csv')
rows = processor.read_and_validate_csv()
groups = processor.get_issue_groups(rows)
Data model for CSV rows with validation.
from src.models import CSVRow
row = CSVRow(
id='1',
project_key='TEST',
summary='Test Issue',
description='Test Description',
issue_type='Task'
)
Run the test suite:
# Run all tests
python -m pytest tests/
# Run specific test file
python -m pytest tests/test_improved_modules.py
# Run with coverage
python -m pytest tests/ --cov=src --cov-report=html
tests/test_improved_modules.py
: Comprehensive tests for all new modulestests/test_multi_issue_upload_with_subtasks.py
: Original tests (legacy)
-
Authentication Failed
- Verify your Jira credentials in the
.env
file - Ensure your API token is correct and not expired
- Check that your Jira instance URL is correct
- Verify your Jira credentials in the
-
CSV Validation Errors
- Use
python cli.py validate --csv-file your-file.csv
to check for issues - Ensure all required columns are present
- Check that each issue group has exactly one main issue row
- Use
-
Permission Errors
- Ensure your Jira user has permission to create issues in the target project
- Verify the project key exists and is accessible
-
Rate Limiting
- The tool includes automatic retry logic with exponential backoff
- Increase
RETRY_DELAY
in your.env
file if you encounter rate limiting
The tool creates detailed logs in jira_upload.log
. Check this file for detailed error information:
tail -f jira_upload.log
- Fork the repository
- Create a feature branch:
git checkout -b feature-name
- Make your changes and add tests
- Run the test suite:
python -m pytest tests/
- Commit your changes:
git commit -am 'Add feature'
- Push to the branch:
git push origin feature-name
- Submit a pull request
# Install development dependencies
pip install -r requirements.txt
# Install pre-commit hooks (optional)
pre-commit install
# Run linting
flake8 src/ tests/
# Run type checking
mypy src/
This project is licensed under the MIT License. See the LICENSE file for details.
- Atlassian Python API for Jira integration
- Pydantic for data validation
- Click for CLI interface