<commit_before><?php

namespace REBELinBLUE\Deployer\Github;

use Httpful\Request;
use Illuminate\Contracts\Cache\Repository as CacheRepository;
use REBELinBLUE\Deployer\Contracts\Github\LatestReleaseInterface;

/**
 * A class to get the latest release tag for Github.
 */
class LatestRelease implements LatestReleaseInterface
{
    const CACHE_TIME_IN_HOURS = 12;

    /**
     * @var string
     **/
    private $github_url = 'https://api.github.com/repos/REBELinBLUE/deployer/releases/latest';

    /**
     * @var CacheRepository
     */
    private $cache;

    /**
     * LatestRelease constructor.
     *
     * @param CacheRepository $cache
     */
    public function __construct(CacheRepository $cache)
    {
        $this->cache = $cache;
    }

    /**
     * Get the latest release from Github.
     *
     * @return false|string
     */
    public function latest()
    {
        $cache_for = self::CACHE_TIME_IN_HOURS * 60;

        $release = $this->cache->remember('latest_version', $cache_for, function () {
            $request = Request::get($this->github_url)
                              ->expectsJson()
                              ->withAccept('application/vnd.github.v3+json');

            if (config('deployer.github_oauth_token')) {
                $request->withAuthorization('token ' . config('deployer.github_oauth_token'));
            }

            $response = $request->send();

            if ($response->hasErrors()) {
                return false;
            }

            return $response->body;
        });
<commit_msg>Handling the timeout checking for an update on github, i.e. when I am at work behind a proxy<commit_after><?php

namespace REBELinBLUE\Deployer\Github;

use Httpful\Exception\ConnectionErrorException;
use Httpful\Request;
use Illuminate\Contracts\Cache\Repository as CacheRepository;
use REBELinBLUE\Deployer\Contracts\Github\LatestReleaseInterface;

/**
 * A class to get the latest release tag for Github.
 */
class LatestRelease implements LatestReleaseInterface
{
    const CACHE_TIME_IN_HOURS = 12;

    /**
     * @var string
     **/
    private $github_url = 'https://api.github.com/repos/REBELinBLUE/deployer/releases/latest';

    /**
     * @var CacheRepository
     */
    private $cache;

    /**
     * LatestRelease constructor.
     *
     * @param CacheRepository $cache
     */
    public function __construct(CacheRepository $cache)
    {
        $this->cache = $cache;
    }

    /**
     * Get the latest release from Github.
     *
     * @return false|string
     */
    public function latest()
    {
        $cache_for = self::CACHE_TIME_IN_HOURS * 60;

        $release = $this->cache->remember('latest_version', $cache_for, function () {

            $request = Request::get($this->github_url)
                              ->timeoutIn(5)
                              ->expectsJson()
                              ->withAccept('application/vnd.github.v3+json');

            if (config('deployer.github_oauth_token')) {
                $request->withAuthorization('token ' . config('deployer.github_oauth_token'));
            }

            try {
                $response = $request->send();
            } catch (ConnectionErrorException $exception) {
                return false;
            }
            
            if ($response->hasErrors()) {
                return false;
            }

            return $response->body;
        });

{'fraction_non_alphanumeric': 0.11638056444573756, 'fraction_numerical': 0.003200465522257783, 'mean_word_length': 2.0290748898678412, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2617176', 'n_tokens_mistral': 1006, 'n_tokens_neox': 960, 'n_words': 190}