-
Notifications
You must be signed in to change notification settings - Fork 34
/
contribute.m
executable file
·178 lines (150 loc) · 6.36 KB
/
contribute.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
function contribute(repoName, printLevel, autoOption)
% devTools
%
% INPUT:
%
% repoName: Name of the repository (default: opencobra/cobratoolbox)
% printLevel: 0: minimal printout (default)
% 1: detailed printout (debug mode)
% autoOption: menu option
% 1. Start a new branch:
% 2. Select an existing branch to work on.
% 3. Publish a branch.
% 4. Delete a branch.
% 5. Update the fork
%
% EXAMPLES:
% contribute('opencobra/cobratoolbox')
% contribute('opencobra/COBRA.tutorials')
global gitConf
global gitCmd
global resetDevToolsFlag
global DEFAULTREPONAME
resetDevToolsFlag = true;
% retrieve the current directory
currentDir = pwd;
% adding the src folder of the devTools
addpath(genpath(fileparts(which(mfilename))));
% check the automatic option argument
autoOptionFlag = false;
if exist('autoOption', 'var')
if ~isempty(autoOption) && autoOption > 0 && autoOption < 6
autoOptionFlag = true;
else
error('Please enter an automatic menu option between 1 and 5.')
end
end
% treatment of input arguments
if ~exist('repoName', 'var') || isempty(repoName)
DEFAULTREPONAME = 'opencobra/cobratoolbox'; % set the default repository
repoName = DEFAULTREPONAME;
end
% soft reset if the repository name is different
if ~isempty(gitConf) && exist('repoName', 'var') && isfield(gitConf, 'remoteUserName') && isfield(gitConf, 'remoteRepoName')
if ~strcmpi(repoName, [gitConf.remoteUserName '/' gitConf.remoteRepoName])
resetDevTools();
end
end
% check the system and set the configuration
if exist('printLevel', 'var')
checkSystem(mfilename, repoName, printLevel);
else
checkSystem(mfilename, repoName);
end
% perform a soft reset if interrupted
finishup = onCleanup(@() resetDevTools());
% determine the directory of the devTools
devToolsDir = fileparts(which(mfilename));
% change to the directory of the devTools
cd(devToolsDir);
% update the devTools
updateDevTools();
% print the launcher
fprintf(gitConf.launcher);
% show the menu to select an option
if autoOptionFlag
choice = autoOption;
else
choice = input('\n (You can abort any process using CTRL+C)\n\n [1] Start a new branch.\n [2] Select an existing branch to work on.\n [3] Publish a branch.\n [4] Delete a branch.\n [5] Update the fork.\n\n -> Please select what you want to do (enter the number): ', 's');
choice = str2num(choice);
end
% evaluate the option
if length(choice) == 0 || choice > 5 || choice < 0
error('Please enter a number between 1 and 5.')
else
if ~isempty(choice) && length(choice) > 0
% ask for a name of the branch
if choice == 1
% list the available branches if the fork is already configured
if exist('gitConf.fullForkDir', 'var')
%list all available branches
listBranches();
end
% define a name of an example branch
exampleBranch = gitConf.exampleBranch;
reply = '';
while isempty(reply)
reply = input([' -> Please enter a name of the new branch that you want to work on (example: ', exampleBranch, '): '], 's');
if ~isempty(strfind(reply, 'develop')) || ~isempty(strfind(reply, 'master'))
reply = '';
fprintf([gitCmd.lead, 'Please use a different name that does not contain <develop> or <master>.', gitCmd.fail, gitCmd.trail]);
end
end
exitFlag = false;
else
% initialize the development tools
initDevTools(repoName,currentDir);
% change to the fork diretory
cd(gitConf.fullForkDir);
%list all available branches
[exitFlag, currentBranch, ~, exampleBranch] = listBranches();
if ~strcmpi('develop', currentBranch) && ~strcmpi('master', currentBranch)
exampleBranch = currentBranch;
end
if ~exitFlag
reply = '';
if choice == 2
while isempty(reply) && ~exitFlag
reply = input([' -> Please enter the name of the existing branch that you want to work on (example: ', exampleBranch, '): '], 's');
end
elseif choice == 3
while isempty(reply)
reply = input([' -> Please enter the name of the branch that you want to publish (example: ', exampleBranch, '): '], 's');
end
elseif choice == 4
% list the available branches if the fork is already configured
if exist('gitConf.fullForkDir', 'var')
%list all available branches
listBranches();
end
while isempty(reply)
reply = input([' -> Please enter the name of the branch that you want to delete (example: ', exampleBranch, '): '], 's');
end
end
end
end
if ~exitFlag
if choice == 1 || choice == 2
% call initContribution
if isempty(reply)
initContribution;
else
initContribution(strtrim(reply));
end
elseif choice == 3
% call submitContribution
submitContribution(reply);
elseif choice == 4
% call deleteContribution
deleteContribution(reply);
elseif choice == 5
% call updateFork
updateFork();
end
end
end
end
resetDevToolsFlag = false;
% change back to the current directory
cd(currentDir);
end