From b536a68ee18ce347440d69a6a27c35ae19493af0 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Mon, 1 Oct 2018 05:51:24 +0400 Subject: Source code Signed-off-by: Valentin Popov --- src/index.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/index.js (limited to 'src') diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..2ecf583 --- /dev/null +++ b/src/index.js @@ -0,0 +1,41 @@ +/** + * @public + * @param {String} target + * @param {Object} comment + * @description Adding a comment to a template. + */ +function addComment (target = "document", comment = {}) { + const template = $("#template").html(); + const date = new Date(comment.updated_at); + + /* eslint-disable-next-line no-undef */ + const dotted = doT.template(template); + + $(target).append(dotted({ + avatar: comment.user.avatar_url, + content: comment.body_html, + date: date.toDateString(), + url: comment.user.html_url, + user: comment.user.login + })); +} + +/** + * @public + * @param {String} repos + * @param {Number} issue + * @param {Function} callback + * @description Getting a list of comments. + */ +function getComments (repos = "", issue = 0, callback) { + const jqxhr = $.ajax({ + url: `https://api.github.com/repos/${repos}/issues/${issue}/comments`, + headers: { "Accept": "application/vnd.github.v3.html+json" }, + dataType: "json" + }); + + jqxhr.fail((jqXHR, textStatus) => callback(textStatus, null)); + jqxhr.done((data) => callback(null, data)); +} + +export { addComment, getComments }; -- cgit v1.2.3