Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confluence api v2 and Jira api v3 added #1522

Open
wants to merge 52 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
33b7d66
Add Confluence API v2 implementation checklist
batzel-upenn Apr 1, 2025
14077d3
Implement Phase 1: Core Structure for Confluence API v2 support
batzel-upenn Apr 1, 2025
a97ab3f
Implement Phase 2: Core Methods for Confluence API v2 support
batzel-upenn Apr 1, 2025
d0f44f4
Implement comment methods for Confluence V2 API
batzel-upenn Apr 1, 2025
bcda06d
Implement whiteboard and custom content methods for Confluence V2 API
batzel-upenn Apr 1, 2025
3ad75e4
Implement Confluence V2 API compatibility layer and migration guide
batzel-upenn Apr 1, 2025
bfdb287
Complete Phase 4: Testing for Confluence v2 API implementation
batzel-upenn Apr 1, 2025
9bdb469
Add remaining Confluence v2 implementation files for Phases 1-4
batzel-upenn Apr 1, 2025
8e3fd9b
Complete Phase 5: Documentation for Confluence v2 API implementation
batzel-upenn Apr 1, 2025
1635b0c
Improve security by removing hardcoded credentials and implement envi…
batzel-upenn Apr 1, 2025
423208f
Update README.rst to add contributor credits for Confluence v2 API im…
batzel Apr 1, 2025
2c1bc60
refactor: reorganize Confluence module into proper directory structure
batzel Apr 2, 2025
9f89053
security: improve URL validation in Confluence base class
batzel Apr 2, 2025
350c32c
fix: update imports and test structure for new Confluence module orga…
batzel Apr 2, 2025
04863f8
Fix hanging Confluence tests and improve test reliability
batzel Apr 2, 2025
c53ff64
Fix URL handling to prevent /wiki/wiki duplication in Confluence client
batzel Apr 2, 2025
484510b
Add space-related methods from master to refactored Confluence structure
batzel Apr 2, 2025
6edd103
Complete refactoring of Confluence Cloud module with V2 API support
batzel Apr 2, 2025
48c4f6c
Fix Codacy critical issues in examples - Fixed parameter names for AP…
batzel Apr 2, 2025
949b05d
Fix string statement and unused variable in examples/confluence_v2_co…
batzel Apr 2, 2025
32f93ec
Fix unused variables and cleanup example files
batzel Apr 2, 2025
36133c0
Fix Codacy Critical issue - remove return statement outside function
batzel Apr 2, 2025
ab02155
Fix Codacy code style issues - remove unused imports, fix parameter n…
batzel Apr 2, 2025
783ae04
Apply Black formatting to improve code style
batzel Apr 2, 2025
de92224
Apply isort to fix import order issues
batzel Apr 2, 2025
7cbc897
Add custom content label and property methods, fix compatibility laye…
batzel Apr 2, 2025
eca9f45
This project is to upgrade the jira portion of atlassian-python-api t…
batzel Apr 2, 2025
060f89a
Implement Phase 1 and core methods of Phase 2 for Jira v3 API
batzel Apr 2, 2025
46566d7
Add missing adapter methods for legacy compatibility
batzel Apr 2, 2025
4ec70d2
Add get_current_user method to CloudJira class
batzel Apr 2, 2025
65f9050
Complete Phase 1: Add error handling, validation and debugging
batzel Apr 2, 2025
43b2b2c
Update checklist: Phase 1 now 100% complete
batzel Apr 2, 2025
e0e4ba5
Complete Phase 2: Implement remaining core methods
batzel Apr 2, 2025
11df010
Implement Phase 3 features: Jira Software API and Permissions API
batzel Apr 2, 2025
d29e06f
Add examples for Jira Software and Permissions API usage
batzel Apr 2, 2025
5bd0128
Add example script for Jira User and Group Management API
batzel Apr 2, 2025
52af69f
Add Rich Text support with Atlassian Document Format (ADF)
batzel Apr 2, 2025
aaac219
Add Issue Types and Field Configurations support
batzel Apr 2, 2025
3ad1e19
Add enhanced project configuration support
batzel Apr 2, 2025
e1fab31
Add advanced search capabilities
batzel Apr 2, 2025
6965fc6
Complete Phase 3 implementation with user management and search capab…
batzel Apr 2, 2025
affc619
Implement Phase 4 - Testing for Jira V3 API
batzel Apr 2, 2025
87c90d8
Add integration test script and documentation
batzel Apr 2, 2025
6f043eb
Enhanced error handling and fixed Jira issue creation in v3 API
batzel Apr 3, 2025
999ffa7
Complete Phase 4 testing for Jira V3 API implementation. Add server-s…
batzel Apr 3, 2025
05e589b
Implement Jira V3 API with server integration and cloud support - Bas…
batzel Apr 3, 2025
7227dd8
Fix import path in Jira V3 mock tests
batzel Apr 3, 2025
60cd9e0
Fix Jira V3 integration tests to handle offline mode correctly
batzel Apr 3, 2025
c936e49
Fix Jira V3 integration tests and code style issues
batzel Apr 3, 2025
2a8a2a9
Remove automatic /wiki URL handling in Confluence client
batzel Apr 3, 2025
7bedaaf
Update README and integration tests for Confluence URL handling, add …
batzel Apr 3, 2025
93f2e8e
Jira V3 API implementation updates
batzel Apr 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Atlassian Python API - Test Environment Variables
# Copy this file to .env and fill in your values

