< Summary - go-semantic-release Coverage

Line coverage
90%
Covered lines: 29
Uncovered lines: 3
Coverable lines: 32
Total lines: 63
Line coverage: 90.6%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Analyze0%0090.63%

File(s)

/home/runner/work/go-semantic-release/go-semantic-release/internal/app/analyze_commits.go

#LineLine coverage
 1package app
 2
 3import (
 4  "context"
 5  "fmt"
 6
 7  "github.com/jedi-knights/go-semantic-release/internal/domain"
 8  "github.com/jedi-knights/go-semantic-release/internal/ports"
 9)
 10
 11// CommitAnalyzer analyzes commits since the last release.
 12type CommitAnalyzer struct {
 13  git    ports.GitRepository
 14  parser ports.CommitParser
 15  logger ports.Logger
 16}
 17
 18// NewCommitAnalyzer creates a commit analyzer.
 19func NewCommitAnalyzer(git ports.GitRepository, parser ports.CommitParser, logger ports.Logger) *CommitAnalyzer {
 20  return &CommitAnalyzer{git: git, parser: parser, logger: logger}
 21}
 22
 23// Analyze retrieves and parses commits since the given tag hash.
 524func (a *CommitAnalyzer) Analyze(ctx context.Context, sinceHash string) ([]domain.Commit, error) {
 525  rawCommits, err := a.git.CommitsSince(ctx, sinceHash)
 126  if err != nil {
 127    return nil, fmt.Errorf("fetching commits: %w", err)
 128  }
 29
 430  a.logger.Debug("found raw commits", "count", len(rawCommits))
 431
 432  parsed := make([]domain.Commit, 0, len(rawCommits))
 433  for i := range rawCommits {
 634    fullMessage := rawCommits[i].Message
 135    if rawCommits[i].Body != "" {
 136      fullMessage = rawCommits[i].Message + "\n\n" + rawCommits[i].Body
 137    }
 38
 639    commit, err := a.parser.Parse(fullMessage)
 140    if err != nil {
 141      a.logger.Warn("skipping unparseable commit", "hash", rawCommits[i].Hash, "error", err)
 142      continue
 43    }
 44
 45    // Preserve git metadata from raw commit.
 546    commit.Hash = rawCommits[i].Hash
 547    commit.Author = rawCommits[i].Author
 548    commit.AuthorEmail = rawCommits[i].AuthorEmail
 549    commit.Date = rawCommits[i].Date
 550
 551    // Populate changed files.
 552    files, err := a.git.FilesChangedInCommit(ctx, rawCommits[i].Hash)
 053    if err != nil {
 054      a.logger.Warn("failed to get changed files", "hash", rawCommits[i].Hash, "error", err)
 055    }
 556    commit.FilesChanged = files
 557
 558    parsed = append(parsed, commit)
 59  }
 60
 461  a.logger.Info("analyzed commits", "total", len(rawCommits), "parsed", len(parsed))
 462  return parsed, nil
 63}

Methods/Properties

Analyze