Skip to content

Issue #116: fix php versions api rate limit. Issue #117: allow theme …#118

Open
gthomas2 wants to merge 2 commits into
mainfrom
issue_116_fix_rate_limit
Open

Issue #116: fix php versions api rate limit. Issue #117: allow theme …#118
gthomas2 wants to merge 2 commits into
mainfrom
issue_116_fix_rate_limit

Conversation

@gthomas2
Copy link
Copy Markdown
Collaborator

…to be configured via config prop

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses two user-facing areas: (1) making PHP version discovery resilient to GitHub API rate limiting, and (2) allowing Moodle’s $CFG->theme to be configured via the recipe config object.

Changes:

  • Add config.theme support to the recipe model and Moodle config.php Twig template.
  • Extend the hard-coded PHP version fallback list and add a rate-limit fallback path when querying GitHub branches.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
templates/moodle/config.php.twig Emits $CFG->theme when config.theme is set.
src/Service/PHPVersions.php Adds 8.5 to fallback versions and returns fallback list when GitHub API rate limit is hit.
src/Model/MoodleConfig.php Adds theme property to the MoodleConfig model.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread templates/moodle/config.php.twig Outdated
Comment on lines 11 to 14
public string $timezone = self::UNSET,
public string $defaultblocks = self::UNSET,
public string $theme = self::UNSET,
public bool $sslproxy = false
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds a new config.theme option, but it isn’t documented alongside the other config properties. Please update the recipe/config documentation (e.g., README config property table) so users know this option exists and what values are expected.

Copilot uses AI. Check for mistakes.
Comment on lines 42 to +57
@@ -50,6 +51,11 @@ public function listVersions(): array {
return $hardCodedVersions;
}

// Handle api rate limit issue.
if (!empty($branches['message']) && strpos($branches['message'], 'API rate limit exceeded') !== false) {
return $hardCodedVersions;
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

listVersions() now has another early-return path (rate limit), but the cURL handle is never closed on any return path. Please ensure curl_close($ch) always runs (e.g., via try/finally) so repeated calls don’t leak resources.

Copilot uses AI. Check for mistakes.
Comment on lines +54 to +57
// Handle api rate limit issue.
if (!empty($branches['message']) && strpos($branches['message'], 'API rate limit exceeded') !== false) {
return $hardCodedVersions;
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rate-limit check handles one specific GitHub error payload, but other API error responses are also JSON objects with a message field (not an array of branches). In those cases, the foreach ($branches as $branch) loop will hit a TypeError (not caught by catch (\Exception)), causing a fatal. Consider validating that $branches is a list of arrays with a name key before iterating, and/or catching \Throwable in the parsing block.

Copilot uses AI. Check for mistakes.
Comment on lines +54 to +57
// Handle api rate limit issue.
if (!empty($branches['message']) && strpos($branches['message'], 'API rate limit exceeded') !== false) {
return $hardCodedVersions;
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds new behavior (fallback to hard-coded versions when the GitHub API rate limit is exceeded), but there’s no unit test coverage asserting the fallback behavior. Since the repo already uses PHPUnit for services, consider adding a test that simulates an API response containing a rate-limit message and verifies listVersions() returns the hard-coded list (likely by extracting the HTTP call behind a mockable method/service).

Copilot uses AI. Check for mistakes.
Comment on lines +83 to +85
{% if (config.theme != UNSET) %}
$CFG->theme = '{{config.theme}}';
{% endif %}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new config.theme field is now supported, but there’s no test asserting it is rendered into the generated Moodle config.php when set. Consider extending the existing MoodleConfigServiceTest to set $recipe->config->theme and assert the resulting config.php contains the expected $CFG->theme line.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants