@@ -48,16 +48,16 @@ public function handle(): array
4848 }
4949
5050 $ tree = $ this ->fetchRepoTree ($ owner , $ repoName , $ defaultBranch , $ token );
51- $ readme = $ this ->fetchReadme ($ owner , $ repoName , $ token );
5251 $ composerJson = $ this ->fetchComposerJson ($ owner , $ repoName , $ token );
5352 $ nativephpJson = $ this ->fetchNativephpJson ($ owner , $ repoName , $ token );
5453
5554 $ checks = [
55+ 'has_license_file ' => $ this ->checkHasLicenseFile ($ tree ),
56+ 'has_release_version ' => false ,
57+ 'release_version ' => null ,
5658 'supports_ios ' => $ this ->checkDirectoryHasFiles ($ tree , 'resources/ios/ ' ),
5759 'supports_android ' => $ this ->checkDirectoryHasFiles ($ tree , 'resources/android/ ' ),
5860 'supports_js ' => $ this ->checkDirectoryHasFiles ($ tree , 'resources/js/ ' ),
59- 'has_support_email ' => false ,
60- 'support_email ' => null ,
6161 'requires_mobile_sdk ' => false ,
6262 'mobile_sdk_constraint ' => null ,
6363 'has_ios_min_version ' => false ,
@@ -66,10 +66,10 @@ public function handle(): array
6666 'android_min_version ' => null ,
6767 ];
6868
69- if ( $ readme ) {
70- $ email = $ this -> extractEmail ( $ readme );
71- $ checks ['has_support_email ' ] = $ email !== null ;
72- $ checks ['support_email ' ] = $ email ;
69+ $ latestTag = $ this -> fetchLatestTag ( $ owner , $ repoName , $ token );
70+ if ( $ latestTag ) {
71+ $ checks ['has_release_version ' ] = true ;
72+ $ checks ['release_version ' ] = $ latestTag ;
7373 }
7474
7575 if ($ composerJson ) {
@@ -151,30 +151,6 @@ protected function fetchRepoTree(string $owner, string $repo, string $branch, ?s
151151 return $ response ->json ('tree ' , []);
152152 }
153153
154- protected function fetchReadme (string $ owner , string $ repo , ?string $ token ): ?string
155- {
156- $ request = Http::timeout (30 );
157-
158- if ($ token ) {
159- $ request = $ request ->withToken ($ token );
160- }
161-
162- $ response = $ request ->get ("https://api.github.com/repos/ {$ owner }/ {$ repo }/readme " );
163-
164- if ($ response ->failed ()) {
165- return null ;
166- }
167-
168- $ content = $ response ->json ('content ' );
169- $ encoding = $ response ->json ('encoding ' );
170-
171- if ($ encoding === 'base64 ' && $ content ) {
172- return base64_decode ($ content );
173- }
174-
175- return null ;
176- }
177-
178154 protected function fetchComposerJson (string $ owner , string $ repo , ?string $ token ): ?array
179155 {
180156 $ request = Http::timeout (30 );
@@ -241,20 +217,50 @@ protected function checkDirectoryHasFiles(array $tree, string $prefix): bool
241217 return false ;
242218 }
243219
244- protected function extractEmail ( string $ content ): ? string
220+ protected function checkHasLicenseFile ( array $ tree ): bool
245221 {
246- $ excludedDomains = ['example.com ' , 'example.org ' , 'example.net ' , 'test.com ' , 'localhost ' ];
222+ $ licenseNames = ['LICENSE ' , 'LICENSE.md ' , 'LICENSE.txt ' , 'license ' , ' license.md ' , 'license.txt ' ];
247223
248- if ( preg_match_all ( ' /[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}/ ' , $ content , $ matches ) ) {
249- foreach ( $ matches [ 0 ] as $ email ) {
250- $ domain = strtolower ( substr ( $ email , strpos ( $ email , ' @ ' ) + 1 )) ;
224+ foreach ( $ tree as $ item ) {
225+ $ path = $ item [ ' path ' ] ?? '' ;
226+ $ type = $ item [ ' type ' ] ?? '' ;
251227
252- if (! in_array ($ domain , $ excludedDomains , true )) {
253- return $ email ;
254- }
228+ if ($ type === 'blob ' && in_array ($ path , $ licenseNames , true )) {
229+ return true ;
255230 }
256231 }
257232
233+ return false ;
234+ }
235+
236+ protected function fetchLatestTag (string $ owner , string $ repo , ?string $ token ): ?string
237+ {
238+ $ request = Http::timeout (10 );
239+
240+ if ($ token ) {
241+ $ request = $ request ->withToken ($ token );
242+ }
243+
244+ $ response = $ request ->get ("https://api.github.com/repos/ {$ owner }/ {$ repo }/releases/latest " );
245+
246+ if ($ response ->successful ()) {
247+ return $ response ->json ('tag_name ' );
248+ }
249+
250+ $ tagsResponse = Http::timeout (10 );
251+
252+ if ($ token ) {
253+ $ tagsResponse = $ tagsResponse ->withToken ($ token );
254+ }
255+
256+ $ tagsResponse = $ tagsResponse ->get ("https://api.github.com/repos/ {$ owner }/ {$ repo }/tags " , [
257+ 'per_page ' => 1 ,
258+ ]);
259+
260+ if ($ tagsResponse ->successful () && count ($ tagsResponse ->json ()) > 0 ) {
261+ return $ tagsResponse ->json ()[0 ]['name ' ];
262+ }
263+
258264 return null ;
259265 }
260266}
0 commit comments