Skip to content

Commit 0b82c43

Browse files
authored
Merge pull request AcalephStorage#66 from AcalephStorage/release/0.1.5
Release/0.1.5
2 parents 845ace8 + 9cc4d58 commit 0b82c43

File tree

8 files changed

+415
-102
lines changed

8 files changed

+415
-102
lines changed

api/stage.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ func (s *StageResource) extend(ws *restful.WebService) {
4949
Param(ws.PathParameter("repo", "repository name").DataType("string")).
5050
Param(ws.PathParameter("buildNumber", "build number").DataType("int")).
5151
Param(ws.PathParameter("stageIndex", "stage index").DataType("int")).
52+
Param(ws.QueryParameter("continue", "continue to next stage").DataType("string")).
5253
Reads(ps.StatusUpdate{}).
53-
Writes(ps.Stage{}))
54+
Writes(ps.StatusUpdate{}))
5455

5556
ws.Route(ws.POST("/{owner}/{repo}/builds/{buildNumber}/stages/{stageIndex}/run").To(s.run).
5657
Doc("Run build at given stage").
@@ -184,6 +185,7 @@ func (s *StageResource) update(req *restful.Request, res *restful.Response) {
184185
repo := req.PathParameter("repo")
185186
buildNumber := req.PathParameter("buildNumber")
186187
stageIndex := req.PathParameter("stageIndex")
188+
cont := req.QueryParameter("continue")
187189

188190
pipeline, build, stage, err := s.fetchResources(owner, repo, buildNumber, stageIndex)
189191
if err != nil {
@@ -204,19 +206,48 @@ func (s *StageResource) update(req *restful.Request, res *restful.Response) {
204206
return
205207
}
206208

209+
if stage.Type == "wait" {
210+
switch cont {
211+
case "yes":
212+
status.Status = ps.BuildSuccess
213+
status.Timestamp = time.Now().UnixNano()
214+
default:
215+
return
216+
}
217+
}
218+
207219
nextStage, err := stage.UpdateStatus(status, pipeline, build, s.KVClient, client)
220+
208221
if err != nil {
209-
jsonError(res, http.StatusBadRequest, err, "Unable to update stage status")
222+
jsonError(res, http.StatusInternalServerError, err, "Unable to update stage status")
223+
return
224+
}
225+
226+
if nextStage != nil && nextStage.Type == "wait" {
227+
status = new(ps.StatusUpdate)
228+
status.Timestamp = time.Now().UnixNano()
229+
status.Status = ps.BuildWaiting
230+
status.Message = "Do you want to continue? "
231+
if len(nextStage.Params) > 0 && nextStage.Params["message"].(string) != " " {
232+
status.Message = nextStage.Params["message"].(string)
233+
}
234+
235+
_, err := nextStage.UpdateStatus(status, pipeline, build, s.KVClient, client)
236+
if err != nil {
237+
jsonError(res, http.StatusInternalServerError, err, "Unable to update stage status")
238+
}
239+
res.WriteHeaderAndEntity(http.StatusOK, status)
210240
return
211241
}
212242

213243
if nextStage != nil {
214244
if err, msg := s.runStage(pipeline, build, nextStage, client); err != nil {
215245
jsonError(res, http.StatusInternalServerError, err, msg)
216246
}
247+
217248
}
218249

219-
res.WriteHeader(http.StatusOK)
250+
res.WriteHeaderAndEntity(http.StatusOK, nil)
220251
}
221252

222253
func (s *StageResource) fetchResources(owner, repo, buildNumber, stageIndex string) (*ps.Pipeline, *ps.Build, *ps.Stage, error) {

cli/cli.go

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,43 @@ func main() {
172172

173173
Action: initialize,
174174
},
175+
{
176+
Name: "describe",
177+
Subcommands: []cli.Command{
178+
{
179+
Name: "pipeline",
180+
Usage: "display pipeline latest build information",
181+
ArgsUsage: "[pipeline-name]",
182+
Before: func(c *cli.Context) error {
183+
p := strings.TrimSpace(c.Args().First())
184+
if len(p) > 0 {
185+
return requireNameArg(c)
186+
}
187+
return nil
188+
},
189+
Action: getLatestBuild,
190+
},
191+
},
192+
},
193+
{
194+
Name: "resume",
195+
Usage: "resume pipeline builds",
196+
ArgsUsage: "[pipeline-name]",
197+
Flags: []cli.Flag{
198+
cli.IntFlag{
199+
Name: "build, b",
200+
Usage: "Required, Pipeline build number you want to resume",
201+
},
202+
},
203+
Before: func(c *cli.Context) error {
204+
p := strings.TrimSpace(c.Args().First())
205+
if len(p) > 0 {
206+
return requireNameArg(c)
207+
}
208+
return nil
209+
},
210+
Action: resumeBuild,
211+
},
175212
}
176213
app.Run(os.Args)
177214
}
@@ -275,6 +312,48 @@ func getBuilds(c *cli.Context) {
275312
fmt.Println(table)
276313
}
277314

315+
func getLatestBuild(c *cli.Context) {
316+
config, err := apiReq.GetConfigFromFile(c.GlobalString("conf"))
317+
if err != nil {
318+
os.Exit(1)
319+
}
320+
321+
owner, repo, _ := parseNameArg(c.Args().First())
322+
pipelineName := fmt.Sprintf("%s/%s", owner, repo)
323+
324+
pipeline, err := config.GetPipeline(http.DefaultClient, pipelineName)
325+
if err != nil {
326+
fmt.Printf("Pipeline %s doesn't exist \n", pipelineName)
327+
os.Exit(1)
328+
}
329+
330+
stages, _ := config.GetStages(http.DefaultClient, owner, repo, pipeline.LatestBuild.Number)
331+
332+
table := uitable.New()
333+
table.Wrap = true
334+
335+
if pipeline.LatestBuild == nil {
336+
table.AddRow("No available builds for pipeline", pipelineName)
337+
fmt.Println(table)
338+
os.Exit(1)
339+
}
340+
341+
started := time.Unix(0, pipeline.LatestBuild.Created).Format(time.RFC3339)
342+
finished := time.Unix(0, pipeline.LatestBuild.Finished).Format(time.RFC3339)
343+
344+
table.AddRow("")
345+
table.AddRow("Name:", pipelineName)
346+
table.AddRow("Build No:", pipeline.LatestBuild.Number)
347+
table.AddRow("Status:", pipeline.LatestBuild.Status)
348+
table.AddRow("Author:", pipeline.LatestBuild.Author)
349+
table.AddRow("Started:", started)
350+
table.AddRow("Finished:", finished)
351+
table.AddRow("No of Stages:", len(stages))
352+
table.AddRow("")
353+
fmt.Println(table)
354+
355+
}
356+
278357
func getStages(c *cli.Context) {
279358
config, err := apiReq.GetConfigFromFile(c.GlobalString("conf"))
280359
if err != nil {
@@ -338,8 +417,6 @@ func createBuild(c *cli.Context) {
338417

339418
if err != nil {
340419
fmt.Println(err)
341-
} else {
342-
fmt.Printf("building pipeline %s/%s ", owner, repo)
343420
}
344421
}
345422

@@ -434,3 +511,24 @@ func removeDeployedApp(c *cli.Context) {
434511

435512
fmt.Println("Success! Kontinuous resources has been removed from the cluster. ")
436513
}
514+
515+
func resumeBuild(c *cli.Context) {
516+
config, err := apiReq.GetConfigFromFile(c.GlobalString("conf"))
517+
if err != nil {
518+
os.Exit(1)
519+
}
520+
owner, repo, _ := parseNameArg(c.Args().First())
521+
buildNo := c.Int("build")
522+
523+
if owner == "" || repo == "" || buildNo == 0 {
524+
fmt.Println("Missing fields.")
525+
os.Exit(1)
526+
}
527+
528+
err = config.ResumeBuild(http.DefaultClient, owner, repo, buildNo)
529+
530+
if err != nil {
531+
fmt.Println(err)
532+
os.Exit(1)
533+
}
534+
}

0 commit comments

Comments
 (0)