Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Commit

Permalink
Fix some issues with API paths and fix attachment uploading (#169)
Browse files Browse the repository at this point in the history
* fix pathes for api

* allow to pass string as filename for this.addAttachment

* add X-Atlassian-Token nocheck for attachment upload

* add missing ")"
  • Loading branch information
7rulnik authored and MrRefactoring committed Jun 30, 2019
1 parent b294f7e commit a1eacca
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions api/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ function IssueClient(jiraClient) {
*/
this.addWorkLog = function (opts, callback) {
var options = {
uri: this.jiraClient.buildURL('issue/' + opts.issueId || opts.issueKey + '/worklog'),
uri: this.jiraClient.buildURL('/issue/' + (opts.issueId || opts.issueKey) + '/worklog'),
method: 'POST',
json: true,
followAllRedirects: true,
Expand Down Expand Up @@ -926,7 +926,7 @@ function IssueClient(jiraClient) {
*/
this.getWorkLog = function (opts, callback) {
var options = {
uri: this.jiraClient.buildURL('issue/' + opts.issueId || opts.issueKey + '/worklog/' + opts.id || opts.worklogId),
uri: this.jiraClient.buildURL('/issue/' + (opts.issueId || opts.issueKey) + '/worklog/' + (opts.id || opts.worklogId)),
method: 'GET',
json: true,
followAllRedirects: true,
Expand Down Expand Up @@ -962,7 +962,7 @@ function IssueClient(jiraClient) {
*/
this.updateWorkLog = function (opts, callback) {
var options = {
uri: this.jiraClient.buildURL('issue/' + opts.issueId || opts.issueKey + '/worklog/' + opts.id || opts.worklogId),
uri: this.jiraClient.buildURL('/issue/' + (opts.issueId || opts.issueKey) + '/worklog/' + (opts.id || opts.worklogId)),
method: 'PUT',
json: true,
followAllRedirects: true,
Expand Down Expand Up @@ -1013,7 +1013,7 @@ function IssueClient(jiraClient) {
*/
this.deleteWorkLog = function (opts, callback) {
var options = {
uri: this.jiraClient.buildURL('issue/' + opts.issueId || opts.issueKey + '/worklog/' + opts.id || opts.worklogId),
uri: this.jiraClient.buildURL('/issue/' + (opts.issueId || opts.issueKey) + '/worklog/' + (opts.id || opts.worklogId)),
method: 'DELETE',
json: true,
followAllRedirects: true,
Expand Down Expand Up @@ -1044,7 +1044,8 @@ function IssueClient(jiraClient) {
* @return {Promise} Resolved when the attachment has been attached.
*/
this.addAttachment = function (opts, callback) {
var attachments = opts.filename.map(function (filePath) {
var filename = Array.isArray(opts.filename) ? opts.filename : [opts.filename];
var attachments = filename.map(function (filePath) {
var filename = filePath.split('/').reverse()[0];
var mimeType = mime.lookup(filename);
return {
Expand All @@ -1056,12 +1057,17 @@ function IssueClient(jiraClient) {
}
});

var headers = {
charset: 'utf-8',
'X-Atlassian-Token': 'nocheck'
}

var options = {
uri: this.jiraClient.buildURL('issue/' + opts.issueId || opts.issueKey + '/attachments'),
uri: this.jiraClient.buildURL('/issue/' + (opts.issueId || opts.issueKey) + '/attachments'),
method: 'POST',
json: true,
followAllRedirects: true,
headers: Object.assign({ charset: 'utf-8' }, opts.headers || {}),
headers: Object.assign(headers, opts.headers || {}),
formData: {
file: attachments
}
Expand Down

0 comments on commit a1eacca

Please sign in to comment.