1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* check if everything is in plcae for a module |
5
|
|
|
* some quick and dirty methods .... |
6
|
|
|
* |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
class ModuleChecks extends BuildTask |
11
|
|
|
{ |
12
|
|
|
private static $packagist_user_name = ''; |
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* list of methods to run for each module |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
private static $methods_to_check = array( |
|
|
|
|
19
|
|
|
"exitsOnPackagist", |
20
|
|
|
"hasReadMeFile", |
21
|
|
|
"hasLicense", |
22
|
|
|
"hasComposerFile", |
23
|
|
|
"existsOnAddOns", |
24
|
|
|
); |
25
|
|
|
|
26
|
|
|
protected $title = "Check Modules on Github and Packagist"; |
27
|
|
|
|
28
|
|
|
protected $description = "Goes through every module on github and checks for some of the basic requirements. You will need to set your GitHub Username in the configs."; |
29
|
|
|
|
30
|
|
|
public function run($request) |
31
|
|
|
{ |
32
|
|
|
increase_time_limit_to(3600); |
33
|
|
|
|
34
|
|
|
$modules = GitRepoFinder::get_all_repos(); |
35
|
|
|
|
36
|
|
|
$gitUser = Config::inst()->get('GitHubModule', "github_user_name"); |
37
|
|
|
$packagistUser = $this->Config()->get("packagist_user_name"); |
38
|
|
|
|
39
|
|
|
if ($gitUser && $packagistUser) { |
40
|
|
|
//all is good ... |
41
|
|
|
} else { |
42
|
|
|
user_error("make sure to set your git user name ($gitUser) and packagist username ($packagistUser) via the standard config system"); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$count = 0; |
46
|
|
|
echo "<h1>Testing ".count($modules)." modules (git user: $gitUser and packagist user: $packagistUser) ...</h1>"; |
|
|
|
|
47
|
|
|
$methodsToCheck = $this->Config()->get("methods_to_check"); |
48
|
|
|
foreach ($modules as $module) { |
|
|
|
|
49
|
|
|
$count++; |
50
|
|
|
$failures = 0; |
51
|
|
|
echo "<h3><a href=\"https://github.com/".$gitUser."/silverstripe-".$module."\"></a>$count. checking $module</h3>"; |
52
|
|
|
foreach ($methodsToCheck as $method) { |
53
|
|
|
if (!$this->$method($module)) { |
54
|
|
|
$failures++; |
55
|
|
|
DB::alteration_message("bad response for $method", "deleted"); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
if ($failures == 0) { |
59
|
|
|
DB::alteration_message("OK", "created"); |
60
|
|
|
} |
61
|
|
|
echo ' |
62
|
|
|
'; |
63
|
|
|
@ob_flush(); |
|
|
|
|
64
|
|
|
@flush(); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
echo "----------------------------- THE END --------------------------"; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $name |
71
|
|
|
* |
72
|
|
|
* @return boolean |
73
|
|
|
*/ |
74
|
|
|
protected function exitsOnPackagist($name) |
75
|
|
|
{ |
76
|
|
|
return GeneralMethods::check_location("https://packagist.org/packages/".$this->Config()->get("packagist_user_name")."/$name"); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param string $name |
82
|
|
|
* |
83
|
|
|
* @return boolean |
84
|
|
|
*/ |
85
|
|
|
protected function hasLicense($name) |
86
|
|
|
{ |
87
|
|
|
return GeneralMethods::check_location("https://raw.githubusercontent.com/".Config::inst()->get('GitHubModule', 'github_user_name')."/silverstripe-".$name."/master/LICENSE"); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $name |
92
|
|
|
* |
93
|
|
|
* @return boolean |
94
|
|
|
*/ |
95
|
|
|
protected function hasComposerFile($name) |
96
|
|
|
{ |
97
|
|
|
return GeneralMethods::check_location("https://raw.githubusercontent.com/".Config::inst()->get('GitHubModule', 'github_user_name')."/silverstripe-".$name."/master/composer.json"); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param string $name |
102
|
|
|
* |
103
|
|
|
* @return boolean |
104
|
|
|
*/ |
105
|
|
|
protected function hasReadMeFile($name) |
106
|
|
|
{ |
107
|
|
|
return GeneralMethods::check_location("https://raw.githubusercontent.com/".Config::inst()->get('GitHubModule', 'github_user_name')."/silverstripe-".$name."/master/README.md"); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
protected function existsOnAddOns($name) |
111
|
|
|
{ |
112
|
|
|
return GeneralMethods::check_location("http://addons.silverstripe.org/add-ons/".$this->Config()->get("packagist_user_name")."/$name"); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* checks if a particular variable is present in the composer.json file |
118
|
|
|
* |
119
|
|
|
* @param string $name |
120
|
|
|
* @param string $variable |
121
|
|
|
* @return boolean |
122
|
|
|
*/ |
123
|
|
|
protected function checkForDetailsInComposerFile($name, $variable) |
124
|
|
|
{ |
125
|
|
|
die("to be completed"); |
|
|
|
|
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|