octopush/cmd/kraken/commands/process.go

54 lines
1006 B
Go
Raw Normal View History

package commands
import (
"bytes"
"encoding/json"
"net/http"
"github.com/spf13/cobra"
)
func CreateKrakenProcessCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "process",
Run: func(cmd *cobra.Command, _ []string) {
client := http.Client{}
var buf bytes.Buffer
err := json.NewEncoder(&buf).
Encode(struct {
2022-09-13 22:54:49 +02:00
Repository string `json:"repository"`
Branch string `json:"branch"`
Path string `json:"path"`
}{
2022-09-13 22:54:49 +02:00
Repository: "git@git.front.kjuulh.io:kjuulh/kraken.git",
2022-09-18 15:48:58 +02:00
Branch: "feature/query-results",
2022-09-18 15:49:29 +02:00
Path: "_examples/queries/scrape_readme/",
2022-09-13 22:54:49 +02:00
})
if err != nil {
panic(err)
}
req, err := http.NewRequestWithContext(
cmd.Context(),
http.MethodPost,
"http://localhost:3000/commands/processRepos",
&buf,
)
if err != nil {
panic(err)
}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
if resp.StatusCode >= 300 {
panic(resp.Status)
}
},
}
return cmd
}