mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-01-13 13:21:00 +00:00
refactor: let updaters define the files they want to run on (#233)
This change reverses the responsibility for which files the updaters are run on. Now each updater can specify the list of files and wether the files should be created when they do not exist yet. This simplifies the handling of each update in releaserpleaser.go, as we can just iterate over all updaters and call it for each file of that updater. Also update the flags to allow users to easily define which updaters should run.
This commit is contained in:
parent
1e9e0aa5d9
commit
f1aa1a2ef4
20 changed files with 307 additions and 151 deletions
|
|
@ -34,10 +34,10 @@ type ReleaserPleaser struct {
|
|||
commitParser commitparser.CommitParser
|
||||
versioning versioning.Strategy
|
||||
extraFiles []string
|
||||
updaters []updater.NewUpdater
|
||||
updaters []updater.Updater
|
||||
}
|
||||
|
||||
func New(forge forge.Forge, logger *slog.Logger, targetBranch string, commitParser commitparser.CommitParser, versioningStrategy versioning.Strategy, extraFiles []string, updaters []updater.NewUpdater) *ReleaserPleaser {
|
||||
func New(forge forge.Forge, logger *slog.Logger, targetBranch string, commitParser commitparser.CommitParser, versioningStrategy versioning.Strategy, extraFiles []string, updaters []updater.Updater) *ReleaserPleaser {
|
||||
return &ReleaserPleaser{
|
||||
forge: forge,
|
||||
logger: logger,
|
||||
|
|
@ -281,16 +281,12 @@ func (rp *ReleaserPleaser) runReconcileReleasePR(ctx context.Context) error {
|
|||
// Info for updaters
|
||||
info := updater.ReleaseInfo{Version: nextVersion, ChangelogEntry: changelogEntry}
|
||||
|
||||
err = repo.UpdateFile(ctx, updater.ChangelogFile, true, updater.WithInfo(info, updater.Changelog))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update changelog file: %w", err)
|
||||
}
|
||||
|
||||
for _, path := range rp.extraFiles {
|
||||
// TODO: Check for missing files
|
||||
err = repo.UpdateFile(ctx, path, false, updater.WithInfo(info, rp.updaters...))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to run file updater: %w", err)
|
||||
for _, u := range rp.updaters {
|
||||
for _, file := range u.Files() {
|
||||
err = repo.UpdateFile(ctx, file, u.CreateNewFiles(), u.Update(info))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to run updater %T: %w", u, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue