Skip to content

Modernize codebase for PHP 8.5+ and fix five known bugs - #20

Open
tecpromotion wants to merge 3 commits into
joomlagerman:masterfrom
tecpromotion:refactor-php-85
Open

Modernize codebase for PHP 8.5+ and fix five known bugs#20
tecpromotion wants to merge 3 commits into
joomlagerman:masterfrom
tecpromotion:refactor-php-85

Conversation

@tecpromotion

Copy link
Copy Markdown
Member

Summary

Modernizes the bot to run on PHP 8.5+ idiomatically, bumps the Joomla framework dependencies from ^1/~1 to ^4, fixes five long-standing bugs, and introduces a small tooling stack (PHPStan max, PHP-CS-Fixer, PHPUnit). The architecture stays the same: CLI entry point + helpers, configured via includes/constants.php.

Verified end-to-end on a production-equivalent server running PHP 8.5.5 — both the once-a-day guard path and the full GitHub-API-fetch path execute cleanly.

⚠ Breaking Changes

  1. PHP 8.5+ required (composer.json platform constraint).
  2. vendor/ is no longer committed. Installations must run composer install --no-dev after pulling.
  3. Three constants were renamed (typo fix). Existing includes/constants.php files must be updated:
    • NOTIFYER_SLACK_ENABEDNOTIFYER_SLACK_ENABLED
    • NOTIFYER_MATTERMOST_ENABEDNOTIFYER_MATTERMOST_ENABLED
    • NOTIFYER_TELEGRAM_ENABEDNOTIFYER_TELEGRAM_ENABLED
  4. includes/github-base.php was removed — replaced by joomlagerman\Helper\Bootstrap. Anyone embedding the bot from custom CLI scripts must update accordingly.

Bug fixes

  • Latest-tag selection inverted in getLatestGithubReleaseByBranch(): the version_compare check picked the oldest matching tag instead of the newest. Now extracted into a pure, unit-tested static helper GithubApiHelper::pickLatestTag().
  • Default release seed typo: lastrelease<branch>.data was initialized with <branch>.0v0 instead of <branch>.0.0.
  • Branch-label parser broken on multi-digit minors: substr($targetBranch, 0, 3) mangled 4.10-dev into Joomla! 4.1. Now handled by joomlagerman\Enum\JoomlaBranch::labelFor(), with explicit tests for historical (3.10-dev, 4.10-dev) and modern (5.4-dev, 6.1-dev, 6.4-dev) branches.
  • Missing Registry import in NotifyerHelper: a fallback path referenced new Registry without use Joomla\Registry\Registry;.
  • Auth token leaked through global constant: getSourcePullDiff() read GITHUB_AUTHTOKEN directly instead of going through the options Registry. The token is now wired in via Bootstrap.

PHP 8.5+ modernization

  • declare(strict_types=1) in every PHP file.
  • final classes, readonly properties, constructor property promotion.
  • match expressions for the notifier channel routing.
  • Enums:
    • joomlagerman\Enum\NotificationChannel (Slack / Mattermost / Telegram) — each case carries its own isEnabled(), endpoint(), payload(). Replaces three near-duplicate if-blocks.
    • joomlagerman\Enum\JoomlaBranch — pure branch-label parsing.
  • \DateTimeImmutable instead of \DateTime.
  • New joomlagerman\Helper\Bootstrap factory replaces the require-with-side-effects pattern in includes/github-base.php. The CLI script stays procedural but is now type-safe.
  • All Registry reads go through typed accessors (e.g. optString()); no more (string) $registry->get(...) casts on mixed values.
  • Fixed an additional latent bug surfaced during refactoring: HttpFactory::getHttp() was previously called statically, which fatals on PHP 8.4+. Now (new HttpFactory())->getHttp().

Dependency bumps

Package Before After
php 7.3 ^8.5
joomla/github ^1.7 ^4.0
joomla/http ~1.3 ^4.0
joomla/registry (transitive) ^4.0
joomla/uri (transitive) ^4.0

Includes a small adapter for the PSR-7 response shape that joomla/http 4.x exposes ($response->getBody() instead of the old $response->body).

Tooling

  • composer test — PHPUnit 11, 14 tests covering branch-label parsing, latest-tag selection (incl. the bug-A fix), notifier channel routing.
  • composer stan — PHPStan at level: max, 0 errors.
  • composer cs-check / composer cs-fix — PHP-CS-Fixer with PSR-12 + tab indent (matching .editorconfig).
  • tools/phpstan-stubs/constants.stub.php — type stubs so PHPStan knows the runtime constants.

Migration guide for existing deployments

cd /repo/path/jgerman-bot
git pull
composer install --no-dev

# Update the three renamed constants in includes/constants.php:
#   NOTIFYER_SLACK_ENABED      → NOTIFYER_SLACK_ENABLED
#   NOTIFYER_MATTERMOST_ENABED → NOTIFYER_MATTERMOST_ENABLED
#   NOTIFYER_TELEGRAM_ENABED   → NOTIFYER_TELEGRAM_ENABLED

# Verify PHP 8.5+:
php -v