# ==== Jira Cloud Credentials for v3 tests ====
JIRA_URL=https://your-instance.atlassian.net
[email protected]
JIRA_API_TOKEN=your-api-token
JIRA_PROJECT_KEY=TEST

# ==== Jira Server Credentials for v3 tests ====
JIRA_SERVER_URL=https://your-server-instance.example.com
JIRA_SERVER_USERNAME=your-username
JIRA_SERVER_PASSWORD=your-password
JIRA_SERVER_PROJECT_KEY=TEST

# ==== Confluence Cloud Credentials ====
CONFLUENCE_URL=https://your-instance.atlassian.net
[email protected]
CONFLUENCE_API_TOKEN=your-api-token
CONFLUENCE_SPACE_KEY=TEST

# ==== BitBucket Cloud Credentials ====
BITBUCKET_URL=https://api.bitbucket.org
BITBUCKET_USERNAME=your-username
BITBUCKET_PASSWORD=your-app-password
BITBUCKET_WORKSPACE=your-workspace

# ==== Service Desk Credentials ====
SERVICE_DESK_URL=https://your-instance.atlassian.net
[email protected]
SERVICE_DESK_PASSWORD=your-api-token
SERVICE_DESK_PROJECT_KEY=TEST

# ==== Test Settings ====
# Set to "true" to skip tests that require admin permissions
SKIP_ADMIN_TESTS=false

# Optional: Skip expensive tests (tests that create/update many entities)
SKIP_EXPENSIVE_TESTS=false
29 changes: 29 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[flake8]
# Set the maximum line length to 120
max-line-length = 120

# Ignore some common errors that are not relevant for our codebase
ignore =
# Ignore unused imports for type hints
F401,
# Ignore redefinition of unused variables
F811,
# Ignore whitespace warning in blank lines
W293,
# Ignore trailing whitespace
W291,
# Ignore whitespace around arithmetic operators
E226,
# Ignore missing placeholders in f-strings
F541,
# Ignore bare except (though we should fix these later)
E722

# Exclude specific directories from linting
exclude =
.git,
__pycache__,
.tox,
.mypy_cache,
build,
dist
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
- Jira V3 API support (Cloud and Server)
- Base API implementation
- Issue operations with ADF document format support
- Enhanced error handling
- Specialized client adapters for different Jira API areas
- Rich text support via JiraADF helper
- Improved pagination for search results
- Migration guide from V2 to V3 API

### Fixed
- JQL pagination with small page sizes
- Various code style improvements to meet linting standards

### Changed
- Project versioning is now at 4.0.3
46 changes: 42 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,43 @@ The traditional jql method is deprecated for Jira Cloud users, as Atlassian has
data = jira.enhanced_jql(JQL)
print(data)

