private readonly getReportName:()

in test-reporter/src/input-providers/artifact-provider.ts [14:48]


  private readonly getReportName: (name: string) => string

  constructor(
    readonly octokit: InstanceType<typeof GitHub>,
    readonly artifact: string,
    readonly name: string,
    readonly pattern: string[],
    readonly sha: string,
    readonly runId: number,
    readonly token: string
  ) {
    if (this.artifact.startsWith('/')) {
      const endIndex = this.artifact.lastIndexOf('/')
      const rePattern = this.artifact.substring(1, endIndex)
      const reOpts = this.artifact.substring(endIndex + 1)
      const re = new RegExp(rePattern, reOpts)
      this.artifactNameMatch = (str: string) => re.test(str)
      this.getReportName = (str: string) => {
        const match = str.match(re)
        if (match === null) {
          throw new Error(`Artifact name '${str}' does not match regex ${this.artifact}`)
        }
        let reportName = this.name
        for (let i = 1; i < match.length; i++) {
          reportName = reportName.replace(new RegExp(`\\$${i}`, 'g'), match[i])
        }
        return reportName
      }
    } else {
      this.artifactNameMatch = (str: string) => str === this.artifact
      this.getReportName = () => this.name
    }

    this.fileNameMatch = picomatch(pattern)
  }