<commit_before>module SubmoduleHelper
  include Gitlab::ShellAdapter

  # links to files listing for submodule if submodule is a project on this server
  def submodule_links(submodule_item)
    url = @repository.submodule_url_for(@ref, submodule_item.path)

    return url, nil unless url =~ /([^\/:]+\/[^\/]+\.git)\Z/

    project = $1
    project.chomp!('.git')

    if self_url?(url, project)
      return project_path(project), project_tree_path(project, submodule_item.id)
    elsif relative_self_url?(url)
      relative_self_links(url, submodule_item.id)
    elsif github_dot_com_url?(url)
      standard_links('github.com', project, submodule_item.id)
    elsif gitlab_dot_com_url?(url)
      standard_links('gitlab.com', project, submodule_item.id)
    else
      return url, nil
    end
  end

  protected

  def github_dot_com_url?(url)
    url =~ /github\.com[\/:][^\/]+\/[^\/]+\Z/
  end

  def gitlab_dot_com_url?(url)
    url =~ /gitlab\.com[\/:][^\/]+\/[^\/]+\Z/
  end

  def self_url?(url, project)
    return true if url == [ Gitlab.config.gitlab.url, '/', project, '.git' ].join('')
    url == gitlab_shell.url_to_repo(project)
  end

  def relative_self_url?(url)
    # (./)? ( (../repo.git) | (../../project/repo.git) )
    url =~ /(^((\.\/)?(((\.\.)\/)|((\.\.)\/(\.\.)\/.*\/)))[^\.\/]*\.git)\Z/
  end

  def standard_links(host, project, commit)
    base = [ 'https://', host, '/', project ].join('')
    return base, [ base, '/tree/', commit ].join('')
  end

  def relative_self_links(url, commit)
    if url.scan(/(\.\.)/).size == 2
      base = [ Gitlab.config.gitlab.url, '/', url[/.*\/(.*)\/.*\.git/, 1] ].join('')
    else
      base = [ Gitlab.config.gitlab.url, '/', @project.group.path ].join('')
    end
    base = [ base, '/', url[/.*\/(.*)\.git/, 1] ].join('')
    return base, [ base, '/tree/', commit ].join('')
  end
end
<commit_msg>fixed regex to match url pointing to a user repo<commit_after>module SubmoduleHelper
  include Gitlab::ShellAdapter

  # links to files listing for submodule if submodule is a project on this server
  def submodule_links(submodule_item)
    url = @repository.submodule_url_for(@ref, submodule_item.path)

    return url, nil unless url =~ /([^\/:]+\/[^\/]+\.git)\Z/

    project = $1
    project.chomp!('.git')

    if self_url?(url, project)
      return project_path(project), project_tree_path(project, submodule_item.id)
    elsif relative_self_url?(url)
      relative_self_links(url, submodule_item.id)
    elsif github_dot_com_url?(url)
      standard_links('github.com', project, submodule_item.id)
    elsif gitlab_dot_com_url?(url)
      standard_links('gitlab.com', project, submodule_item.id)
    else
      return url, nil
    end
  end

  protected

  def github_dot_com_url?(url)
    url =~ /github\.com[\/:][^\/]+\/[^\/]+\Z/
  end

  def gitlab_dot_com_url?(url)
    url =~ /gitlab\.com[\/:][^\/]+\/[^\/]+\Z/
  end

  def self_url?(url, project)
    return true if url == [ Gitlab.config.gitlab.url, '/', project, '.git' ].join('')
    url == gitlab_shell.url_to_repo(project)
  end

  def relative_self_url?(url)
    # (./)?(../repo.git) || (./)?(../../project/repo.git) )
    url =~ /^((\.\/)?(\.\.\/))(?!(\.\.)|(.*\/)).*\.git\Z/ || url =~ /^((\.\/)?(\.\.\/){2})(?!(\.\.))([^\/]*)\/(?!(\.\.)|(.*\/)).*\.git\Z/
  end

  def standard_links(host, project, commit)
    base = [ 'https://', host, '/', project ].join('')
    return base, [ base, '/tree/', commit ].join('')
  end

  def relative_self_links(url, commit)
    if url.scan(/(\.\.\/)/).size == 2
      base = [ Gitlab.config.gitlab.url, '/', url[/.*\/(.*)\/.*\.git/, 1] ].join('')
    else
      base = [ Gitlab.config.gitlab.url, '/', @project.group.path ].join('')
    end
    base = [ base, '/', url[/.*\/(.*)\.git/, 1] ].join('')
    return base, [ base, '/tree/', commit ].join('')
  end
end

{'fraction_non_alphanumeric': 0.2329515877147319, 'fraction_numerical': 0.002342529932326913, 'mean_word_length': 2.7094594594594597, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7296400', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1442, 'n_words': 285}