/
tapas_check_for_new_release.m
84 lines (76 loc) · 3.22 KB
/
tapas_check_for_new_release.m
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
function haveNewerRelease = tapas_check_for_new_release(verbose)
%% Check if a new release is available.
%
% Input
% verbose -- Show information on command prompt:
% 0 no information
% 1 only if there is a new release (or not)
% 2 as 1, but if there is a new release also
% the release notes for the lase release
% 3 as 1, but if there is a new release also
% the release notes for all newer
% releases.
%
% Output
% haveNewerRelease -- True if there is a newer release on github
% muellmat@ethz.ch
% copyright (C) 2020
%
if nargin < 1
verbose = 3;
end
[online_version,data] = tapas_check_online_version();
if isempty(online_version) % Could not communicate with server
haveNewerRelease = false;
if verbose
fprintf(1, 'Could not reach github to get current TAPAS version!\n');
end
return;
end
offline_version = tapas_get_current_version();
% both versions are strings in the form '3.3.0'.
haveNewerRelease = tapas_compare_versions(online_version,offline_version);
if verbose % Show info
if ~haveNewerRelease
fprintf(1, 'Your TAPAS version is up-to-date.\n\n');
else
fprintf(1, ['There is a new TAPAS release available (installed %s /'...
+'newest %s)!\n\n'],offline_version,online_version);
if verbose > 1 % Show release notes of the new releases
try % in case the api changed and the structure of the struct is
% different
n_data = numel(data);
fprintf(1, 'Release notes:\n')
if verbose == 2
n_data = 1; % Just iterate once through loop
end
for i_data = 1:n_data
str_version = data(i_data).tag_name;
str_version = strrep(str_version,'v','');
if tapas_compare_versions(str_version,offline_version)
fprintf(1, '===== TAPAS v%s =====\n',str_version)
body = data(i_data).body;
body = tapas_remove_problematic_escape_characters(body);
fprintf(1,body);
fprintf(1,'\n======================\n')
end
end
catch
fprintf(1, ['Cannot print release notes. Maybe the github API'...
' has changed.\n']);
end
end
end
end
end
function str = tapas_remove_problematic_escape_characters(str)
%% Removing problematic escape characters
%
% Input
% str -- String with problematic escape characters
%
% Output
% str -- String without problematic escape characters
% matlab does not like some escape sequences from github
str = strrep(str,'\','');
end