- Notifications
You must be signed in to change notification settings - Fork928
feat: add support for template version messages in api and cli#8336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
77dbe0b
f40bcc7
a2aedfd
ffb7f3f
98377ad
960e5d1
7cd20bb
93de18a
5bee51f
9280af6
b8e36f6
9945e94
3329d5b
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -5,6 +5,7 @@ import ( | ||
"fmt" | ||
"io" | ||
"path/filepath" | ||
"strings" | ||
"time" | ||
"github.com/briandowns/spinner" | ||
@@ -21,6 +22,7 @@ import ( | ||
type templateUploadFlags struct { | ||
directory string | ||
ignoreLockfile bool | ||
message string | ||
} | ||
func (pf *templateUploadFlags) options() []clibase.Option { | ||
@@ -35,6 +37,11 @@ func (pf *templateUploadFlags) options() []clibase.Option { | ||
Description: "Ignore warnings about not having a .terraform.lock.hcl file present in the template.", | ||
Default: "false", | ||
Value: clibase.BoolOf(&pf.ignoreLockfile), | ||
}, { | ||
Flag: "message", | ||
FlagShorthand: "m", | ||
Description: "Specify a message describing the changes in this version of the template. Messages longer than 72 characters will be displayed as truncated.", | ||
Value: clibase.StringOf(&pf.message), | ||
}} | ||
} | ||
@@ -110,6 +117,20 @@ func (pf *templateUploadFlags) checkForLockfile(inv *clibase.Invocation) error { | ||
return nil | ||
} | ||
func (pf *templateUploadFlags) templateMessage(inv *clibase.Invocation) string { | ||
title := strings.SplitN(pf.message, "\n", 2)[0] | ||
if len(title) > 72 { | ||
cliui.Warn(inv.Stdout, "Template message is longer than 72 characters, it will be displayed as truncated.") | ||
} | ||
if title != pf.message { | ||
cliui.Warn(inv.Stdout, "Template message contains newlines, only the first line will be displayed.") | ||
} | ||
if pf.message != "" { | ||
return pf.message | ||
} | ||
return "Uploaded from the CLI" | ||
mafredri marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
func (pf *templateUploadFlags) templateName(args []string) (string, error) { | ||
if pf.stdin() { | ||
// Can't infer name from directory if none provided. | ||
@@ -174,6 +195,8 @@ func (r *RootCmd) templatePush() *clibase.Cmd { | ||
return xerrors.Errorf("check for lockfile: %w", err) | ||
} | ||
message := uploadFlags.templateMessage(inv) | ||
resp, err := uploadFlags.upload(inv, client) | ||
if err != nil { | ||
return err | ||
@@ -186,6 +209,7 @@ func (r *RootCmd) templatePush() *clibase.Cmd { | ||
job, err := createValidTemplateVersion(inv, createValidTemplateVersionArgs{ | ||
Name: versionName, | ||
Message: message, | ||
Client: client, | ||
Organization: organization, | ||
Provisioner: database.ProvisionerType(provisioner), | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -477,6 +477,7 @@ func TemplateVersion(t testing.TB, db database.Store, orig database.TemplateVers | ||
CreatedAt: takeFirst(orig.CreatedAt, database.Now()), | ||
UpdatedAt: takeFirst(orig.UpdatedAt, database.Now()), | ||
Name: takeFirst(orig.Name, namesgenerator.GetRandomName(1)), | ||
Message: orig.Message, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. nit: what about testing? do we need a random message generated for unit tests or maybe benchmarks in the future? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. It's a valid concern, although I didn't do it because I'm sure how we'd set an empty message if we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. @mafredri the empty | ||
Readme: takeFirst(orig.Readme, namesgenerator.GetRandomName(1)), | ||
JobID: takeFirst(orig.JobID, uuid.New()), | ||
CreatedBy: takeFirst(orig.CreatedBy, uuid.New()), | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE template_versions DROP COLUMN message; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ALTER TABLE template_versions ADD COLUMN message varchar(1048576) NOT NULL DEFAULT ''; | ||
COMMENT ON COLUMN template_versions.message IS 'Message describing the changes in this version of the template, similar to a Git commit message. Like a commit message, this should be a short, high-level description of the changes in this version of the template. This message is immutable and should not be updated after the fact.'; |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.