From 682b7aaf5327deba52ff400f1ab87ab7c659b2eb Mon Sep 17 00:00:00 2001 From: haosenwang1018 Date: Sun, 12 Apr 2026 04:09:31 +0000 Subject: [PATCH] fix: align jira provider with jira-cli commands --- src/issue-providers/jira-provider.js | 27 ++++++++++++++++++++------- tests/issue-providers.test.js | 8 ++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/issue-providers/jira-provider.js b/src/issue-providers/jira-provider.js index b5de25b6..178adad2 100644 --- a/src/issue-providers/jira-provider.js +++ b/src/issue-providers/jira-provider.js @@ -12,6 +12,14 @@ class JiraProvider extends IssueProvider { static id = 'jira'; static displayName = 'Jira'; + static getAuthCheckCommand() { + return 'jira me'; + } + + static getIssueViewCommand(issueKey) { + return `jira issue view ${issueKey} --raw`; + } + /** * Detect Jira issue keys and URLs * Matches: @@ -71,9 +79,14 @@ class JiraProvider extends IssueProvider { */ static checkAuth() { try { - // go-jira uses 'jira session' to verify authentication - // If not configured, it fails with endpoint/login errors - execSync('jira session', { encoding: 'utf8', stdio: 'pipe', timeout: AUTH_CHECK_TIMEOUT_MS }); + // ankitpokhrel/jira-cli exposes `jira me` for auth verification and is the + // same CLI family used by fetchIssue(). Keep the auth check aligned with + // the actual commands this provider runs. + execSync(JiraProvider.getAuthCheckCommand(), { + encoding: 'utf8', + stdio: 'pipe', + timeout: AUTH_CHECK_TIMEOUT_MS, + }); return { authenticated: true, error: null, recovery: [] }; } catch (err) { const stderr = err.stderr || err.message || ''; @@ -92,8 +105,8 @@ class JiraProvider extends IssueProvider { if (stderr.includes('Command timed out')) { return { authenticated: false, - error: 'jira session timed out', - recovery: ['Retry: jira session', 'Check ~/.jira.d/config.yml for endpoint/login'], + error: 'jira me timed out', + recovery: ['Retry: jira me', 'Check your jira CLI auth/config for endpoint/login'], }; } @@ -111,7 +124,7 @@ class JiraProvider extends IssueProvider { 'Create ~/.jira.d/config.yml with your Jira endpoint', 'See: https://github.com/go-jira/jira#configuration', 'Example config:\n endpoint: https://yourcompany.atlassian.net\n login: your-email@company.com', - 'Then verify: jira session', + 'Then verify: jira me', ], }; } @@ -167,7 +180,7 @@ class JiraProvider extends IssueProvider { const issueKey = this._extractIssueKey(identifier, settings); // Fetch issue using jira CLI - const cmd = `jira issue view ${issueKey} --template json`; + const cmd = JiraProvider.getIssueViewCommand(issueKey); const output = execSync(cmd, { encoding: 'utf8' }); const issue = JSON.parse(output); diff --git a/tests/issue-providers.test.js b/tests/issue-providers.test.js index e8fdf5bb..7d823059 100644 --- a/tests/issue-providers.test.js +++ b/tests/issue-providers.test.js @@ -149,6 +149,14 @@ describe('Jira Provider', () => { expect(tool.name).to.equal('jira'); expect(tool.checkCmd).to.equal('jira version'); }); + + it('uses jira-cli auth command for auth checks', () => { + expect(JiraProvider.getAuthCheckCommand()).to.equal('jira me'); + }); + + it('uses --raw when fetching issue payloads', () => { + expect(JiraProvider.getIssueViewCommand('PROJ-123')).to.equal('jira issue view PROJ-123 --raw'); + }); }); describe('Azure DevOps Provider', () => {