Skip to content

Add support for attaching files to an issue #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
54 changes: 53 additions & 1 deletion lib/jira.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
'pass': this.password
};
}
this.request(options, callback);
return this.request(options, callback);
};

};
Expand Down Expand Up @@ -1022,6 +1022,58 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor

});
};


// ## Add attachment to Jira issue ##
// ### Takes ###
//
// * issueId: the Id of the issue to delete
// * readStream: the readable stream which will be piped out as the attachment
// * callback: for when it's done
//
// ### Returns ###
// * error object (check out the Jira Doc)
// * success object
//
// [Jira Doc](https://docs.atlassian.com/jira/REST/latest/#d2e2894)
this.addAttachment = function(issueNum, readStream, callback) {
var options = {
rejectUnauthorized: this.strictSSL,
uri: this.makeUri('/issue/' + issueNum + '/attachments'),
method: 'POST',
followAllRedirects: true,
headers: { 'X-Atlassian-Token': 'nocheck' },
json: true
};

this.doRequest(options, function(error, response, body) {

if (error) {
callback(error, null);
return;
}

if (response.statusCode === 403) {
callback("Insufficient Permissions");
return;
}

if (response.statusCode === 404) {
callback("Not found");
return;
}

if (response.statusCode !== 200) {
callback(response.statusCode + ': Unable to connect to JIRA during upload.');
return;
}

callback(null, body);

}).form().append('file', readStream);
};



// ## List Components ##
// ### Takes ###
Expand Down