@cryptotaxi247 / netdata-1 / commits / df5cd1b3b

GUI Update check - use version instead of commit (#5283)

* GUI Update check - use version instead of commit * changelog link to docs instead of github

Chris Akritidis committed Jan 29, 2019 at 11:33 UTC df5cd1b3bc735d9c1582fb65930ef70551acf4d3
2 files changed +27 -75
web/gui/index.html
-1
@@ -1199,7 +1199,6 @@
1199 </div>
1200 <div class="modal-body">
1201 Your netdata version: <b><code><span id="netdataVersion">Unknown</span></code></b><br/>
1202 - Your netdata commit: <b><code><span id="netdataCommitId">Unknown</span></code></b>
1202 <br/>
1203 <div style="padding: 10px;"></div>
1204 <div id="versionCheckLog">Not checked yet. Please press the Check Now button.</div>
web/gui/main.js
+27 -74
@@ -2819,89 +2819,43 @@ function versionLog(msg) {
2819 document.getElementById('versionCheckLog').innerHTML = msg;
2820 }
2821
2822 -function getNetdataCommitIdFromVersion() {
2823 - var s = options.version.split('-');
2822 +// New way of checking for updates, based only on versions
2823
2825 - if (s.length !== 3) {
2826 - return null;
2827 - }
2828 - if (s[2][0] === 'g') {
2829 - var v = s[2].split('_')[0].substring(1, 8);
2830 - if (v.length === 7) {
2831 - versionLog('Installed git commit id of netdata is ' + v);
2832 - document.getElementById('netdataCommitId').innerHTML = v;
2833 - return v;
2834 - }
2824 +function versionsMatch(v1, v2) {
2825 + if (v1 == v2) {
2826 + return true;
2827 + } else {
2828 + var s1=v1.split('-');
2829 + var s2=v2.split('-');
2830 + if (s1.length !== s2.length) return false;
2831 + if (s1.length === 4) s1.pop();
2832 + if (s2.length === 4) s2.pop();
2833 + return (s1.join('-') === s2.join('-'));
2834 }
2836 - return null;
2837 -}
2838 -
2839 -function getNetdataCommitId(force, callback) {
2840 - versionLog('Downloading installed git commit id from netdata...');
2841 -
2842 - $.ajax({
2843 - url: 'version.txt',
2844 - async: true,
2845 - cache: false,
2846 - xhrFields: {withCredentials: true} // required for the cookie
2847 - })
2848 - .done(function (data) {
2849 - data = data.replace(/(\r\n|\n|\r| |\t)/gm, "");
2850 -
2851 - var c = getNetdataCommitIdFromVersion();
2852 - if (c !== null && data.length === 40 && data.substring(0, 7) !== c) {
2853 - versionLog('Installed files commit id and internal netdata git commit id do not match');
2854 - data = c;
2855 - }
2856 -
2857 - if (data.length >= 7) {
2858 - versionLog('Installed git commit id of netdata is ' + data);
2859 - document.getElementById('netdataCommitId').innerHTML = data.substring(0, 7);
2860 - callback(data);
2861 - }
2862 - })
2863 - .fail(function () {
2864 - versionLog('Failed to download installed git commit id from netdata!');
2865 -
2866 - if (force === true) {
2867 - var c = getNetdataCommitIdFromVersion();
2868 - if (c === null) {
2869 - versionLog('Cannot find the git commit id of netdata.');
2870 - }
2871 - callback(c);
2872 - } else {
2873 - callback(null);
2874 - }
2875 - });
2835 }
2836
2878 -function getGithubLatestCommit(callback) {
2879 - versionLog('Downloading latest git commit id info from github...');
2837 +function getGithubLatestVersion(callback) {
2838 + versionLog('Downloading latest version id from github...');
2839
2840 $.ajax({
2882 - url: 'https://api.github.com/repos/netdata/netdata/commits',
2841 + url: 'https://api.github.com/repositories/10744183/contents/packaging/version?ref=master',
2842 async: true,
2843 cache: false
2844 })
2845 .done(function (data) {
2887 - versionLog('Latest git commit id from github is ' + data[0].sha);
2888 - callback(data[0].sha);
2846 + data = atob(data.content.replace(/(\r\n|\n|\r| |\t)/gm, ""));
2847 + versionLog('Latest version from github is ' + data);
2848 + callback(data);
2849 })
2850 .fail(function () {
2891 - versionLog('Failed to download installed git commit id from github!');
2851 + versionLog('Failed to download the latest version id from github!');
2852 callback(null);
2853 });
2854 }
2855
2896 -function checkForUpdate(force, callback) {
2897 - getNetdataCommitId(force, function (sha1) {
2898 - if (sha1 === null) {
2899 - callback(null, null);
2900 - }
2901 -
2902 - getGithubLatestCommit(function (sha2) {
2903 - callback(sha1, sha2);
2904 - });
2856 +function checkForUpdateByVersion(force, callback) {
2857 + getGithubLatestVersion(function (sha2) {
2858 + callback(options.version, sha2);
2859 });
2860
2861 return null;
@@ -2927,23 +2881,22 @@ function notifyForUpdate(force) {
2881 }
2882 }
2883
2930 - checkForUpdate(force, function (sha1, sha2) {
2884 + checkForUpdateByVersion(force, function (sha1, sha2) {
2885 var save = false;
2886
2887 if (sha1 === null) {
2888 save = false;
2935 - versionLog('<p><big>Failed to get your netdata git commit id!</big></p><p>You can always get the latest netdata from <a href="https://github.com/netdata/netdata" target="_blank">its github page</a>.</p>');
2889 + versionLog('<p><big>Failed to get your netdata version!</big></p><p>You can always get the latest netdata from <a href="https://github.com/netdata/netdata" target="_blank">its github page</a>.</p>');
2890 } else if (sha2 === null) {
2891 save = false;
2938 - versionLog('<p><big>Failed to get the latest git commit id from github.</big></p><p>You can always get the latest netdata from <a href="https://github.com/netdata/netdata" target="_blank">its github page</a>.</p>');
2939 - } else if (sha1 === sha2) {
2892 + versionLog('<p><big>Failed to get the latest netdata version github.</big></p><p>You can always get the latest netdata from <a href="https://github.com/netdata/netdata" target="_blank">its github page</a>.</p>');
2893 + } else if (versionsMatch(sha1, sha2)) {
2894 save = true;
2895 versionLog('<p><big>You already have the latest netdata!</big></p><p>No update yet?<br/>Probably, we need some motivation to keep going on!</p><p>If you haven\'t already, <a href="https://github.com/netdata/netdata" target="_blank">give netdata a <b><i class="fas fa-star"></i></b> at its github page</a>.</p>');
2896 } else {
2897 save = true;
2944 - var compare = 'https://github.com/netdata/netdata/compare/' + sha1.toString() + '...' + sha2.toString();
2945 -
2946 - versionLog('<p><big><strong>New version of netdata available!</strong></big></p><p>Latest commit: <b><code>' + sha2.substring(0, 7).toString() + '</code></b></p><p><a href="' + compare + '" target="_blank">Click here for the changes log</a> since your installed version, and<br/><a href="https://github.com/netdata/netdata/tree/master/packaging/installer/UPDATE.md" target="_blank">click here for directions on updating</a> your netdata installation.</p><p>We suggest to review the changes log for new features you may be interested, or important bug fixes you may need.<br/>Keeping your netdata updated, is generally a good idea.</p>');
2898 + var compare = 'https://docs.netdata.cloud/changelog/';
2899 + versionLog('<p><big><strong>New version of netdata available!</strong></big></p><p>Latest version: <b><code>' + sha2 + '</code></b></p><p><a href="' + compare + '" target="_blank">Click here for the changes log</a> and<br/><a href="https://github.com/netdata/netdata/tree/master/packaging/installer/UPDATE.md" target="_blank">click here for directions on updating</a> your netdata installation.</p><p>We suggest to review the changes log for new features you may be interested, or important bug fixes you may need.<br/>Keeping your netdata updated is generally a good idea.</p>');
2900
2901 document.getElementById('update_badge').innerHTML = '!';
2902 }