MCPcopy
hub / github.com/stephengpope/thepopebot / fetchAgentJobLog

Function fetchAgentJobLog

lib/tools/github.js:158–177  ·  view source on GitHub ↗

* Fetch the session log (.jsonl) for an agent job from the GitHub repo at a specific commit. * @param {string} agentJobId - The agent job ID (used to locate logs/{agentJobId}/) * @param {string} commitSha - Git commit SHA to read from * @returns {Promise } - Log content or empty string if

(agentJobId, commitSha)

Source from the content-addressed store, hash-verified

156 * @returns {Promise<string>} - Log content or empty string if unavailable
157 */
158async function fetchAgentJobLog(agentJobId, commitSha) {
159 if (!commitSha) return '';
160 const { GH_OWNER, GH_REPO } = process.env;
161 try {
162 const files = await githubApi(
163 `/repos/${GH_OWNER}/${GH_REPO}/contents/logs/${agentJobId}?ref=${encodeURIComponent(commitSha)}`
164 );
165 if (!Array.isArray(files)) return '';
166 const logFile = files.find(f => f.name.endsWith('.jsonl'));
167 if (!logFile || !logFile.download_url) return '';
168 const res = await fetch(logFile.download_url, {
169 headers: { 'Authorization': `Bearer ${getConfig('GH_TOKEN')}` },
170 });
171 if (!res.ok) return '';
172 return await res.text();
173 } catch (err) {
174 console.error('Failed to fetch agent job log:', err.message);
175 return '';
176 }
177}
178
179/**
180 * Fetch open pull requests for the repository.

Callers 1

handleGithubWebhookFunction · 0.90

Calls 2

getConfigFunction · 0.90
githubApiFunction · 0.85

Tested by

no test coverage detected