# Smoke test (won't create issues — exits via the once-a-day guard):
echo "$(date +%Y-%m-%d)" > data/lastrun.data
php cli/jgerman-github-bot.php
tail -5 logs/$(date +%Y%m)_jgerman.log

Test plan

  • composer test — 14/14 green
  • composer stan[OK] No errors
  • composer cs-check — clean
  • Server smoke test on PHP 8.5.5 — bootstrap, autoload, constants loading, logging all verified
  • Server end-to-end run with real merged PRs — issue created in the translation repo, Slack notification fired

Notes

  • joomla/github 4.0.1 and joomla/http 4.0.2 emit a handful of E_DEPRECATED warnings on PHP 8.5 (implicitly nullable parameters, dynamic property creation). These are upstream issues in those packages, not introduced by this PR. They will not break execution on PHP 8.5 but will need fixing before PHP 9.
  • setOption() on the helpers is unused externally. Kept in place for now; can be deprecated/removed in a follow-up if there are no embedders.

@tecpromotion
tecpromotion requested a review from zero-24 May 1, 2026 13:52
Replace the four per-event notifier posts (Start / count / date / End)
  plus the per-issue messages with one consolidated message sent at the
  end of the run. Slack and Mattermost get an attachment with a colored
  bar — green on success, yellow when the daily guard skipped the run.
  Telegram keeps a plain-text variant with HTML links.

  - Add RunStatus + RunSummary under joomlagerman\Notification\
  - NotificationChannel::summaryPayload() builds the channel payload
  - NotifyerHelper exposes a single sendRunSummary() method
  - Drop the unused NOTIFYER_GITHUB_ISSUE_MESSAGE_TEMPLATE constant
@zero-24

zero-24 commented May 26, 2026

Copy link
Copy Markdown
Member

Hmm, to be honest, I can't keep up with all the changes that have been made here. In some cases, the code seems to have been changed quite significantly, even though I understand that it's already running on our setup right?

Will cc also @wojsmol so he is aware that we are working here on a PHP 8.5+ only version which, from my understanding will no longer work on hosts lower than PHP 8.5 right?

@tecpromotion

Copy link
Copy Markdown
Member Author

Will cc also @wojsmol so he is aware that we are working here on a PHP 8.5+ only version which, from my understanding will no longer work on hosts lower than PHP 8.5 right?

I was already incurring additional costs of over €100 a year for the old 7.4 version, so with Claude’s help I managed to get it up to a usable standard.

@zero-24

zero-24 commented May 26, 2026

Copy link
Copy Markdown
Member

Didnt want to say that we are not doing it just mean to cc him in as he is also using that bot for his setup

@zero-24

zero-24 commented May 30, 2026

Copy link
Copy Markdown
Member

@tecpromotion I took another close look at the code and think it looks fine for now. Especially since the code has already been running like this for a few weeks. But I've noticed that since April 30, I haven't been getting any updates from the JGerman bot did you remove me from that list? Or just does the telegram notification not work?

@zero-24

zero-24 commented Jun 2, 2026

Copy link
Copy Markdown
Member

As confirmed via Mattermost the messages are now comming to my channel again. I would suggest to await one final test whether the message is still correct when an upstream PR has been merged an an Issue has been created. Once that is confirmed i would reccommend to merge here.

@wojsmol as you have not commented here yet can you please confirm that your proccess will not break with the new requirementes of PHP version we will deploy this once this is merged?

Thanks

@wojsmol

wojsmol commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

@zero-24 I use older version and working on moving drom a standard server to a GHA for that bot - also with Claude.

define('GITHUB_TRANSLATION_REPO', '');
define('GITHUB_TRANSLATION_LABEL', '');
define('GITHUB_TRANSLATION_ASSIGMENTS', '');
define('GITHUB_TRANSLATION_ASSIGMENTS', []);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
define('GITHUB_TRANSLATION_ASSIGMENTS', []);
define('GITHUB_TRANSLATION_ASSIGNMENTS', []);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@tecpromotion Auch hier kannst du den typo noch an allen stellen im PR fixen? Oder soll ich dir einen PR schicken? aktuell klappt es da es an allen stellen falsch ist nur das anpassen hier reicht dann nicht aus.

@wojsmol

wojsmol commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

@tecpromotion Additional typo find during a refactor for GHA - show in one place but there is more.

Comment thread src/Bootstrap.php
$options->set('translation.repo', GITHUB_TRANSLATION_REPO);
$options->set('translation.label', GITHUB_TRANSLATION_LABEL);
$options->set('translation.assigments', GITHUB_TRANSLATION_ASSIGMENTS);
$options->set('translation.templagebody', GITHUB_TRANSLATION_TEMPLATE_BODY);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
$options->set('translation.templagebody', GITHUB_TRANSLATION_TEMPLATE_BODY);
$options->set('translation.templatebody', GITHUB_TRANSLATION_TEMPLATE_BODY);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@tecpromotion kannst du den typo noch an allen stellen im PR fixen? Oder soll ich dir einen PR schicken? aktuell klappt es da es an allen stellen falsch ist nur das anpassen hier reicht nicht aus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants