aboutsummaryrefslogtreecommitdiff
path: root/src/modules/releases.js
blob: b041d3833223b2026076294eae58dc89285875ca (plain)
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
88
89
90
91
92
const win = require("../win");
const ipcMain = require("electron").ipcMain;

const requests = require("./requests");

let releases = {
	notes: {},
	latest: {}
}

// returns release notes to renderer
ipcMain.on("get-ns-notes", async () => {
	win().send("ns-notes", await releases.notes.northstar());
})

ipcMain.on("get-vp-notes", async () => {
	win().send("vp-notes", await releases.notes.viper());
})

// gets and returns the release notes of a GitHub repo
async function github_releases(repo) {
	let request = false;

	// attempt to perform the request, while caching it
	try {
		request = JSON.parse(await requests.get(
			"api.github.com", `/repos/${repo}/releases`,
			"release-notes-" + repo
		))
	}catch(err) {
		// request or parsing failed, return `false`
		return false;
	}

	// request is somehow falsy, return `false`
	if (! request) {
		return false;
	}

	// return the actual request as parsed JSON
	return request;
}

// returns release notes for Viper
releases.notes.viper = async () => {
	return await github_releases("0neGal/viper");
}

// returns release notes for Northstar
releases.notes.northstar = async () => {
	return await github_releases("R2Northstar/Northstar");
}

// gets and returns some details of the latest release of a GitHub repo
async function github_latest(repo) {
	let request = false;

	// attempt to perform the request, while caching it
	try {
		request = JSON.parse(await requests.get(
			"api.github.com", `/repos/${repo}/releases/latest`,
			"latest-release-" + repo
		))
	}catch(err) {
		// request or parsing failed, return `false`
		return false;
	}

	// request is somehow falsy, return `false`
	if (! request) {
		return false;
	}

	// return the actual request as parsed JSON
	return {
		notes: request.body,
		version: request.tag_name,
		download_link: request.assets[0].browser_download_url
	}
}

// returns latest release for Viper
releases.latest.viper = async () => {
	return await github_latest("0neGal/viper");
}

// returns latest release for Northstar
releases.latest.northstar = async () => {
	return await github_latest("R2Northstar/Northstar");
}

module.exports = releases;