New UpTo parameter to reduce grade accordingly
This commit is contained in:
parent
07ceb20d63
commit
f7da603dbe
20
gradation.go
20
gradation.go
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -38,10 +39,11 @@ type TestsWebhook struct {
|
||||
Login string `json:"login"`
|
||||
RepositoryId int `json:"repository_id"`
|
||||
BuildNumber int `json:"build_number"`
|
||||
UpTo float64 `json:"upto"`
|
||||
Steps map[string]float64 `json:"steps,omitempty"`
|
||||
}
|
||||
|
||||
func (r *Repository) fetchRepoTests(build_number int, steps map[string]float64) error {
|
||||
func (tw *TestsWebhook) fetchRepoTests(r *Repository) error {
|
||||
tmp := strings.Split(r.TestsRef, "/")
|
||||
if len(tmp) < 3 {
|
||||
return fmt.Errorf("This repository tests reference is not filled properly.")
|
||||
@ -53,9 +55,9 @@ func (r *Repository) fetchRepoTests(build_number int, steps map[string]float64)
|
||||
}
|
||||
|
||||
client := drone.NewClient(droneEndpoint, droneConfig)
|
||||
result, err := client.Build(tmp[0], tmp[1], build_number)
|
||||
result, err := client.Build(tmp[0], tmp[1], tw.BuildNumber)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to find the referenced build (%d): %w", build_number, err)
|
||||
return fmt.Errorf("Unable to find the referenced build (%d): %w", tw.BuildNumber, err)
|
||||
}
|
||||
|
||||
if result.Finished > 0 {
|
||||
@ -65,7 +67,7 @@ func (r *Repository) fetchRepoTests(build_number int, steps map[string]float64)
|
||||
var grade float64
|
||||
for _, stage := range result.Stages {
|
||||
for _, step := range stage.Steps {
|
||||
if g, ok := steps[fmt.Sprintf("%d", step.Number)]; ok {
|
||||
if g, ok := tw.Steps[fmt.Sprintf("%d", step.Number)]; ok {
|
||||
log.Printf("Step %q (%d) in status %q", step.Name, step.Number, step.Status)
|
||||
// Give the point if it succeed
|
||||
if step.Status == "success" {
|
||||
@ -74,7 +76,7 @@ func (r *Repository) fetchRepoTests(build_number int, steps map[string]float64)
|
||||
continue
|
||||
}
|
||||
|
||||
if g, ok := steps[step.Name]; ok {
|
||||
if g, ok := tw.Steps[step.Name]; ok {
|
||||
log.Printf("Step %q (%d) in status %q", step.Name, step.Number, step.Status)
|
||||
// Give the point if it succeed
|
||||
if step.Status == "success" {
|
||||
@ -83,9 +85,9 @@ func (r *Repository) fetchRepoTests(build_number int, steps map[string]float64)
|
||||
continue
|
||||
}
|
||||
|
||||
logs, err := client.Logs(tmp[0], tmp[1], build_number, stage.Number, step.Number)
|
||||
logs, err := client.Logs(tmp[0], tmp[1], tw.BuildNumber, stage.Number, step.Number)
|
||||
if err != nil {
|
||||
log.Printf("Unable to retrieve build logs %s/%s/%d/%d/%d: %s", tmp[0], tmp[1], build_number, stage.Number, step.Number, err.Error())
|
||||
log.Printf("Unable to retrieve build logs %s/%s/%d/%d/%d: %s", tmp[0], tmp[1], tw.BuildNumber, stage.Number, step.Number, err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
@ -105,6 +107,10 @@ func (r *Repository) fetchRepoTests(build_number int, steps map[string]float64)
|
||||
}
|
||||
}
|
||||
|
||||
if tw.UpTo != 0 {
|
||||
grade = math.Trunc(grade*2000/tw.UpTo) / 100
|
||||
}
|
||||
|
||||
work.AddGrade(WorkGrade{
|
||||
IdUser: r.IdUser,
|
||||
IdWork: work.Id,
|
||||
|
@ -470,7 +470,7 @@ func declareCallbacksRoutes(router *gin.RouterGroup) {
|
||||
return
|
||||
}
|
||||
|
||||
err = repo.fetchRepoTests(hook.BuildNumber, hook.Steps)
|
||||
err = hook.fetchRepoTests(repo)
|
||||
if err != nil {
|
||||
log.Printf("Unable to fetchRepoTests(%d): %s", hook.RepositoryId, err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to fetch tests results."})
|
||||
|
Reference in New Issue
Block a user