MCPcopy Index your code
hub / github.com/github/github-mcp-server / getJobLogData

Function getJobLogData

pkg/github/actions.go:130–166  ·  view source on GitHub ↗

getJobLogData retrieves log data for a single job, either as URL or content

(ctx context.Context, client *github.Client, owner, repo string, jobID int64, jobName string, returnContent bool, tailLines int, contentWindowSize int)

Source from the content-addressed store, hash-verified

128
129// getJobLogData retrieves log data for a single job, either as URL or content
130func getJobLogData(ctx context.Context, client *github.Client, owner, repo string, jobID int64, jobName string, returnContent bool, tailLines int, contentWindowSize int) (map[string]any, *github.Response, error) {
131 // Get the download URL for the job logs
132 url, resp, err := client.Actions.GetWorkflowJobLogs(ctx, owner, repo, jobID, 1)
133 if err != nil {
134 return nil, resp, fmt.Errorf("failed to get job logs for job %d: %w", jobID, err)
135 }
136 defer func() { _ = resp.Body.Close() }()
137
138 result := map[string]any{
139 "job_id": jobID,
140 }
141 if jobName != "" {
142 result["job_name"] = jobName
143 }
144
145 if returnContent {
146 // Download and return the actual log content
147 content, originalLength, httpResp, err := downloadLogContent(ctx, url.String(), tailLines, contentWindowSize) //nolint:bodyclose // Response body is closed in downloadLogContent, but we need to return httpResp
148 if err != nil {
149 // To keep the return value consistent wrap the response as a GitHub Response
150 ghRes := &github.Response{
151 Response: httpResp,
152 }
153 return nil, ghRes, fmt.Errorf("failed to download log content for job %d: %w", jobID, err)
154 }
155 result["logs_content"] = content
156 result["message"] = "Job logs content retrieved successfully"
157 result["original_length"] = originalLength
158 } else {
159 // Return just the URL
160 result["logs_url"] = url.String()
161 result["message"] = "Job logs are available for download"
162 result["note"] = "The logs_url provides a download link for the individual job logs in plain text format. Use return_content=true to get the actual log content."
163 }
164
165 return result, resp, nil
166}
167
168func downloadLogContent(ctx context.Context, logURL string, tailLines int, maxLines int) (string, int, *http.Response, error) {
169 prof := profiler.New(nil, profiler.IsProfilingEnabled())

Callers 2

handleFailedJobLogsFunction · 0.85
handleSingleJobLogsFunction · 0.85

Calls 3

downloadLogContentFunction · 0.85
CloseMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected