Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
fix: put commits into release notes builder
fix: provide total commits num
fix: add unused category if there are any unused commits
  • Loading branch information
Semior001 committed Aug 21, 2024
1 parent d90986f commit 1277fc2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
27 changes: 15 additions & 12 deletions app/service/notes/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ type BuildRequest struct {
// Build builds the changelog for the tag.
func (s *Builder) Build(ctx context.Context, req BuildRequest) (string, error) {
data := tmplData{
From: req.From,
To: req.To,
Date: s.now(),
Extras: s.Extras,
Total: len(req.ClosedPRs),
From: req.From,
To: req.To,
Date: s.now(),
Extras: s.Extras,
Total: len(req.ClosedPRs),
TotalCommits: len(req.Commits),
}

usedPRs := make([]bool, len(req.ClosedPRs))
Expand Down Expand Up @@ -109,7 +110,8 @@ func (s *Builder) Build(ctx context.Context, req BuildRequest) (string, error) {
}

if s.UnusedTitle != "" {
if unlabeled := s.makeUnlabeledCategory(usedPRs, usedCommits, req.ClosedPRs, req.Commits); len(unlabeled.PRs) > 0 {
unlabeled := s.makeUnlabeledCategory(usedPRs, usedCommits, req.ClosedPRs, req.Commits)
if len(unlabeled.PRs) > 0 || len(unlabeled.Commits) > 0 {
s.sortPRs(unlabeled.PRs)
data.Categories = append(data.Categories, unlabeled)
}
Expand Down Expand Up @@ -185,12 +187,13 @@ func (s *Builder) sortPRs(prs []git.PullRequest) {
}

type tmplData struct {
From string
To string
Date time.Time // always set to the time when the changelog is generated
Extras map[string]string
Total int // total number of PRs
Categories []categoryTmplData
From string
To string
Date time.Time // always set to the time when the changelog is generated
Extras map[string]string
Total int // total number of PRs
TotalCommits int // total number of commits
Categories []categoryTmplData
}

type categoryTmplData struct {
Expand Down
22 changes: 12 additions & 10 deletions app/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ package service
import (
"context"
"fmt"
gengine "github.com/Semior001/releaseit/app/git/engine"
"log"
"regexp"

gengine "github.com/Semior001/releaseit/app/git/engine"

"github.com/Semior001/releaseit/app/git"
"github.com/Semior001/releaseit/app/notify"
"github.com/Semior001/releaseit/app/service/eval"
Expand All @@ -32,13 +33,19 @@ func (s *Service) Changelog(ctx context.Context, fromExpr, toExpr string) error
return fmt.Errorf("evaluate commit IDs: %w", err)
}

log.Printf("[DEBUG] comparing commits between %s and %s", from, to)
compare, err := s.Engine.Compare(ctx, from, to)
if err != nil {
return fmt.Errorf("compare commits between %s and %s: %w", from, to, err)
}

log.Printf("[DEBUG] aggregating closed pull requests between %s and %s", from, to)
prs, err := s.closedPRsBetweenSHA(ctx, from, to)
prs, err := s.closedPRsBetweenSHA(ctx, compare.Commits)
if err != nil {
return fmt.Errorf("get closed pull requests between %s and %s: %w", from, to, err)
}

req := notes.BuildRequest{From: from, To: to, ClosedPRs: prs}
req := notes.BuildRequest{From: from, To: to, ClosedPRs: prs, Commits: compare.Commits}

log.Printf("[DEBUG] building release notes for %d pull requests", len(prs))
text, err := s.ReleaseNotesBuilder.Build(ctx, req)
Expand All @@ -54,15 +61,10 @@ func (s *Service) Changelog(ctx context.Context, fromExpr, toExpr string) error
return nil
}

func (s *Service) closedPRsBetweenSHA(ctx context.Context, fromSHA, toSHA string) ([]git.PullRequest, error) {
func (s *Service) closedPRsBetweenSHA(ctx context.Context, commits []git.Commit) ([]git.PullRequest, error) {
var res []git.PullRequest

commits, err := s.Engine.Compare(ctx, fromSHA, toSHA)
if err != nil {
return nil, fmt.Errorf("compare commits between %s and %s: %w", fromSHA, toSHA, err)
}

for _, commit := range commits.Commits {
for _, commit := range commits {
if ok := s.isMergeCommit(commit); !ok {
continue
}
Expand Down

0 comments on commit 1277fc2

Please sign in to comment.