fix(actions): avoid malformed response on log download failure
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9cdeefb9-91cd-4f65-8eb2-089c9e00a2b8
This commit is contained in:
@@ -146,11 +146,11 @@ func getJobLogData(ctx context.Context, client *github.Client, owner, repo strin
|
||||
// Download and return the actual log content
|
||||
content, originalLength, httpResp, err := downloadLogContent(ctx, url.String(), tailLines, contentWindowSize) //nolint:bodyclose // Response body is closed in downloadLogContent, but we need to return httpResp
|
||||
if err != nil {
|
||||
// To keep the return value consistent wrap the response as a GitHub Response
|
||||
ghRes := &github.Response{
|
||||
Response: httpResp,
|
||||
var ghResp *github.Response
|
||||
if httpResp != nil {
|
||||
ghResp = &github.Response{Response: httpResp}
|
||||
}
|
||||
return nil, ghRes, fmt.Errorf("failed to download log content for job %d: %w", jobID, err)
|
||||
return nil, ghResp, fmt.Errorf("failed to download log content for job %d: %w", jobID, err)
|
||||
}
|
||||
result["logs_content"] = content
|
||||
result["message"] = "Job logs content retrieved successfully"
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/github/github-mcp-server/internal/toolsnaps"
|
||||
@@ -624,6 +625,25 @@ func Test_ActionsGetJobLogs_SingleJob(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetJobLogData_DownloadTransportErrorReturnsNilResponse(t *testing.T) {
|
||||
logServer := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
|
||||
logURL := logServer.URL
|
||||
logServer.Close()
|
||||
|
||||
client := mustNewGHClient(t, MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
|
||||
GetReposActionsJobsLogsByOwnerByRepoByJobID: func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Header().Set("Location", logURL)
|
||||
w.WriteHeader(http.StatusFound)
|
||||
},
|
||||
}))
|
||||
|
||||
_, resp, err := getJobLogData(t.Context(), client, "owner", "repo", 123, "", true, 100, 5000)
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, resp)
|
||||
assert.Contains(t, err.Error(), "failed to download log content for job 123")
|
||||
}
|
||||
|
||||
func Test_ActionsGetJobLogs_FailedJobs(t *testing.T) {
|
||||
toolDef := ActionsGetJobLogs(translations.NullTranslationHelper)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user