aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 0c5efecec84b61dbb9030372f98921cf624704b7 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# GitHub Library

A small library for personal use.

* Build the package:

```bash
npm run-script build
```

* Testing the package:

```bash
npm run-script test
```

## API

### Github.addComment( target, comment ) ⇒ `Undefined`

| Param     | Type      | Default       | Description       |
| --------- | --------- | ------------- | ----------------- |
| `target`  | `String`  | `document`    | Selector object   |
| `comment` | `Object`  |               | Comment data      |

Adding a comment to a template.

Example:

```javascript
window.addEventListener("load", function () {
  Github.getComments("octocat/Hello-World", 1,
    function (error, comments) {
      if (error) { throw new Error(error); }
      // code
    });
});
```

### Github.getComments( repos, issue, callback ) ⇒ `Array`

| Param         | Type          | Default   | Description       |
| ------------- | ------------- | --------- | ----------------- |
| `repos`       | `String`      |           | Repository name   |
| `issue`       | `Number`      |           | Issue number      |
| `callback`    | `Function`    |           | Function handler  |

Getting a list of comments.

Example:

```html
<!-- Template -->
<script type="text/html" id="template">
  <div class="panel panel-default">
    <!-- Title -->
    <div class="panel-heading">
      <img class="github-avatar img-rounded" src="{{= it.avatar }}">
      <a href="{{= it.url }}"><strong>{{= it.user }}</strong></a>
      <span>commented on {{= it.date }}</span>
    </div>
    <!-- Content -->
    <div class="panel-body">{{= it.content }}</div>
  </div>
</script>

<!-- Script loading comments -->
<script defer type="text/javascript">
  window.addEventListener("load", function () {
    Github.getComments("octocat/Hello-World", 1,
      function (error, comments) {
        if (error) { throw new Error(error); }
        comments.forEach(function (comment) {
          Github.addComment("#comments", comment);
        });
      });
  });
</script>
```

## License

<img width="256px" alt="MIT License" src="https://raw.githubusercontent.com/valentineus/valentineus.github.io/master/assets/images/7d05cad0-d553-42c7-be1f-7007926ba720.png" />

[MIT](LICENSE.txt).
Copyright (c)
[Valentin Popov](https://valentineus.link/).