<commit_before>package material.plugin

import com.amazonaws.auth.BasicAWSCredentials
import com.thoughtworks.go.plugin.api.material.packagerepository._
import com.thoughtworks.go.plugin.api.response.Result
import material.plugin.config.S3PackageMaterialConfiguration
import material.store._
import com.amazonaws.services.s3.AmazonS3Client
import material.store.Exists
import material.store.S3ArtifactStore
import material.util.LoggerUtil


class S3PackageMaterialPoller extends PackageMaterialPoller with LoggerUtil {
  val USER = "go"
  override def getLatestRevision(packageConfig: PackageConfiguration, repoConfig: RepositoryConfiguration): PackageRevision = {
    val s3Bucket = repoConfig.get(S3PackageMaterialConfiguration.S3_BUCKET).getValue
    val artifactStore = S3ArtifactStore(s3Client(repoConfig), s3Bucket)
    val revision = artifactStore.latestRevision(artifact(packageConfig))
    revision match {
      case x: RevisionSuccess => new PackageRevision(x.revision.revision, x.lastModified, USER, x.revisionComments, x.trackBackUrl)
      case f : OperationFailure => throw new RuntimeException(f.th)
     }
  }

  override def checkConnectionToPackage(packageConfig: PackageConfiguration, repoConfig: RepositoryConfiguration): Result = {
    val s3Bucket = repoConfig.get(S3PackageMaterialConfiguration.S3_BUCKET).getValue
    val artifactStore = S3ArtifactStore(s3Client(repoConfig), s3Bucket)
    artifactStore.exists(artifact(packageConfig).prefix) match {
      case e: Exists => new Result().withSuccessMessages(s"Check ${artifact(packageConfig)} exists ${e.message}")
      case f: OperationFailure => new Result().withErrorMessages(f.message)
    }
  }

  override def checkConnectionToRepository(repoConfig: RepositoryConfiguration): Result = {
    val s3Bucket = repoConfig.get(S3PackageMaterialConfiguration.S3_BUCKET).getValue
    val artifactStore = S3ArtifactStore(s3Client(repoConfig), s3Bucket)
    artifactStore.bucketExists match {
      case e: Exists => new Result().withSuccessMessages(s"Check [$s3Bucket] exists ${e.message}")
      case f: OperationFailure => new Result().withErrorMessages(f.message)<commit_msg>print stack trace on check package connection failure<commit_after>package material.plugin

import com.amazonaws.auth.BasicAWSCredentials
import com.thoughtworks.go.plugin.api.material.packagerepository._
import com.thoughtworks.go.plugin.api.response.Result
import material.plugin.config.S3PackageMaterialConfiguration
import material.store._
import com.amazonaws.services.s3.AmazonS3Client
import material.store.Exists
import material.store.S3ArtifactStore
import material.util.LoggerUtil


class S3PackageMaterialPoller extends PackageMaterialPoller with LoggerUtil {
  val USER = "go"
  override def getLatestRevision(packageConfig: PackageConfiguration, repoConfig: RepositoryConfiguration): PackageRevision = {
    val s3Bucket = repoConfig.get(S3PackageMaterialConfiguration.S3_BUCKET).getValue
    val artifactStore = S3ArtifactStore(s3Client(repoConfig), s3Bucket)
    val revision = artifactStore.latestRevision(artifact(packageConfig))
    revision match {
      case x: RevisionSuccess => new PackageRevision(x.revision.revision, x.lastModified, USER, x.revisionComments, x.trackBackUrl)
      case f : OperationFailure => throw new RuntimeException(f.th)
     }
  }

  override def checkConnectionToPackage(packageConfig: PackageConfiguration, repoConfig: RepositoryConfiguration): Result = {
    val s3Bucket = repoConfig.get(S3PackageMaterialConfiguration.S3_BUCKET).getValue
    val artifactStore = S3ArtifactStore(s3Client(repoConfig), s3Bucket)
    artifactStore.exists(artifact(packageConfig).prefix) match {
      case e: Exists => new Result().withSuccessMessages(s"Check ${artifact(packageConfig)} exists ${e.message}")
      case f: OperationFailure => 
	f.th.printStackTrace()
	new Result().withErrorMessages(f.message)
    }
  }

  override def checkConnectionToRepository(repoConfig: RepositoryConfiguration): Result = {
    val s3Bucket = repoConfig.get(S3PackageMaterialConfiguration.S3_BUCKET).getValue
    val artifactStore = S3ArtifactStore(s3Client(repoConfig), s3Bucket)
    artifactStore.bucketExists match {
      case e: Exists => new Result().withSuccessMessages(s"Check [$s3Bucket] exists ${e.message}")
      case f: OperationFailure => new Result().withErrorMessages(f.message)
{'fraction_non_alphanumeric': 0.08836996336996338, 'fraction_numerical': 0.01098901098901099, 'mean_word_length': 5.934920634920635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, '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': '2770387', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1180, 'n_words': 245}