@@ -67,92 +67,6 @@ private static function getChangedFilesBaseDir()
6767 return __DIR__ . '/.. ' ;
6868 }
6969
70- /**
71- * returns a multi array with the list of modules with corresponding changes as
72- * no. of files changed, insertions and deletions
73- *
74- * @param string $changeCheckDir
75- * @return array
76- * @throws \Magento\Framework\Exception\LocalizedException
77- */
78- public static function getChangedCoreModules (string $ changeCheckDir = '' ): array
79- {
80- $ whitelistFiles = self ::getWhitelist (['php ' , 'graphqls ' ], '' , '' , '/_files/whitelist/graphql.txt ' );
81-
82- $ affectedModules = [];
83- foreach ($ whitelistFiles as $ whitelistFile ) {
84- $ fileName = substr ($ whitelistFile , strlen ($ changeCheckDir ));
85- $ changedModule = explode ('/ ' , $ fileName );
86-
87- $ isGraphQlModule = str_ends_with ($ changedModule [1 ], 'GraphQl ' );
88- $ isGraphQlModuleExists = file_exists ($ changeCheckDir . '/ ' . $ changedModule [1 ] . 'GraphQl ' );
89-
90- if ((!$ isGraphQlModule && $ isGraphQlModuleExists &&
91- (
92- in_array ($ changedModule [2 ], ["Controller " , "Model " , "Block " ]) ||
93- (($ changedModule [2 ] == "Ui " ) && in_array ($ changedModule [3 ], ["Component " , "DataProvider " ]))
94- )
95- ) || ($ isGraphQlModule )) {
96- $ gitDiffUnifiedStat = self ::getGitDiffUnifiedStat ($ whitelistFile );
97- if (isset ($ affectedModules [$ changedModule [1 ]])) {
98- $ affectedModules [$ changedModule [1 ]]['filesChanged ' ] += $ gitDiffUnifiedStat ['filesChanged ' ];
99- $ affectedModules [$ changedModule [1 ]]['insertions ' ] += $ gitDiffUnifiedStat ['insertions ' ];
100- $ affectedModules [$ changedModule [1 ]]['deletions ' ] += $ gitDiffUnifiedStat ['deletions ' ];
101- $ affectedModules [$ changedModule [1 ]]['paramsChanged ' ] += $ gitDiffUnifiedStat ['paramsChanged ' ];
102- } else {
103- $ affectedModules [$ changedModule [1 ]] = $ gitDiffUnifiedStat ;
104- }
105- }
106- }
107- return $ affectedModules ;
108- }
109-
110- /**
111- * Returns the git stats of the file like
112- * insertions, deletions and param change if any
113- *
114- * @param string $filename
115- * @return array
116- * @throws \Magento\Framework\Exception\LocalizedException
117- */
118- private static function getGitDiffUnifiedStat (string $ filename = '' ): array
119- {
120- $ shell = new \Magento \Framework \Shell (
121- new \Magento \Framework \Shell \CommandRenderer ()
122- );
123-
124- $ paramChange = explode (
125- PHP_EOL ,
126- $ shell ->execute ('git diff --stat --unified=0 ' . $ filename )
127- );
128-
129- $ fileStatus = array_values (array_filter ($ paramChange , function ($ value ) {
130- return strpos ($ value , '(+) ' ) || strpos ($ value , '(-) ' );
131- }, ARRAY_FILTER_USE_BOTH ));
132- $ paramChange = array_filter ($ paramChange , function ($ value ) {
133- return ((str_starts_with (trim ($ value ), '+ ' )) ||
134- (str_starts_with (trim ($ value ), '- ' ))) &&
135- (strpos ($ value , '@param ' ));
136- }, ARRAY_FILTER_USE_BOTH );
137-
138- $ insertions = 0 ;
139- $ deletions = 0 ;
140- $ filesChanged = 0 ;
141- if ($ fileStatus ) {
142- $ fileChanges = explode (", " , $ fileStatus [0 ]);
143- $ filesChanged = (isset ($ fileChanges [0 ])) ? intval ($ fileChanges [0 ]) : 0 ;
144- $ insertions = (isset ($ fileChanges [1 ])) ? intval ($ fileChanges [1 ]) : 0 ;
145- $ deletions = (isset ($ fileChanges [2 ])) ? intval ($ fileChanges [2 ]) : 0 ;
146- }
147-
148- return [
149- 'filesChanged ' => $ filesChanged ,
150- 'insertions ' => $ insertions ,
151- 'deletions ' => $ deletions ,
152- 'paramsChanged ' => sizeof ($ paramChange )
153- ];
154- }
155-
15670 /**
15771 * Returns whitelist based on blacklist and git changed files
15872 *
0 commit comments