shad-go/tools/testtool/commands/report.go

46 lines
809 B
Go
Raw Normal View History

2020-02-12 22:54:25 +00:00
package commands
import (
"fmt"
"log"
"net/http"
"net/url"
)
var testingToken = ""
const reportEndpoint = "https://go.manytask.org/api/report"
2020-02-12 22:54:25 +00:00
func reportTestResults(token string, task string, userID string, failed bool) error {
if failed {
// TODO: see how to report failed submit to new manytask
return nil
}
2020-02-12 22:54:25 +00:00
form := url.Values{}
form.Set("token", "x "+token)
2020-02-12 22:54:25 +00:00
form.Set("task", task)
form.Set("user_id", userID)
var rsp *http.Response
var err error
for i := 0; i < 3; i++ {
rsp, err = http.PostForm(reportEndpoint, form)
if err != nil {
log.Printf("retrying report: %v", err)
continue
}
if rsp.StatusCode != 200 {
err = fmt.Errorf("server returned status %d", rsp.StatusCode)
log.Printf("retrying report: %v", err)
continue
}
return nil
}
return err
}