src/actions.ts — downloadJobLog (cache-first, attempt param) #115
Labels
No labels
bug
chore
documentation
enhancement
feature
ready
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
david/pi-extensions-and-skills#115
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
downloadJobLog()insrc/actions.ts: cache-first download of a single job's log (GET /repos/{owner}/{repo}/actions/jobs/{job_id}/logs?attempt=N), returning{path, sizeBytes, lineCount, cached}.Background
Part of the Forgejo Actions tooling feature (tracking issue #111 — branch
feature/issue-111/forgejo-actions-tools, commitsissue-111: ...). Builds on the cache module (#113) for path computation and cache-first read/write, and onforgejoApiCall()for HTTP. Powers theforgejo_action_job_logtool. Cache-first contract: if the computed cache path exists andrefreshis not set, return it without any network hit. Baseline is Forgejo v16 (?attempt=supported;?step=/?q=/?format=ndjsonare v17+ — out of scope).Documentation Required
docs/reference/forgejo-actions-api/(same folder as the metadata-queries step — already researched):read:repository).GET /repos/{owner}/{repo}/actions/jobs/{job_id}/logsdefinition incl. theattemptquery param and the response (plain-text log).A separate process downloads these into
docs/reference/forgejo-actions-api/before this issue is implemented. Check that folder for the actual reference material before starting.Implementation Details
downloadJobLog({host, owner, repo, runId, jobId, attempt?, refresh?}) -> Result<{path, sizeBytes, lineCount, cached}, ApiError>.cachedLogPath()(#113); if the file exists andrefreshis falsy → return{path, sizeBytes, lineCount, cached: true}immediately (no fetch).GET /repos/{owner}/{repo}/actions/jobs/{job_id}/logswithattemptappended when provided; write viawriteLog()(#113); return{path, sizeBytes, lineCount, cached: false}.lineCount= number of lines in the log (split on\n); compute after write (cheap for typical logs).ApiErrorwith actionable text (per the existing friendly-error pattern).Acceptance Criteria
refresh) returns the cached file without callingfetch(assert via mocked fetch — fetch must not be invoked).cached: falsewith correctsizeBytes/lineCount.refresh: truere-fetches and overwrites even when the path exists.attemptis included in the query string and in the cache key (path).ApiErrorwith actionable messages.os.tmpdir()subdir.npm run checkpasses.Test Plan
cd extensions/forgejo && npm test— new cases intests/actions.test.ts.forgejo_action_job_log run_id=... job_id=..., then again — second call returnscached: truewith no network; passrefresh: trueafter a workflow re-run and confirm re-download; verifyattempt=2fetches the second attempt's log.pi-loop opened and merged a pull request for this issue: #127