Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/github/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 20 additions & 0 deletions pkg/github/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"

"github.com/github/github-mcp-server/internal/toolsnaps"
Expand Down Expand Up @@ -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)

Expand Down
Loading