aboutsummaryrefslogtreecommitdiff
path: root/src/index.js
blob: 2ecf583262ba1011d2d21e7d225fefd63899d224 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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 };