34
34
35
35
$ fileExtensions = explode (', ' , isset ($ options ['file-extensions ' ]) ? $ options ['file-extensions ' ] : 'php ' );
36
36
37
+ include_once __DIR__ . '/framework/autoload.php ' ;
38
+
37
39
$ mainline = 'mainline_ ' . (string )rand (0 , 9999 );
38
40
$ repo = getRepo ($ options , $ mainline );
39
41
$ branches = $ repo ->getBranches ('--remotes ' );
40
42
generateBranchesList ($ options ['output-file ' ], $ branches , $ options ['branch ' ]);
41
43
$ changes = retrieveChangesAcrossForks ($ mainline , $ repo , $ options ['branch ' ]);
42
44
$ changedFiles = getChangedFiles ($ changes , $ fileExtensions );
43
45
generateChangedFilesList ($ options ['output-file ' ], $ changedFiles );
46
+ saveChangedFileContent ($ repo );
44
47
cleanup ($ repo , $ mainline );
45
48
49
+ /**
50
+ * Save changed file content.
51
+ *
52
+ * @param GitRepo $repo
53
+ * @return void
54
+ */
55
+ function saveChangedFileContent (GitRepo $ repo )
56
+ {
57
+ $ changedFilesContentFileName = BP . Magento \TestFramework \Utility \ChangedFiles::CHANGED_FILES_CONTENT_FILE ;
58
+ foreach ($ repo ->getChangedContentFiles () as $ key => $ changedContentFile ) {
59
+ file_put_contents (sprintf ($ changedFilesContentFileName , $ key ), json_encode ($ changedContentFile ), FILE_APPEND );
60
+ }
61
+ }
62
+
46
63
/**
47
64
* Generates a file containing changed files
48
65
*
@@ -170,6 +187,18 @@ class GitRepo
170
187
*/
171
188
private $ remoteList = [];
172
189
190
+ /**
191
+ * Array of changed content files.
192
+ *
193
+ * Example:
194
+ * 'extension' =>
195
+ * 'path_to_file/filename' => 'Content that was edited',
196
+ * 'path_to_file/filename2' => 'Content that was edited',
197
+ *
198
+ * @var array
199
+ */
200
+ private $ changedContentFiles = [];
201
+
173
202
/**
174
203
* @param string $workTree absolute path to git project
175
204
*/
@@ -285,6 +314,9 @@ protected function filterChangedFiles(array $changes, $remoteAlias, $remoteBranc
285
314
'diff HEAD %s/%s -- %s ' , $ remoteAlias , $ remoteBranch , $ this ->workTree . '/ ' . $ fileName )
286
315
);
287
316
if ($ result ) {
317
+ if (!(isset ($ this ->changedContentFiles [$ fileName ]))) {
318
+ $ this ->setChangedContentFile ($ result , $ fileName );
319
+ }
288
320
$ filteredChanges [] = $ fileName ;
289
321
}
290
322
}
@@ -295,6 +327,38 @@ protected function filterChangedFiles(array $changes, $remoteAlias, $remoteBranc
295
327
return $ filteredChanges ;
296
328
}
297
329
330
+ /**
331
+ * Set changed content for file.
332
+ *
333
+ * @param array $content
334
+ * @param string $fileName
335
+ * @return void
336
+ */
337
+ private function setChangedContentFile (array $ content , $ fileName )
338
+ {
339
+ $ changedContent = '' ;
340
+ $ extension = Magento \TestFramework \Utility \ChangedFiles::getFileExtension ($ fileName );
341
+
342
+ foreach ($ content as $ item ) {
343
+ if (strpos ($ item , '--- ' ) !== 0 && strpos ($ item , '- ' ) === 0 && $ line = ltrim ($ item , '- ' )) {
344
+ $ changedContent .= $ line . "\n" ;
345
+ }
346
+ }
347
+ if ($ changedContent !== '' ) {
348
+ $ this ->changedContentFiles [$ extension ][$ fileName ] = $ changedContent ;
349
+ }
350
+ }
351
+
352
+ /**
353
+ * Get changed content files collection.
354
+ *
355
+ * @return array
356
+ */
357
+ public function getChangedContentFiles ()
358
+ {
359
+ return $ this ->changedContentFiles ;
360
+ }
361
+
298
362
/**
299
363
* Makes call ro git cli
300
364
*
0 commit comments