Skip to content

Commit ac11443

Browse files
committed
Merge branch 'json'
This branch cherry-picks a couple of improvements from git-for-windows#12, adding proper commit messages, and leaving the support for static URLs to the original author (if still needed, given the suggestions to use the GitHub API directly). Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 1b50d21 + 057785c commit ac11443

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

bump-version.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,26 @@ var autoUpdate = function() {
4747
};
4848

4949
var determineVersion = function(body) {
50-
var lines = body.replace(/\n/gm, ',').split(',');
51-
var tagName = lines.findFirst(/"tag_name": *"(.*)"/);
52-
var regex = /^v(\d+\.\d+\.\d+(\.\d+)?)\.windows\.(\d+)$/;
53-
var match = regex.exec(tagName);
54-
var version = match[1];
55-
if (parseInt(match[3]) > 1)
56-
version += '(' + match[3] + ')';
57-
var timestamp = lines.findFirst(/"published_at": *"(.*)"/);
58-
regex = /^(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)Z$/;
59-
match = regex.exec(timestamp);
60-
var latest = new Date(match[1], match[2] - 1, match[3],
61-
match[4], match[5], match[6], 0).toUTCString();
62-
latest = latest.replace(/GMT$/, 'UTC');
63-
var url = lines.findFirst(/"html_url": *"(.*)"/);
50+
var release = JSON.parse(body),
51+
versionRegex = /^v(\d+\.\d+\.\d+(\.\d+)?)\.windows\.(\d+)/,
52+
timeRegex = /^(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)Z$/,
53+
version = false,
54+
match, latest, url;
55+
56+
if (match = release.tag_name.match(versionRegex)) {
57+
version = match[1];
58+
59+
if (parseInt(match[3]) > 1) {
60+
version += '(' + match[3] + ')';
61+
}
62+
63+
match = release.published_at.match(timeRegex);
64+
latest = new Date(match[1], match[2] - 1, match[3],
65+
match[4], match[5], match[6], 0).toUTCString();
66+
latest = latest.replace(/GMT$/, 'UTC');
67+
url = release.html_url;
68+
}
69+
6470
process.stderr.write('Auto-detected version ' + version
6571
+ ' (' + latest + ')\n');
6672
return [ version, latest, url ];
@@ -70,7 +76,7 @@ var autoUpdate = function() {
7076
https.body = '';
7177
https.get({
7278
'hostname': 'api.github.com',
73-
'path': '/repos/git-for-windows/git/releases',
79+
'path': '/repos/git-for-windows/git/releases/latest',
7480
'headers': {
7581
'User-Agent': 'Git for Windows version updater'
7682
}
@@ -94,4 +100,3 @@ else if (process.argv.length == 5)
94100
else
95101
die('Usage: node ' + process.argv[1]
96102
+ ' <version> <timestamp> <url>\n');
97-

0 commit comments

Comments
 (0)