@@ -184,6 +184,8 @@ public function create(array $options = [
184184 *
185185 * @param string $batchCommand Name of command to run in batch mode (patch or merge, default: patch)
186186 * @param array $options
187+ * @option $repository-column Name of the repository column (fallback: first column in CSV)
188+ * @option $branch-column Name of the branch column (fallback: second column in CSV)
187189 * @option $working-directory Working directory to check out repositories
188190 * @option $patch-source-directory Source directory for all collected patches
189191 * @option $patch-name Name of the directory where the patch code resides
@@ -194,6 +196,8 @@ public function create(array $options = [
194196 * @throws TaskException
195197 */
196198 public function batch (string $ batchCommand , array $ options = [
199+ 'repository-column ' => null ,
200+ 'branch-column ' => null ,
197201 'working-directory|d ' => null ,
198202 'patch-source-directory|s ' => null ,
199203 'patch-name|p ' => 'template ' ,
@@ -209,23 +213,24 @@ public function batch(string $batchCommand, array $options = [
209213 return 1 ;
210214 }
211215
216+ // Parse CSV to array, with keys from header row
212217 $ csvFileContent = file_get_contents ('repositories.csv ' );
213218 $ repositories = str_getcsv ($ csvFileContent , PHP_EOL );
214- array_walk ($ repositories , static function (&$ k ) use ($ repositories ) {
215- $ k = str_getcsv ($ k );
219+ $ header = str_getcsv (array_shift ($ repositories )); // get & remove header
220+ array_walk ($ repositories , static function (&$ k ) use ($ repositories , $ header ) {
221+ $ k = array_combine ($ header , str_getcsv ($ k ));
216222 });
217- array_shift ($ repositories ); // remove column header
218223
219224 if ($ batchCommand === 'patch ' ) {
220225 foreach ($ repositories as $ repository ) {
221226 /** @noinspection DisconnectedForeachInstructionInspection */
222227 chdir ($ workingDirectory ); // reset working directory
223228 $ this ->patch ([
224- 'repository-url ' => $ repository [0 ],
229+ 'repository-url ' => $ repository [$ options [ ' repository-column ' ]] ?? array_values ( $ repository )[ 0 ],
225230 'working-directory ' => $ options ['working-directory ' ],
226231 'patch-source-directory ' => $ options ['patch-source-directory ' ],
227232 'patch-name ' => $ options ['patch-name ' ],
228- 'source-branch ' => $ repository [1 ],
233+ 'source-branch ' => $ repository [$ options [ ' branch-column ' ]] ?? array_values ( $ repository )[ 1 ],
229234 'branch-name ' => $ options ['branch-name ' ],
230235 'halt-before-commit ' => $ options ['halt-before-commit ' ],
231236 ]);
@@ -236,10 +241,10 @@ public function batch(string $batchCommand, array $options = [
236241 /** @noinspection DisconnectedForeachInstructionInspection */
237242 chdir ($ workingDirectory ); // reset working directory
238243 $ this ->merge ([
239- 'repository-url ' => $ repository [0 ],
244+ 'repository-url ' => $ repository [$ options [ ' repository-column ' ]] ?? array_values ( $ repository )[ 0 ],
240245 'working-directory ' => $ options ['working-directory ' ],
241246 'source ' => $ options ['source ' ],
242- 'target ' => $ repository [1 ],
247+ 'target ' => $ repository [$ options [ ' branch-column ' ]] ?? array_values ( $ repository )[ 1 ],
243248 ]);
244249 }
245250 }
0 commit comments