Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 15 additions & 1 deletion lib/jira-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,26 @@ class JiraClient {
return false;
}

isNonJsonResponse(response) {
const contentType = response.headers?.['content-type'] || '';
if (contentType.includes('text/html')) return true;
if (typeof response.data === 'string') return true;
return false;
}

async requestApi(method, url, dataOrConfig) {
const axiosConfig = this.normalizeAxiosArgs(method, dataOrConfig);
const preferred = this.apiVersion;

try {
return await this.getApiClient(preferred).request({ method, url, ...axiosConfig });
const response = await this.getApiClient(preferred).request({ method, url, ...axiosConfig });
if (this.apiVersionMode === 'auto' && this.isNonJsonResponse(response)) {
const fallbackVersion = preferred === 3 ? 2 : 3;
const fallbackResponse = await this.getApiClient(fallbackVersion).request({ method, url, ...axiosConfig });
this.apiVersion = fallbackVersion;
return fallbackResponse;
}
return response;
} catch (error) {
if (this.apiVersionMode !== 'auto' || !this.shouldFallbackApiVersion(error)) throw error;

Expand Down
6 changes: 6 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ function createSprintsTable(sprints) {

// Format issue as markdown
function formatIssueAsMarkdown(issue) {
if (!issue || !issue.fields) {
throw new Error('Unexpected API response: issue fields missing. Try setting API version with: jira config --api-version 2');
}
const lines = [];

lines.push(`# ${issue.key}: ${issue.fields.summary}`);
Expand Down Expand Up @@ -144,6 +147,9 @@ function formatIssueAsMarkdown(issue) {

// Display issue details
function displayIssueDetails(issue) {
if (!issue || !issue.fields) {
throw new Error('Unexpected API response: issue fields missing. Try setting API version with: jira config --api-version 2');
}
console.log(chalk.bold(`\n${issue.key}: ${issue.fields.summary}`));
console.log(chalk.gray('─'.repeat(60)));

Expand Down
95 changes: 49 additions & 46 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading