Skip to content

Commit

Permalink
[062101] ♻️ for pipeline/list
Browse files Browse the repository at this point in the history
  • Loading branch information
daijinru committed Jun 29, 2024
1 parent 40b928e commit 9d5239b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 3 additions & 2 deletions http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,15 @@ type PipelinesReply struct {

// ReadPipelines Gets all pipeline files by the path passing.
func (Cis *CiService) ReadPipelines(w http.ResponseWriter, r *http.Request) {
workspace, err := runner.NewWorkSpace(r.FormValue("path"))
name := r.FormValue("name")
workspace, err := runner.NewWorkSpace(name)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}

pipeline, err := runner.NewPipeline(&runner.PipelineArgs{
Tag: r.FormValue("tag"),
Tag: name,
Path: workspace.CWD,
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion http_test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ curl -X POST -d "name=mango" -d "filename=mango_20240629_113957.txt" http://loca

pipeline list:
```bash
curl -X POST -d "path=/datas/mango-runner" -d "tag=mango" http://localhost:1234/pipeline/list
curl -X POST -d "name=mango" http://localhost:1234/pipeline/list
```

Is service healthy?
Expand Down
15 changes: 8 additions & 7 deletions runner/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,21 @@ func (pip *Pipeline) ReadDir() ([]string, error) {
}
filenames = append(filenames, file.Name())
}
sort.Slice(filenames, func(i, j int) bool {
file1 := filepath.Join(pip.Directory, filenames[i])
file2 := filepath.Join(pip.Directory, filenames[j])
info1, _ := os.Stat(file1)
info2, _ := os.Stat(file2)
return info1.ModTime().Before(info2.ModTime())
})

filteredFilenames := make([]string, 0)
for _, filename := range filenames {
if strings.Contains(filename, pip.Tag) {
filteredFilenames = append(filteredFilenames, filename)
}
}

sort.Slice(filteredFilenames, func(i, j int) bool {
file1 := filepath.Join(pip.Directory, filenames[i])
file2 := filepath.Join(pip.Directory, filenames[j])
info1, _ := os.Stat(file1)
info2, _ := os.Stat(file2)
return info1.ModTime().Before(info2.ModTime())
})
return filteredFilenames, nil
}

Expand Down

0 comments on commit 9d5239b

Please sign in to comment.