2020-02-12 22:54:25 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
|
|
|
var testingToken = ""
|
|
|
|
|
2024-06-05 17:36:34 +00:00
|
|
|
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 {
|
2024-06-05 17:36:34 +00:00
|
|
|
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{}
|
2024-06-05 17:36:34 +00:00
|
|
|
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
|
|
|
|
}
|