|
| 1 | +package artifacts |
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + "github.com/easy-up/go-coverage" |
| 6 | + "log/slog" |
| 7 | + "strings" |
| 8 | +) |
| 9 | + |
| 10 | +func example() (coverage.Report, error) { |
| 11 | + lcovParser := coverage.New(coverage.LCOV) |
| 12 | + report, err := lcovParser.Parse("./path/to/lcov.info") |
| 13 | + if err != nil { |
| 14 | + // Handle error |
| 15 | + return coverage.Report{}, err |
| 16 | + } |
| 17 | + // Use the parsed report |
| 18 | + return report, nil |
| 19 | +} |
| 20 | + |
| 21 | +func IsCoverageReport(inputFilename string) bool { |
| 22 | + return strings.Contains(inputFilename, "lcov") || |
| 23 | + strings.HasSuffix(inputFilename, ".info") || |
| 24 | + strings.Contains(inputFilename, "clover") || |
| 25 | + strings.Contains(inputFilename, "cobertura") || |
| 26 | + strings.Contains(inputFilename, "coverage") |
| 27 | +} |
| 28 | + |
| 29 | +func GetCoverageMode(inputFilename string) (coverage.CoverageMode, error) { |
| 30 | + var coverageFormat coverage.CoverageMode |
| 31 | + if strings.Contains(inputFilename, "lcov") || strings.HasSuffix(inputFilename, ".info") { |
| 32 | + coverageFormat = coverage.LCOV |
| 33 | + } else if strings.Contains(inputFilename, "clover") { |
| 34 | + coverageFormat = coverage.CLOVER |
| 35 | + } else if strings.HasSuffix(inputFilename, ".xml") { |
| 36 | + coverageFormat = coverage.COBERTURA |
| 37 | + } else { |
| 38 | + slog.Error("unsupported coverage file type, cannot be determined from filename", "filename", inputFilename) |
| 39 | + return "", errors.New("failed to list coverage content") |
| 40 | + } |
| 41 | + return coverageFormat, nil |
| 42 | +} |
0 commit comments