github-vet / github-vet/rangeloop-pointer-findings

gardener/test-infra: pkg/tm-bot/ui/pages/runs.go; 44 LoC

Open
#16,218 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [gardener/test-infra](https://www.github.com/gardener/test-infra) at [pkg/tm-bot/ui/pages/runs.go](https://github.com/gardener/test-infra/blob/90111f7e68bb1b76bf3b3c8c7e04d7d187a83ead/pkg/tm-bot/ui/pages/runs.go#L91-L134)

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.

> reference to tr was used in a composite literal at line 116

[Click here to see the code in its original context.](https://github.com/gardener/test-infra/blob/90111f7e68bb1b76bf3b3c8c7e04d7d187a83ead/pkg/tm-bot/ui/pages/runs.go#L91-L134)

Click here to show the 44 line(s) of Go which triggered the analyzer.

```go
for i, tr := range runs.Items {
testrun := tr

if rgName == "" {
runsList.Add(&testrun)
}
metadata := tmetadata.FromTestrun(&tr)
startTime := ""
if tr.Status.StartTime != nil {
startTime = tr.Status.StartTime.Format(time.RFC822)
}

d := time.Duration(tr.Status.Duration) * time.Second
if tr.Status.Duration == 0 && !tr.Status.StartTime.IsZero() {
d = time.Now().Sub(tr.Status.StartTime.Time)
d = d / time.Second * time.Second // remove unnecessary milliseconds
}

testrunsList[i] = testrunItem{
testrun: &testrun,
ID: tr.GetName(),
Namespace: tr.GetNamespace(),
Phase: PhaseIcon(tr.Status.Phase),
StartTime: startTime,
Duration: d.String(),
Progress: util.TestrunProgress(&tr),
Dimension: metadata.GetDimensionFromMetadata("/"),
}
if retries, ok := tr.Annotations[common.AnnotationRetries]; ok {
testrunsList[i].Retries = retries
}
if prevAttempt, ok := tr.Annotations[common.AnnotationPreviousAttempt]; ok {
testrunsList[i].PreviousAttempt = prevAttempt
}
if runID, ok := tr.Labels[common.LabelTestrunExecutionGroup]; ok {
testrunsList[i].RunID = runID
}
if argoHostURL != "" {
testrunsList[i].ArgoURL = testrunner.GetArgoURLFromHost(argoHostURL, &tr)
}
if grafanaHostURL != "" {
testrunsList[i].GrafanaURL = testrunner.GetGrafanaURLFromHostForWorkflow(grafanaHostURL, tr.Status.Workflow)
}
}

```

Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.

commit ID: 90111f7e68bb1b76bf3b3c8c7e04d7d187a83ead

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.