-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsm-github.js
71 lines (60 loc) · 2.01 KB
/
dsm-github.js
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
{
const yaml = require('js-yaml');
const request = require('es6-request');
const util = require('./util');
const EVENTS_PATH = '_data/events.yml';
const JOBS_PATH = '_data/jobs.yml';
const GROUPS_PATH = '_data/groups.yml';
class Entry {
constructor(ymlRelativePath) {
this.ymlRelativePath = ymlRelativePath;
}
getEntries(commit) {
return new Promise((fulfill, reject) => {
request.get(this._getGithubUrl(process.env.GITHUB_USERNAME, commit, this.ymlRelativePath))
.then((response) => {
fulfill(yaml.safeLoad(response[0]) || []);
});
});
}
getNewEntries(beforeCommit, afterCommit) {
return new Promise((fulfill, reject) => {
Promise.all([
this.getEntries(beforeCommit),
this.getEntries(afterCommit),
]).then((values) => {
const [previousEntries, currentEntries] = values;
const newEntries = currentEntries.filter((currentEntry) =>
!previousEntries.some((previousEntry) => util.objectsAreEqual(previousEntry, currentEntry)));
fulfill(newEntries);
});
});
}
getLatestEntries() {
return this.getEntries('master');
}
_getGithubUrl(username, commit, file) {
return `https://raw.githubusercontent.com/${username}/dsmwebcollective.github.io/${commit}/${file}`;
}
}
class EventEntry extends Entry {
constructor() {
super(EVENTS_PATH);
}
}
class JobEntry extends Entry {
constructor() {
super(JOBS_PATH);
}
}
class GroupEntry extends Entry {
constructor() {
super(GROUPS_PATH);
}
}
module.exports = {
event: new EventEntry(),
job: new JobEntry(),
group: new GroupEntry()
}
}