private function normalizeSha(Environment $environment, $sha = null)
    {
        if ($environment->head_commit === null) {
            return null;
        }
        if ($sha === null) {
            return $environment->head_commit;
        }
        if (strpos($sha, 'HEAD') === 0) {
            $sha = $environment->head_commit . substr($sha, 4);
        }

        return $sha;
    }