Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions hooks/available.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ end

function GetReleaseListForWindows()
local result = {}
local urls = { WIN_URL, WIN_URL_LTS }
local urls = { WIN_RELEASES_URL, WIN_RELEASES_URL_LTS }

for _, url in ipairs(urls) do
local resp, err = http.get({ url = url })
Expand All @@ -41,7 +41,7 @@ function GetReleaseListForWindows()
name = versionStr
}

entry.is_from_lts = (url == WIN_URL_LTS)
entry.is_from_lts = (url == WIN_RELEASES_URL_LTS)
table.insert(result, entry)
end
end
Expand All @@ -53,20 +53,27 @@ function GetReleaseListForWindows()
end

function GetReleaseListForLinux()
local resp, err = http.get({
url = URL .. '/releases'
})
local doc = html.parse(resp.body)

local result = {}
doc:find("#layout-content h2"):each(function(i, selection)
local versionStr = selection:text()
if util.compare_versions(versionStr, "5.3.2") >= 0 then
table.insert(result, {
version = versionStr,
})
local urls = { RELEASES_URL, RELEASES_URL_LTS }

for _, url in ipairs(urls) do
local resp, err = http.get({ url = url })
local is_from_lts = (url == RELEASES_URL_LTS)

if resp then
local doc = html.parse(resp.body)
local query = "#layout-content " .. (is_from_lts and "h3" or "h2")
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

The CSS selector construction using string concatenation with conditional logic makes the code harder to understand. Consider defining separate constants for the selectors or extracting this into a helper function.

Copilot uses AI. Check for mistakes.
doc:find(query):each(function(i, selection)
local versionStr = is_from_lts and selection:attr("id") or selection:text()
versionStr = versionStr:gsub("^v", "")
Comment on lines +67 to +68
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

The conditional logic for extracting version strings is unclear. Consider extracting this into separate functions for LTS and standard release parsing to improve readability and maintainability.

Copilot uses AI. Check for mistakes.
if util.compare_versions(versionStr, "5.3.2") >= 0 then
table.insert(result, {
version = versionStr,
})
end
end)
end
end)
end

table.sort(result, function(a, b)
return util.compare_versions(a.version, b.version) > 0
Expand Down
4 changes: 2 additions & 2 deletions hooks/pre_install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ function PLUGIN:PreInstall(ctx)
end

function GetReleaseForWindows(versions)
url = WIN_URL .. versions.name
url = WIN_RELEASES_URL .. versions.name

if (versions.is_from_lts) then
url = WIN_URL_LTS .. versions.name
url = WIN_RELEASES_URL_LTS .. versions.name
end
return {
version = versions.version,
Expand Down
8 changes: 5 additions & 3 deletions lib/constants.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
URL = 'https://www.php.net/'
WIN_URL = 'https://windows.php.net/downloads/releases/archives/'
WIN_URL_LTS = 'https://windows.php.net/downloads/releases/'
URL = 'https://www.php.net'
RELEASES_URL = URL .. '/releases/'
RELEASES_URL_LTS = URL .. '/downloads.php'
WIN_RELEASES_URL = 'https://windows.php.net/downloads/releases/archives/'
WIN_RELEASES_URL_LTS = 'https://windows.php.net/downloads/releases/'