Skip to content

Bugfix/1855 jira deprecated endpoint - #1860

Merged
FelicianoTech merged 5 commits into
wtfutil:trunkfrom
dfoulkes:bugfix/1855-jira-deprecated-endpoint
Oct 18, 2025
Merged

FelicianoTech merged 5 commits into
wtfutil:trunkfrom
dfoulkes:bugfix/1855-jira-deprecated-endpoint

Conversation

@dfoulkes

@dfoulkes dfoulkes commented Oct 5, 2025 •

Copy link
Copy Markdown
Contributor

fixes #1855

This pull request introduces a new caching mechanism and logic for converting JIRA usernames to account IDs, and updates the search flow to use the new JIRA API v3 endpoints. It also adds unit tests for the new caching and conversion logic. These changes improve the efficiency and reliability of user-based JIRA queries, reduce redundant API calls, and enhance error handling and test coverage.

JIRA Username-to-AccountID Conversion and Caching:

  • Added a thread-safe cache (UserIDCacheMap) to store mappings from JIRA usernames to account IDs, with expiration logic to avoid unnecessary API requests.
  • Implemented the ConvertJQLWithUsername method, which converts a JQL query containing a username to use the corresponding account ID, leveraging the cache and calling the /rest/api/3/jql/pdcleaner endpoint when needed.
  • Added helper functions for extracting account IDs from JQL strings and for cache management (extractAccountIDFromJQL, Set, Get, Clear).

JIRA API Usage and Search Improvements:

  • Refactored the IssuesFor method to use the new API v3 search endpoint (/rest/api/3/search/jql) and fetch full issue details by ID, improving compatibility and future-proofing.
  • Improved error handling in both GET and POST JIRA API requests, providing more informative error messages including response bodies and request URLs.

Testing and Reliability:

  • Added unit tests in client_test.go to cover the caching logic, JQL conversion, error cases, and integration with mocked JIRA endpoints, ensuring robust and predictable behaviour.

Fixes wtfutil#1855 - Replace deprecated username-based queries with account ID conversion

- Implement JQL conversion API using /rest/api/3/jql/pdcleaner endpoint
- Add ConvertJQLWithUsername function to convert usernames to account IDs
- Add jiraPostRequest method for POST requests with JSON payload
- Update IssuesFor function to use converted account IDs instead of usernames
- Maintain backward compatibility for existing username-based configurations

This addresses JIRA Cloud API changes where usernames are no longer supported
in favor of account IDs for user identification in JQL queries.
- Add UserIDCacheMap with thread-safe caching for username to account ID mappings
- Implement 10-minute cache expiration to balance performance and data freshness
- Add extractAccountIDFromJQL helper function for proper account ID extraction
- Fix Get method to properly clean up expired cache entries
- Add comprehensive test suite with 10 test cases covering:
  * Cache operations (set, get, expiration, cleanup)
  * Account ID extraction from various JQL formats
  * API integration with mock HTTP servers
  * Error handling for various failure scenarios
  * Cache hit/miss performance scenarios
JIRA deprecated the /rest/api/2/search and /rest/api/3/search endpoints,
causing 410 Gone errors. This commit implements a two-step API approach:

1. Use /rest/api/3/search/jql to retrieve issue IDs
2. Fetch full issue details via /rest/api/3/issue/{id} for each result

Key changes:
- Add searchWithNewAPI() method using /rest/api/3/search/jql endpoint
- Add getIssueByID() method for individual issue retrieval
- Implement UserIDCacheMap with thread-safe caching for username->accountID conversion
- Add ConvertJQLWithUsername() for JQL username to account ID conversion via /rest/api/3/jql/pdcleaner
- Improve error handling with detailed API response information
- Set result limit to 20 issues to balance performance and API call limits
- Add graceful error handling to continue processing if individual issues fail

This resolves the widget crashes and restores JIRA integration functionality
while maintaining backward compatibility with existing configurations.

Fixes wtfutil#1855
JIRA deprecated the /rest/api/2/search and /rest/api/3/search endpoints,
causing 410 "Gone" errors. This commit implements a two-step API approach:

1. Use /rest/api/3/search/jql to retrieve issue IDs
2. Fetch full issue details via /rest/api/3/issue/{id} for each result

Key changes:
- Add searchWithNewAPI() method using /rest/api/3/search/jql endpoint
- Add getIssueByID() method for individual issue retrieval
- Implement UserIDCacheMap with thread-safe caching for username->accountID conversion
- Add ConvertJQLWithUsername() for JQL username to account ID conversion via /rest/api/3/jql/pdcleaner
- Improve error handling with detailed API response information
- Set result limit to 20 issues to balance performance and API call limits
- Add graceful error handling to continue processing if individual issues fail
- Fix unit test to handle improved error message format

This resolves the widget crashes and restores JIRA integration functionality
while maintaining backward compatibility with existing configurations.

Fixes wtfutil#1855
@yak3d

yak3d commented Oct 16, 2025

Copy link
Copy Markdown

@FelicianoTech how do we get this merged? would love to have this working again!

@FelicianoTech

Copy link
Copy Markdown
Collaborator

This will make this next release. I’ll get to it very soon.

@FelicianoTech FelicianoTech added this to the v0.47.0 milestone Oct 17, 2025
@FelicianoTech

Copy link
Copy Markdown
Collaborator

@dfoulkes As far as you know, the PR shouldn't require any changes to:

  1. the docs on the website
  2. a user's config

right?

@FelicianoTech

Copy link
Copy Markdown
Collaborator

@yak3d The plan is to have this merged and a new release published within the next 24 hours.

@dfoulkes

Copy link
Copy Markdown
Contributor Author

@FelicianoTech, based on my assessment, the current state appears satisfactory. However, if you require any specific considerations regarding the caching element, please advise. I would like to remind users of this fix that modifications to a user ID will necessitate the cache duration to resolve; however, I assess this scenario as highly specialised, if not entirely improbable.

@FelicianoTech

Copy link
Copy Markdown
Collaborator

This is definitely good enough for now. As this is a bugfix, kind of, I want to prioritize getting this merged. If there's any optimization to be done, we can always do it in a future PR. In the next 6 months I want to start a program where every module in WTF is reviewed for necessity, stability, bugs, security, and possible optimizations. We'll have time to improve, if it's even needed.

This is a pretty sizable PR for an open-source bug fix. Thank you @dfoulkes for taking the time to contribute. I don't use Jira myself but I'm sure people are using it will really appreciate this work.

@FelicianoTech
FelicianoTech merged commit d97a938 into wtfutil:trunk Oct 18, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Jira plugin using deprecated endpoint

3 participants

⌂ 换网址