-
Notifications
You must be signed in to change notification settings - Fork 361
/
Copy pathchangelog.js
53 lines (46 loc) · 1.56 KB
/
changelog.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
const axios = require('axios');
const path = require('path');
const fs = require('fs');
const fm = require('front-matter');
const yaml = require('js-yaml');
API_URL = "https://api.github.com/repos/segmentio/"
const getLog = async (url = "") => {
try {
const res = await axios.get(url, {
headers: {
'Content-Type': 'application/json',
}
});
return res.data
} catch (error) {
console.log(error)
}
}
let libraries = ["analytics-android","analytics-ios", "analytics-react-native", "analytics-node", "analytics-python", "analytics-php", "analytics-go", "analytics-java", "analytics.NET"]
const replace_token = /.+\r\n(-{2,}\r\n)|.+\r\n(={2,}\r\n)/mg;
const subst = ``
const updateLog = async(library) => {
let releasesUpdated = []
let url = API_URL+library+'/releases'
const releases = await getLog(url)
releases.forEach(release => {
let note = release.body
cleaned_note = note.replace(replace_token,subst)
let updatedRelease = {
version: release.name,
url: release.html_url,
date: release.published_at,
notes: cleaned_note
}
releasesUpdated.push(updatedRelease)
})
const options = { noArrayIndent: true };
var todayDate = new Date().toISOString().slice(0,10);
output = "# AUTOGENERATED FROM GITHUB API. DO NOT EDIT\n"
output += "# Releases last updated " + todayDate + " \n";
output += yaml.dump({ releases: releasesUpdated }, options);
fs.writeFileSync(path.resolve(__dirname, `../src/_data/changelogs/${library}.yml`), output);
}
libraries.forEach(library => {
updateLog(library);
});