Repository: neovim/neovim
File: runtime/lua/vim/health/health.lua (Lua)

Code before:
    if env then
      return type(val) == 'function' and val() or val
    end
  end

  return 'unknown'
end

---@param nvim_version string
local function check_stable_version(nvim_version)
  local latest_version = nil
  if vim.fn.executable('git') == 1 then
    local result = vim
      .system({
        'git',
        'ls-remote',
        '--tags',
        'https://github.com/neovim/neovim',
      }, { text = true })
      :wait()
    local stable_sha = result.stdout:match('(%x+)%s+refs/tags/stable\n')
    if stable_sha then
      latest_version = result.stdout:match(stable_sha .. '%s+refs/tags/v?(%d+%.%d+%.%d+)%^{}')
    end
  else
    if vim.fn.executable('curl') == 1 then
      local result = vim
        .system({
          'curl',
          '-s',
          'https://api.github.com/repos/neovim/neovim/releases/latest',
        }, { text = true })
        :wait()
      if result.code == 0 then
        ---@type boolean, table<string, string>
        local ok, data = pcall(vim.json.decode, result.stdout)
        if ok and data.tag_name then
          latest_version = data.tag_name:match('v?(%d+%.%d+%.%d+)')
        end
      end
    end
  end

  if latest_version then
    local current_version = nvim_version:match('v(%d+%.%d+%.%d+)')
    if latest_version ~= current_version then
      vim.health.warn(
        string.format('Neovim %s is available (current: %s)', latest_version, current_version)
      )
    end
  end

Review comment (suggestion):
I do not think we need to bother with trying both git and curl. Just pick one. `git` is a reasonable expectation for this feature, let's drop the `curl` branches.

Code after:
    if env then
      return type(val) == 'function' and val() or val
    end
  end

  return 'unknown'
end

---@param nvim_version string
local function check_stable_version(nvim_version)
  local result = vim
    .system(
      { 'git', 'ls-remote', '--tags', 'https://github.com/neovim/neovim' },
      { text = true, timeout = 5000 }
    )
    :wait()
  if result.code ~= 0 or not result.stdout or result.stdout == '' then
    return
  end
  local stable_sha = result.stdout:match('(%x+)%s+refs/tags/stable%^{}')
    or result.stdout:match('(%x+)%s+refs/tags/stable\n')
  if not stable_sha then
    return
  end
  local latest_version = result.stdout:match(stable_sha .. '%s+refs/tags/v?(%d+%.%d+%.%d+)%^{}')
  if not latest_version then
    return
  end
  local current_version = nvim_version:match('v?(%d+%.%d+%.%d+)')
  if not current_version then
    return
  end
  local current = vim.version.parse(current_version)
  local latest = vim.version.parse(latest_version)
  if current and latest and vim.version.lt(current, latest) then
    vim.health.warn(('Nvim %s is available (current: %s)'):format(latest_version, current_version))
  else
    vim.health.ok(('Up to date (%s)'):format(current_version))
  end
end

---@param commit string
local function check_head_hash(commit)
  local result = vim
    .system(
      { 'git', 'ls-remote', 'https://github.com/neovim/neovim', 'HEAD' },
      { text = true, timeout = 5000 }
    )
    :wait()
  if result.code ~= 0 or not result.stdout or result.stdout == '' then
    return