<commit_before>package com.softwaremill.codebrag.service.commits

import java.nio.file.Path
import org.eclipse.jgit.transport.{URIish, CredentialItem, UsernamePasswordCredentialsProvider, CredentialsProvider}

trait RepoData {
  def remoteUri: String
  def localPathRelativeTo(path: Path): Path
  def credentials: CredentialsProvider
  def credentialsValid: Boolean
}

case class GitHubRepoData(repoOwner: String, repoName: String, token: String) extends RepoData {
  def remoteUri = s"https://github.com/$repoOwner/$repoName.git"
  def localPathRelativeTo(path: Path) = path.resolve(repoOwner).resolve(repoName)
  def credentials = new UsernamePasswordCredentialsProvider(token, "")
  def credentialsValid = token.nonEmpty
}

case class GitRepoData(name: String, uri: String, username: String, password: String) extends RepoData {
  def remoteUri = uri
  def localPathRelativeTo(path: Path) = path.resolve(name)
  def credentials = new UsernamePasswordCredentialsProvider(username, password)
  def credentialsValid = (password != null && password.nonEmpty)
}

case class GitSshRepoData(name: String, uri: String, passphrase: String) extends RepoData {
  def remoteUri = uri
  def localPathRelativeTo(path: Path) = path.resolve(name)
  def credentials = new SshPassphraseCredentialsProvider(passphrase)
  def credentialsValid = (passphrase != null && passphrase.nonEmpty)

}

class SshPassphraseCredentialsProvider(passphrase: String) extends CredentialsProvider {
  def isInteractive = false
  def supports(items: CredentialItem*) = true
  def get(uri: URIish, items: CredentialItem*) = {
    items.foreach(_.asInstanceOf[CredentialItem.StringType].setValue(passphrase))
    true<commit_msg>Allow connecting to repositories using empty user/password/passphrase<commit_after>package com.softwaremill.codebrag.service.commits

import java.nio.file.Path
import org.eclipse.jgit.transport.{URIish, CredentialItem, UsernamePasswordCredentialsProvider, CredentialsProvider}

trait RepoData {
  def remoteUri: String
  def localPathRelativeTo(path: Path): Path
  def credentials: CredentialsProvider
  def credentialsValid: Boolean
}

case class GitHubRepoData(repoOwner: String, repoName: String, token: String) extends RepoData {
  def remoteUri = s"https://github.com/$repoOwner/$repoName.git"
  def localPathRelativeTo(path: Path) = path.resolve(repoOwner).resolve(repoName)
  def credentials = new UsernamePasswordCredentialsProvider(token, "")
  def credentialsValid = token.nonEmpty
}

case class GitRepoData(name: String, uri: String, username: String, password: String) extends RepoData {
  def remoteUri = uri
  def localPathRelativeTo(path: Path) = path.resolve(name)
  def credentials = new UsernamePasswordCredentialsProvider(username, password)
  def credentialsValid = true
}

case class GitSshRepoData(name: String, uri: String, passphrase: String) extends RepoData {
  def remoteUri = uri
  def localPathRelativeTo(path: Path) = path.resolve(name)
  def credentials = new SshPassphraseCredentialsProvider(passphrase)
  def credentialsValid = true

}

class SshPassphraseCredentialsProvider(passphrase: String) extends CredentialsProvider {
  def isInteractive = false
  def supports(items: CredentialItem*) = true
  def get(uri: URIish, items: CredentialItem*) = {
    if(passphrase.nonEmpty) {
      items.foreach { item => {
        item match {
          case i: CredentialItem.StringType => i.setValue(passphrase)
          case _ => {}
        }
      }}
    }
    true
{'fraction_non_alphanumeric': 0.08923959827833572, 'fraction_numerical': 0.0, 'mean_word_length': 5.503731343283582, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '5400316', 'n_tokens_mistral': 989, 'n_tokens_neox': 989, 'n_words': 254}