Skip to content

Commit 7c49815

Browse files
committed
Refactor handling of github actions in CLI
1 parent 921c68c commit 7c49815

File tree

3 files changed

+77
-40
lines changed

3 files changed

+77
-40
lines changed

console/create.php

Lines changed: 70 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -159,53 +159,31 @@ protected function get_component_data()
159159
$components = $this->packager->get_component_dialog_values();
160160
foreach ($components as $component => $details)
161161
{
162-
foreach ($details['dependencies'] as $depends)
162+
// Skip early as it's handled elsewhere
163+
if ($component === 'githubactions_deprecated')
163164
{
164-
if (empty($this->data['components'][$depends]))
165-
{
166-
$this->data['components'][$component] = false;
167-
continue 2;
168-
}
165+
continue;
169166
}
170167

171-
// Special logic for GitHub Actions options
172-
if ($component === 'githubactions')
168+
// Check dependencies
169+
if (!$this->check_dependencies($details['dependencies']))
173170
{
174-
$question = $this->language->lang('SKELETON_QUESTION_COMPONENT_GITHUBACTIONS') . $this->language->lang('COLON');
175-
$choices = [
176-
$this->language->lang('SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_0'),
177-
$this->language->lang('SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_1'),
178-
$this->language->lang('SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_2'),
179-
];
180-
181-
$question = new ChoiceQuestion($question, $choices, 0);
182-
183-
$choice = $this->helper->ask($this->input, $this->output, $question);
184-
$index = array_search($choice, $choices, true);
185-
186-
$this->data['components']['githubactions'] = false;
187-
$this->data['components']['githubactions_deprecated'] = false;
188-
189-
if ($index === 1)
190-
{
191-
$this->data['components']['githubactions'] = true;
192-
}
193-
else if ($index === 2)
194-
{
195-
$this->data['components']['githubactions_deprecated'] = true;
196-
}
197-
171+
$this->data['components'][$component] = false;
198172
continue;
199173
}
200174

201-
if ($component === 'githubactions_deprecated')
175+
// Handle GitHub Actions
176+
if ($component === 'githubactions')
202177
{
203-
// Already handled via githubactions logic
178+
$this->handle_github_actions();
204179
continue;
205180
}
206181

207182
// Default logic for all other components
208-
$this->data['components'][$component] = $this->get_user_input('component_' . $component, $details['default']);
183+
$this->data['components'][$component] = $this->get_user_input(
184+
'component_' . $component,
185+
$details['default']
186+
);
209187
}
210188
}
211189

@@ -239,4 +217,61 @@ protected function get_user_input($value, $default)
239217

240218
return $return_value;
241219
}
220+
221+
/**
222+
* Check if all dependencies are satisfied
223+
*
224+
* @param array $dependencies List of dependencies to check
225+
* @return bool
226+
*/
227+
private function check_dependencies(array $dependencies): bool
228+
{
229+
foreach ($dependencies as $depends)
230+
{
231+
if (empty($this->data['components'][$depends]))
232+
{
233+
return false;
234+
}
235+
}
236+
return true;
237+
}
238+
239+
/**
240+
* Handle GitHub Actions specific logic
241+
*/
242+
private function handle_github_actions(): void
243+
{
244+
$question = $this->language->lang('SKELETON_QUESTION_COMPONENT_GITHUBACTIONS') . $this->language->lang('COLON');
245+
$choices = [
246+
$this->language->lang('SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_CLI', 0),
247+
$this->language->lang('SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_CLI', 1),
248+
$this->language->lang('SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_CLI', 2),
249+
];
250+
251+
$question = new ChoiceQuestion($question, $choices, 0);
252+
253+
$choice = $this->helper->ask($this->input, $this->output, $question);
254+
$index = array_search($choice, $choices, true);
255+
256+
$this->data['components']['githubactions'] = false;
257+
$this->data['components']['githubactions_deprecated'] = false;
258+
259+
// Initialize both flags to false
260+
$this->data['components'] = array_merge(
261+
$this->data['components'],
262+
[
263+
'githubactions' => false,
264+
'githubactions_deprecated' => false
265+
]
266+
);
267+
268+
if ($index === 1)
269+
{
270+
$this->data['components']['githubactions'] = true;
271+
}
272+
else if ($index === 2)
273+
{
274+
$this->data['components']['githubactions_deprecated'] = true;
275+
}
276+
}
242277
}

language/en/common.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,12 @@
120120
'SKELETON_QUESTION_COMPONENT_TESTS' => 'Create sample PHPUnit tests',
121121
'SKELETON_QUESTION_COMPONENT_TESTS_UI' => 'Tests (PHPUnit)',
122122
'SKELETON_QUESTION_COMPONENT_TESTS_EXPLAIN' => 'Unit tests can test an extension to verify that specific portions of its source code work properly. This helps ensure basic code integrity and prevents regressions as an extension is being developed and debugged.',
123-
'SKELETON_QUESTION_COMPONENT_GITHUBACTIONS' => 'Create a GitHub Actions workflow to run tests in your repository',
124-
'SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_0' => 'No (Default)',
125-
'SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_1' => 'Reusable (Recommended – uses phpBB’s maintained workflow)',
126-
'SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_2' => 'Standalone (Deprecated – overrides reusable workflow)',
123+
'SKELETON_QUESTION_COMPONENT_GITHUBACTIONS' => 'Create a GitHub Actions workflow',
124+
'SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_CLI' => [
125+
0 => 'No (Default)',
126+
1 => 'Reusable (Recommended – uses phpBB’s maintained workflow)',
127+
2 => 'Standalone (Deprecated - customise and maintain your own workflow)',
128+
],
127129
'SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_UI' => 'GitHub Actions Workflow (Reusable – Recommended)',
128130
'SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_EXPLAIN' => 'Creates a GitHub Actions workflow that uses a reusable, phpBB-maintained framework to run PHPUnit tests on your repository. The workflow file is saved in .github/workflows and runs automatically on each commit and pull request.',
129131
'SKELETON_QUESTION_COMPONENT_GITHUBACTIONS_DEPRECATED' => 'Create a standalone GitHub Actions workflow [Deprecated: not recommended unless you plan to modify jobs or steps]',

tests/console/create_test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public function get_questions()
184184
// 'SKELETON_QUESTION_COMPONENT_NOTIFICATION' => 'y',
185185
// 'SKELETON_QUESTION_COMPONENT_PERMISSIONS' => 'y',
186186
'SKELETON_QUESTION_COMPONENT_TESTS' => 'y',
187-
'SKELETON_QUESTION_COMPONENT_GITHUBACTIONS' => 'y',
187+
'SKELETON_QUESTION_COMPONENT_GITHUBACTIONS' => 2,
188188
// 'SKELETON_QUESTION_COMPONENT_BUILD' => 'y',
189189
];
190190
}

0 commit comments

Comments
 (0)