Using Confluence v2 API
_______________________

The library now supports Confluence's v2 API for Cloud instances. The v2 API provides improved performance, new content types, and more consistent endpoint patterns.

.. code-block:: python

from atlassian import Confluence

# Initialize with v2 API
confluence = Confluence(
url='https://your-instance.atlassian.net/wiki', # Include /wiki in the URL if required by your instance
username='[email protected]',
password='your-api-token',
api_version=2, # Specify API version 2
cloud=True # v2 API is only available for cloud instances
)

# Get pages from a space
pages = confluence.get_pages(space_key='DEMO', limit=10)

# Create a new page
new_page = confluence.create_page(
space_id='DEMO',
title='New Page with v2 API',
body='<p>This page was created using the v2 API</p>'
)

# Use v2-only features like whiteboards
whiteboard = confluence.create_whiteboard(
space_id='DEMO',
title='My Whiteboard',
content='{"version":1,"type":"doc","content":[]}'
)

The library includes a compatibility layer to ease migration from v1 to v2 API. See the migration guide in the documentation for details.

Also, you can use the Bitbucket module e.g. for getting project list

.. code-block:: python
Expand Down Expand Up @@ -211,11 +248,12 @@ In addition to all the contributors we would like to thank these vendors:
* Atlassian_ for developing such a powerful ecosystem.
* JetBrains_ for providing us with free licenses of PyCharm_
* Microsoft_ for providing us with free licenses of VSCode_
* GitHub_ for hosting our repository and continuous integration
* Cursor.com_ for AI assistance in development
* John B Batzel ([email protected]) for implementing the Confluence Cloud v2 API support

.. _Atlassian: https://www.atlassian.com/
.. _JetBrains: http://www.jetbrains.com
.. _PyCharm: http://www.jetbrains.com/pycharm/
.. _GitHub: https://github.com/
.. _Microsoft: https://github.com/Microsoft/vscode/
.. _VSCode: https://code.visualstudio.com/
.. _Microsoft: https://www.microsoft.com
.. _VSCode: https://code.visualstudio.com
.. _Cursor.com: https://cursor.com
165 changes: 165 additions & 0 deletions README_JIRA_V3_SERVER_TESTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# Jira Server V3 API Integration Tests

This document provides instructions for running the integration tests for the Jira Server V3 API implementation in the Atlassian Python API client.

## Prerequisites

1. A Jira Server instance with admin access
2. Python 3.6 or higher
3. Dependencies installed (`pip install -r requirements.txt`)

## Setting Up Environment Variables

1. Create a `.env` file in the root directory of the project based on the `.env.example` file:

```
# Jira Server credentials for integration tests
JIRA_SERVER_URL=https://your-server-instance.example.com
JIRA_SERVER_USERNAME=your-username
JIRA_SERVER_PASSWORD=your-password
JIRA_SERVER_PROJECT_KEY=TEST
```

2. Replace placeholders with your actual Jira Server instance details:
- `JIRA_SERVER_URL`: Your Jira Server instance URL
- `JIRA_SERVER_USERNAME`: Your username for the Jira Server instance
- `JIRA_SERVER_PASSWORD`: Your password for the Jira Server instance
- `JIRA_SERVER_PROJECT_KEY`: A project key in your Jira Server instance that can be used for testing

## Running Integration Tests

### Running Tests Manually

```bash
# Load environment variables (bash/zsh)
source .env
# Or in Windows PowerShell
# Get-Content .env | ForEach-Object { $data = $_.Split('='); if($data[0] -and $data[1]) { Set-Item -Path "env:$($data[0])" -Value $data[1] } }

# Run tests
python -m unittest tests/test_jira_v3_server_integration.py -v
```

### Running Specific Test Classes or Methods

To run a specific test class:

```bash
python -m unittest tests.test_jira_v3_server_integration.TestJiraV3ServerIntegration
```

To run a specific test method:

