aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2018-10-01 04:51:24 +0300
committerValentin Popov <info@valentineus.link>2018-10-01 04:52:17 +0300
commitb536a68ee18ce347440d69a6a27c35ae19493af0 (patch)
treef7745072c0fa03937ccd894a9b2781c0b020f19d /src
parent28f84df00ff3dba768f6324f5f750cc86356f1e8 (diff)
downloadjs-github-library-b536a68ee18ce347440d69a6a27c35ae19493af0.tar.xz
js-github-library-b536a68ee18ce347440d69a6a27c35ae19493af0.zip
Source code
Signed-off-by: Valentin Popov <info@valentineus.link>
Diffstat (limited to 'src')
-rw-r--r--src/index.js41
1 files changed, 41 insertions, 0 deletions
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 };