Skip to content

Commit ad25ac8

Browse files
author
Max Siegieda
authored
Add ability to set messages on build creation (#32)
* Add ability to set comments on build creation * message not comment * add header for message field in reco build list
1 parent cd3e1ee commit ad25ac8

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

build.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ type buildJob struct {
1515
*clientImpl
1616
}
1717

18-
func (b buildJob) prepareBuild() (string, error) {
18+
func (b buildJob) prepareBuild(message string) (string, error) {
1919
projectID, err := b.projectID()
2020
if err != nil {
2121
return "", err
2222
}
2323
req := b.apiRequest(endpoints.builds.String())
24-
reqBody := M{"project_id": projectID}
24+
reqBody := M{"project_id": projectID, "message": message}
2525
resp, err := req.Do("POST", reqBody)
2626
if err != nil {
2727
return "", err
@@ -39,9 +39,10 @@ func (b buildJob) prepareBuild() (string, error) {
3939
func (b buildJob) Start(args Args) (string, error) {
4040
srcDir := String(args.At(0))
4141
wait := Bool(args.At(1))
42+
message := String(args.At(2))
4243

4344
logger.Info.Println("preparing build")
44-
id, err := b.prepareBuild()
45+
id, err := b.prepareBuild(message)
4546
if err != nil {
4647
return "", err
4748
}
@@ -95,6 +96,7 @@ func (b buildJob) List(filter M) (printer.Table, error) {
9596
build.Status,
9697
buildTime,
9798
timeRounder(build.Duration).Nearest(time.Second),
99+
build.Message,
98100
}
99101
if allProjects {
100102
row = append(row, build.Project)
@@ -104,7 +106,7 @@ func (b buildJob) List(filter M) (printer.Table, error) {
104106
}
105107

106108
table = printer.Table{
107-
Header: []string{"build id", "status", "started", "duration"},
109+
Header: []string{"build id", "status", "started", "duration", "message"},
108110
Body: body,
109111
}
110112
if allProjects {

cmd/build.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import (
1313

1414
var (
1515
buildVars = struct {
16-
wait bool
17-
force bool
16+
wait bool
17+
force bool
18+
message string
1819
}{
1920
wait: true,
2021
}
@@ -74,6 +75,7 @@ var (
7475
func init() {
7576
buildCmdStart.PersistentFlags().BoolVarP(&buildVars.wait, "wait", "w", buildVars.wait, "Wait for the build to complete. If wait=false, logs will only be displayed up to where the build is started and assigned its unique ID. Use 'reco build list' to check the status of your builds")
7677
buildCmdStart.PersistentFlags().BoolVarP(&buildVars.force, "force", "f", buildVars.force, "Force a build to start. Ignore source code validation")
78+
buildCmdStart.PersistentFlags().StringVarP(&buildVars.message, "message", "m", buildVars.message, "Add a message to describe this build's purpose")
7779

7880
buildCmd := genDevCommand("build", "build", "b", "builds")
7981
buildCmd.AddCommand(genListSubcommand("builds", tool.Build()))
@@ -90,7 +92,7 @@ func startBuild(cmd *cobra.Command, args []string) {
9092
exitWithError(errInvalidSourceDirectory)
9193
}
9294

93-
id, err := tool.Build().Start(reco.Args{srcDir, buildVars.wait})
95+
id, err := tool.Build().Start(reco.Args{srcDir, buildVars.wait, buildVars.message})
9496
if err != nil {
9597
exitWithError(err)
9698
}

job.go

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type jobInfo struct {
5757
Command string
5858
Build string
5959
IPAddress string
60+
Message string
6061
}
6162

6263
// UnmarshalJSON customizes JSON decoding for BuildInfo.
@@ -77,6 +78,7 @@ func (ji *jobInfo) UnmarshalJSON(b []byte) error {
7778
ji.Project = str.Project.Name
7879
ji.Command = str.Command
7980
ji.IPAddress = str.IPAddress
81+
ji.Message = str.Message
8082
if str.Build.ID != "" {
8183
ji.Build = str.Build.ID
8284
}

request.go

+1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ type apiResponse struct {
174174
} `json:"build,omitempty"`
175175
// workaround for deployments
176176
// TODO: fix on platform
177+
Message string `json:"message"`
177178
Events []event `json:"events,omitempty"`
178179
Command string `json:"command,omitempty"`
179180
IPAddress string `json:"ip_address,omitempty"`

0 commit comments

Comments
 (0)