```bash
python -m unittest tests.test_jira_v3_server_integration.TestJiraV3ServerIntegration.test_get_current_user
```

### Running Tests in Offline Mode

You can run the tests without an actual Jira Server instance using the offline mode with mocks:

```bash
JIRA_OFFLINE_TESTS=true python -m unittest tests/test_jira_v3_server_integration.py -v
```

This mode uses mock responses to simulate a Jira Server instance, which is useful for:
- Running tests in CI environments without access to a Jira Server
- Quick validation of code changes without hitting rate limits
- Testing error handling without needing to reproduce errors on a real instance

### Using the Convenience Script

A convenience script is provided to simplify running tests:

```bash
# Run Jira Server tests
./run_jira_v3_tests.sh --server

# Run a specific class
./run_jira_v3_tests.sh --server --class TestJiraV3ServerIntegration
```

## Key Test Cases

The integration tests for Jira Server include the following key test cases:

1. **Core Functionality Tests (TestJiraV3ServerIntegration)**
- `test_get_current_user`: Verifies authentication and user data
- `test_get_all_projects`: Tests retrieving projects list
- `test_get_project`: Tests retrieving a single project
- `test_search_issues`: Tests JQL search functionality
- `test_pagination_handling`: Tests server-specific pagination

2. **Issue Operations Tests (TestJiraV3ServerIssuesIntegration)**
- `test_create_and_get_issue`: Tests issue creation and retrieval
- `test_update_issue`: Tests updating issue fields
- `test_get_issue_transitions`: Tests retrieving valid transitions
- `test_issue_comments`: Tests adding/updating comments

3. **Permissions Tests (TestJiraV3ServerPermissionsIntegration)**
- `test_permission_handling`: Tests handling of permission-sensitive operations
- `test_get_my_permissions`: Tests retrieving the current user's permissions

## Test Categories

The integration tests for Jira Server cover the following areas:

1. **Core Jira Functionality**: Basic API operations working with the server instance
2. **Issue Operations**: Issue CRUD operations, transitions, comments
3. **Project Operations**: Project components and versions

## Differences Between Server and Cloud

The Jira Server tests are designed to handle the differences between Server and Cloud instances:

1. **Authentication**: Server uses username/password rather than API tokens
2. **Response Format**: Server responses may have different field names or structures
3. **Comment Format**: Server may handle rich text differently than Cloud
4. **Error Handling**: Server may have different error messages or codes

## Troubleshooting

If you encounter issues:

1. Verify your environment variables are correctly set in the `.env` file
2. Ensure your credentials are valid
3. Check that your user has sufficient permissions in the Jira Server instance
4. Verify network connectivity to your Jira Server instance

For specific test failures, examine the error messages which often contain details about the API response that caused the failure.

## Adapting Tests for Your Environment

You may need to adapt the tests to match your specific Jira Server configuration:

1. Edit `tests/test_jira_v3_server_integration.py` to update issue creation data:
- Update issue types to match those available in your project
- Add any required custom fields specific to your Jira configuration

2. For permission-sensitive tests, you can use the `check_permissions` helper method which will skip tests that require administrative privileges if your user doesn't have them.

## Known Limitations

1. **API Version Compatibility**: Some Jira Server versions may not fully support the v3 API
2. **Feature Availability**: Not all Cloud features are available in Server instances
3. **Self-Hosted Considerations**: Firewalls, VPNs, or custom configurations may impact test connectivity

## Debugging Integration Tests

For more detailed debugging:

1. Increase logging level by modifying the `logging.basicConfig(level=logging.DEBUG)` line in the test file
2. Add print statements in specific test methods
3. Use more specific test runs to isolate issues
4. Check Jira Server logs for additional error information

## Contributing New Tests

When adding new tests:

1. Follow the existing pattern of creating test methods within the appropriate test class
2. Ensure tests are isolated and do not depend on the state from other tests
3. Clean up any created resources (like issues) at the end of tests
4. Add proper assertions to verify both structure and content of responses
5. Consider differences between Server and Cloud APIs
6. Use the `check_permissions` helper to gracefully handle permission issues
Loading