From 88f3aea086587ee1ba8cdf31ca7d8d867194f504 Mon Sep 17 00:00:00 2001 From: Carlos A Becker Date: Sun, 19 Mar 2023 23:32:33 -0300 Subject: [PATCH] refactor: improve tmpl mergeability with pro Signed-off-by: Carlos A Becker --- internal/tmpl/tmpl.go | 67 +++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/internal/tmpl/tmpl.go b/internal/tmpl/tmpl.go index 59ee5774e..fd1d1d71a 100644 --- a/internal/tmpl/tmpl.go +++ b/internal/tmpl/tmpl.go @@ -81,38 +81,43 @@ func New(ctx *context.Context) *Template { sv := ctx.Semver rawVersionV := fmt.Sprintf("%d.%d.%d", sv.Major, sv.Minor, sv.Patch) + fields := map[string]interface{}{} + for k, v := range map[string]interface{}{ + projectName: ctx.Config.ProjectName, + modulePath: ctx.ModulePath, + version: ctx.Version, + rawVersion: rawVersionV, + summary: ctx.Git.Summary, + tag: ctx.Git.CurrentTag, + previousTag: ctx.Git.PreviousTag, + branch: ctx.Git.Branch, + commit: ctx.Git.Commit, + shortCommit: ctx.Git.ShortCommit, + fullCommit: ctx.Git.FullCommit, + commitDate: ctx.Git.CommitDate.UTC().Format(time.RFC3339), + commitTimestamp: ctx.Git.CommitDate.UTC().Unix(), + gitURL: ctx.Git.URL, + env: ctx.Env, + date: ctx.Date.UTC().Format(time.RFC3339), + timestamp: ctx.Date.UTC().Unix(), + now: ctx.Date.UTC(), + major: ctx.Semver.Major, + minor: ctx.Semver.Minor, + patch: ctx.Semver.Patch, + prerelease: ctx.Semver.Prerelease, + isSnapshot: ctx.Snapshot, + releaseNotes: ctx.ReleaseNotes, + releaseURL: ctx.ReleaseURL, + tagSubject: ctx.Git.TagSubject, + tagContents: ctx.Git.TagContents, + tagBody: ctx.Git.TagBody, + runtimeK: ctx.Runtime, + } { + fields[k] = v + } + return &Template{ - fields: Fields{ - projectName: ctx.Config.ProjectName, - modulePath: ctx.ModulePath, - version: ctx.Version, - rawVersion: rawVersionV, - tag: ctx.Git.CurrentTag, - previousTag: ctx.Git.PreviousTag, - branch: ctx.Git.Branch, - commit: ctx.Git.Commit, - shortCommit: ctx.Git.ShortCommit, - fullCommit: ctx.Git.FullCommit, - commitDate: ctx.Git.CommitDate.UTC().Format(time.RFC3339), - commitTimestamp: ctx.Git.CommitDate.UTC().Unix(), - gitURL: ctx.Git.URL, - summary: ctx.Git.Summary, - tagSubject: ctx.Git.TagSubject, - tagContents: ctx.Git.TagContents, - tagBody: ctx.Git.TagBody, - releaseURL: ctx.ReleaseURL, - env: ctx.Env, - date: ctx.Date.UTC().Format(time.RFC3339), - now: ctx.Date.UTC(), - timestamp: ctx.Date.UTC().Unix(), - major: ctx.Semver.Major, - minor: ctx.Semver.Minor, - patch: ctx.Semver.Patch, - prerelease: ctx.Semver.Prerelease, - isSnapshot: ctx.Snapshot, - releaseNotes: ctx.ReleaseNotes, - runtimeK: ctx.Runtime, - }, + fields: fields, } }