Skip to content

Commit

Permalink
#175 Changed to set authorization header only when config params are …
Browse files Browse the repository at this point in the history
…populated to add support for Jira sites that are accessible with no auth.
  • Loading branch information
martan001 committed Jun 8, 2024
1 parent 70efc8f commit 7f5feee
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions lib/core/provider/jira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
JiraPullRequestDetails,
JiraPullRequestsFullDetails,
JiraPullRequestsSummary,
JiraUserEndpoint,
} from '../../types/jiraTypes';

const log = debug('jira');
Expand Down Expand Up @@ -166,20 +165,14 @@ class Jira {
private request(path: string) {
log('request(%o)', path);
const credentials = this.usermail + ':' + this.privateToken;
const header = {
method: 'GET',
headers: {
Authorization: `Basic ${Buffer.from(credentials).toString('base64')}`,
Accept: 'application/json',
},
timeout: this.requestTimeout || 3000,
};
const header = this.createHeader(credentials, 'GET');

const isNonOfficial = path.includes('dev-status');
const requestUrl = isNonOfficial ? this.baseUrl.split(`api/${this.API_VERSION}`)[0] + path : urlJoin(this.baseUrl, path);
return fetch(requestUrl, header).then((response) => {
const successful = response.ok;
if (!successful) {
console.log('different response code: ' + response.status + '\n' + requestUrl);
log('different response code: ' + response.status + '\n' + requestUrl);
return { headers: response.headers, body: [] };
}
return response.json().then((data) => {
Expand All @@ -196,24 +189,31 @@ class Jira {
});
}

private createHeader(credentials: string, methodType: string) {
const myHeader = new Headers();
myHeader.set('Accept', 'application/json');
if (this.usermail && this.privateToken) {
myHeader.set('Authorization', `Basic ${Buffer.from(credentials).toString('base64')}`);
}
return {
method: methodType,
headers: myHeader,
timeout: this.requestTimeout || 3000,
};
}

private requestTeamMembers(path: string) {
log('team(%o)', path);
const credentials = this.usermail + ':' + this.privateToken;
const header = {
method: 'POST',
headers: {
Authorization: `Basic ${Buffer.from(credentials).toString('base64')}`,
Accept: 'application/json',
},
timeout: this.requestTimeout || 3000,
};
const header = this.createHeader(credentials, 'POST');

return fetch(path, header).then((response) => {
const successful = response.ok;

return response.json().then((data) => {
if (!successful) {
log('different response code: ' + response.status + '\n' + data);
return [];
}
return data.results;
});
Expand Down

0 comments on commit 7f5feee

Please sign in to comment.