├── LICENSE
├── MMM-GitHub-Monitor.css
├── MMM-GitHub-Monitor.js
├── README.md
└── screenshot.png
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 fpfuetsch
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/MMM-GitHub-Monitor.css:
--------------------------------------------------------------------------------
1 | .gh-monitor td:not(:last-child) {
2 | padding-right: 1em;
3 | }
4 |
5 | .gh-monitor td {
6 | white-space: nowrap;
7 | }
--------------------------------------------------------------------------------
/MMM-GitHub-Monitor.js:
--------------------------------------------------------------------------------
1 | Module.register('MMM-GitHub-Monitor', {
2 | defaults: {
3 | updateInterval: 1000 * 60 * 10,
4 | renderInterval: 1000 * 5,
5 | maxPullRequestTitleLength: 100,
6 | repositories: [
7 | {
8 | owner: 'fpfuetsch',
9 | name: 'MMM-GitHub-Monitor',
10 | pulls: {
11 | display: true,
12 | loadCount: 10,
13 | displayCount: 2,
14 | state: 'open',
15 | head: '',
16 | base: 'main',
17 | sort: 'created',
18 | direction: 'desc',
19 | }
20 | },
21 | ],
22 | sort: true,
23 | baseURL: 'https://api.github.com',
24 | },
25 |
26 | getStyles: function () {
27 | return [
28 | this.file('MMM-GitHub-Monitor.css'),
29 | 'font-awesome.css'
30 | ];
31 | },
32 |
33 | start: function () {
34 | Log.log('Starting module: ' + this.name);
35 | this.initState();
36 | this.updateCycle();
37 | setInterval(this.updateCycle, this.config.updateInterval);
38 | setInterval(() => this.updateDom(), this.config.renderInterval);
39 | },
40 |
41 | initState: function () {
42 | this.state = [];
43 | for (let id = 0; id < this.config.repositories.length; id++) {
44 | this.state[id] = 0;
45 | }
46 | },
47 |
48 | updateCycle: async function () {
49 | this.ghData = [];
50 | await this.updateData();
51 | this.updateDom();
52 | },
53 |
54 | updateData: async function () {
55 | for (let id = 0; id < this.config.repositories.length; id++) {
56 | const repo = this.config.repositories[id];
57 | const resBase = await fetch(`${this.config.baseURL}/repos/${repo.owner}/${repo.name}`)
58 | if (resBase.ok) {
59 | const jsonBase = await resBase.json();
60 | const repoData = {
61 | id: id,
62 | title: `${repo.owner}/${repo.name}`,
63 | stars: jsonBase.stargazers_count,
64 | forks: jsonBase.forks_count,
65 | }
66 |
67 | if (repo.pulls && repo.pulls.display) {
68 | const pullsConfig = {
69 | state: repo.pulls.state || 'open',
70 | head: repo.pulls.head,
71 | base: repo.pulls.base,
72 | sort: repo.pulls.sort || 'created',
73 | direction: repo.pulls.direction || 'desc',
74 | }
75 | let params = [];
76 | Object.keys(pullsConfig).forEach(key => {
77 | if (pullsConfig[key]) {
78 | params.push(`${key}=${pullsConfig[key]}`)
79 | }
80 | });
81 | const resPulls = await fetch(`${this.config.baseURL}/repos/${repo.owner}/${repo.name}/pulls?${params.join('&')}`)
82 | if (resPulls.ok) {
83 | let jsonPulls = await resPulls.json();
84 | if (repo.pulls.loadCount) {
85 | jsonPulls = jsonPulls.slice(0, repo.pulls.loadCount);
86 | }
87 | if (this.config.maxPullRequestTitleLength) {
88 | jsonPulls.forEach(pull => {
89 | if (pull.title.length > this.config.maxPullRequestTitleLength) {
90 | pull.title = pull.title.substr(0, this.config.maxPullRequestTitleLength) + '...';
91 | }
92 | })
93 | }
94 | repoData.step = Math.min(repo.pulls.displayCount, jsonPulls.length);
95 | repoData.pulls = jsonPulls;
96 | }
97 | }
98 | this.ghData.push(repoData)
99 | }
100 | }
101 | if (this.config.sort) {
102 | this.ghData.sort((r1, r2) => r1.title.localeCompare(r2.title));
103 | }
104 | },
105 |
106 | getDom: function () {
107 | let table = document.createElement('table');
108 | table.classList.add('gh-monitor');
109 |
110 | this.ghData.forEach((repo) => {
111 | let basicRow = document.createElement('tr');
112 | basicRow.style.fontWeight = 'bold';
113 | basicRow.style.paddingBottom = '0.5em';
114 |
115 | let title = document.createElement('td');
116 | title.innerText = repo.title;
117 |
118 | let stars = document.createElement('td');
119 | stars.innerHTML = ` ${repo.stars}`;
120 | stars.style.textAlign = 'left';
121 |
122 | let forks = document.createElement('td');
123 | forks.innerHTML = ` ${repo.forks}`;
124 | forks.style.textAlign = 'left';
125 |
126 | basicRow.append(title);
127 | basicRow.append(stars);
128 | basicRow.append(forks)
129 | table.append(basicRow);
130 |
131 | if (repo.pulls) {
132 | const displayedPulls = [];
133 | for (let i = 0; i < repo.step; i++) {
134 | if (this.state[repo.id] + 1 < repo.pulls.length) {
135 | displayedPulls.push(repo.pulls[this.state[repo.id] + 1])
136 | this.state[repo.id]++;
137 | } else {
138 | displayedPulls.push(repo.pulls[0])
139 | this.state[repo.id] = 0;
140 | }
141 | }
142 | displayedPulls.forEach(pull => {
143 | const pullRow = document.createElement('tr');
144 | const pullEntry = document.createElement('td');
145 | pullEntry.style.paddingLeft = '1em';
146 | pullEntry.colSpan = 3;
147 | pullEntry.innerText = `#${pull.number} ${pull.title}`;
148 | pullRow.append(pullEntry);
149 | table.append(pullRow);
150 | });
151 | }
152 | })
153 | return table;
154 | }
155 | });
156 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MagicMirror² Module - GitHub Monitor
2 | ## What?
3 | This module enables you to display certain information about your favourite GitHub Repositories on your MagicMirror² Mirror.
4 |
5 | 
6 |
7 | ## How?
8 | ### Installation
9 | 1. Navigate to the `/modules` folder of you MagicMirror²
10 | 2. Clone this repository using the following command: `git clone https://github.com/fpfuetsch/MMM-GitHub-Monitor.git`
11 | ### Configuration
12 | To use this module, add it to the modules array in the `config/config.js` file:
13 | ```javascript
14 | modules: [
15 | {
16 | module: 'MMM-GitHub-Monitor',
17 | position: 'top_left', // any possible region
18 | config: {
19 | repositories: [ // list of GitHub repositories to monitor
20 | {
21 | owner: 'MichMich', // reposistory owner
22 | name: 'MagicMirror', // repository name
23 | pulls: {
24 | display: true, // show recent pull requests
25 | loadCount: 10, // cycle through 10 latest pull requests
26 | displayCount: 2, // show 2 pull requests at a time
27 | state: 'open', // show only open pull requests
28 | sort: 'created', // sort by creation date
29 | direction: 'desc', // sort in descending order
30 | }
31 | },
32 | {
33 | owner: 'fpfuetsch',
34 | name: 'MMM-GitHub-Monitor',
35 | },
36 | ],
37 | sort: true, // sort repositories alphabetically (default: true)
38 | updateInterval: 10000, // update interval in milliseconds (default: 10 min)
39 | baseURL: 'https://YOUR_GITHUB_URL/api/v3', // Optional for non-public githubs
40 | },
41 | },
42 | ]
43 | ```
44 | ### Update
45 | Navigate to the folder of the module in the `/modules` folder and get the latest version using the command `git pull`.
46 |
--------------------------------------------------------------------------------
/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fpfuetsch/MMM-GitHub-Monitor/61c5c615b39fcbf07e205343a9adacc27b6871d8/screenshot.png
--------------------------------------------------------------------------------