Skip to content

Commit 75cab36

Browse files
committed
Fix bug and test
1 parent bf5ccf8 commit 75cab36

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

routers/common/actions.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,8 @@ func DownloadActionsRunJobLogs(ctx *context.Base, ctxRepo *repo_model.Repository
3939
}
4040

4141
var curJob *actions_model.ActionRunJob
42-
for _, job := range runJobs {
43-
if job.ID == jobIndex {
44-
curJob = job
45-
break
46-
}
42+
if jobIndex >= 0 && jobIndex < int64(len(runJobs)) {
43+
curJob = runJobs[jobIndex]
4744
}
4845
if curJob == nil {
4946
ctx.HTTPError(http.StatusNotFound)

tests/integration/actions_log_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"net/http"
99
"net/url"
10+
"strconv"
1011
"strings"
1112
"testing"
1213
"time"
@@ -149,8 +150,9 @@ jobs:
149150
)
150151
}
151152

153+
runID, _ := strconv.ParseInt(task.Context.GetFields()["run_id"].GetStringValue(), 10, 64)
152154
// download task logs from API and check content
153-
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/actions/runs/%s/jobs/0/logs", user2.Name, repo.Name, runIndex)).
155+
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/actions/runs/%d/jobs/0/logs", user2.Name, repo.Name, runID)).
154156
AddTokenAuth(token)
155157
resp = MakeRequest(t, req, http.StatusOK)
156158
logTextLines = strings.Split(strings.TrimSpace(resp.Body.String()), "\n")

0 commit comments

Comments
 (0)