Skip to content

Commit

Permalink
Update ModuleCustomTrait.php
Browse files Browse the repository at this point in the history
Adding an additional method call to allow the processing of the response from the get latest version request. With this it would be possible for me to query the version information directly from githubs release json without the need for an exta latest-release.txt file. Using the method I could easily parse the JSON response and extract the version information.
  • Loading branch information
magicsunday committed Oct 24, 2024
1 parent 95621db commit f8cdec5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/Module/ModuleCustomTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ public function customModuleLatestVersionUrl(): string
return '';
}

/**
* Fetch the version information from the given content string.
*
* @param string $content
*
* @return string
*/
protected function extractVersion(string $content): string

Check warning on line 92 in app/Module/ModuleCustomTrait.php

View check run for this annotation

Codecov / codecov/patch

app/Module/ModuleCustomTrait.php#L92

Added line #L92 was not covered by tests
{
return $content;

Check warning on line 94 in app/Module/ModuleCustomTrait.php

View check run for this annotation

Codecov / codecov/patch

app/Module/ModuleCustomTrait.php#L94

Added line #L94 was not covered by tests
}

/**
* Fetch the latest version of this module.
*
Expand All @@ -103,7 +115,7 @@ public function customModuleLatestVersion(): string
$response = $client->get($this->customModuleLatestVersionUrl());

if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) {
$version = $response->getBody()->getContents();
$version = $this->extractVersion($response->getBody()->getContents());

Check warning on line 118 in app/Module/ModuleCustomTrait.php

View check run for this annotation

Codecov / codecov/patch

app/Module/ModuleCustomTrait.php#L118

Added line #L118 was not covered by tests

// Does the response look like a version?
if (preg_match('/^\d+\.\d+\.\d+/', $version)) {
Expand Down

0 comments on commit f8cdec5

Please sign in to comment.