refactor: cut remaining long comments down to what the code does
This commit is contained in:
1 parent
0cbb65c684
commit
cb6b8618c2
141 files changed
+610
-2622
No files matched your search
@@ -12,14 +12,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// extractTarGz extracts a gzipped tar stream into destDir, stripping a single
|
||||
// common leading path component when every entry shares one (the wrapper
|
||||
// directory GitHub's and Gitea's repository archives both add, named after the
|
||||
// repo and ref -- e.g. "acme-widget-deadbeef/"). A.git entry is never written:
|
||||
// PRSource's isolation contract requires the pipeline to read a.git-free
|
||||
// snapshot, and a malicious PR's own tarball is exactly the input this cannot
|
||||
// trust, so an entry escaping destDir via ".." or an absolute path is refused
|
||||
// rather than silently written outside it.
|
||||
// extractTarGz extracts a .tar.gz into destDir, stripping a common top-level
|
||||
// directory. It skips .git and refuses paths escaping destDir.
|
||||
func extractTarGz(r io.Reader, destDir string) error {
|
||||
gz, err := gzip.NewReader(r)
|
||||
if err != nil {
|
||||
@@ -73,11 +67,7 @@ func planExtraction(tr *tar.Reader) (prefix string, entries []tarEntry, err erro
|
||||
top, _, hasSlash := strings.Cut(name, "/")
|
||||
switch {
|
||||
case !hasSlash && hdr.Typeflag != tar.TypeDir:
|
||||
// A bare top-level file (no directory component at all) proves
|
||||
// there is no single wrapper directory containing everything. A
|
||||
// bare top-level *directory* entry is not this evidence -- it is
|
||||
// exactly the wrapper directory's own header, which real
|
||||
// archives include alongside the files nested under it.
|
||||
// A top-level file means there is no wrapper directory.
|
||||
commonPrefix = ""
|
||||
first = false
|
||||
case first:
|
||||
@@ -99,11 +89,8 @@ func planExtraction(tr *tar.Reader) (prefix string, entries []tarEntry, err erro
|
||||
return commonPrefix, entries, nil
|
||||
}
|
||||
|
||||
// writeEntry writes one archive entry under destDir, with prefix (if any)
|
||||
// stripped from its name. destDir is the absolute destination directory
|
||||
// resolved by extractTarGz. Directories, regular files, and nothing else
|
||||
// are written: a symlink or device entry from an untrusted PR archive is
|
||||
// skipped rather than followed.
|
||||
// writeEntry writes one directory or regular file under destDir; other
|
||||
// entry types are skipped.
|
||||
func writeEntry(destDir, prefix string, e tarEntry) error {
|
||||
name := path.Clean(filepath.ToSlash(e.header.Name))
|
||||
if name == "." || name == prefix {
|
||||
|
||||
@@ -17,21 +17,12 @@ import (
|
||||
// package's reader cannot drift into two different paths.
|
||||
const PrefetchDirName = ".archie-pr-review"
|
||||
|
||||
// MountSource implements workflow.PRSource by reading data the daemon
|
||||
// already fetched and wrote to disk before the container started, instead of
|
||||
// calling the forge itself. This is how the sandboxed pipeline gets pull
|
||||
// request data with no forge credential ever entering the container: the
|
||||
// daemon (which holds the credential) runs Source (this package's
|
||||
// HTTP-backed implementation) against baseDir before handing the container
|
||||
// off, and the pipeline's Stage.Run bodies read the result through
|
||||
// MountSource instead.
|
||||
//
|
||||
// baseDir holds three artifacts, all written by prefetchTo (the daemon-side
|
||||
// counterpart, in internal/daemon):
|
||||
// MountSource implements workflow.PRSource from data the daemon prefetched
|
||||
// into baseDir:
|
||||
//
|
||||
// metadata.json -- {"title", "body", "head_sha"}
|
||||
// diff.patch -- the raw unified diff
|
||||
// snapshot/ -- the extracted repository tree at head_sha
|
||||
// diff.patch -- the unified diff
|
||||
// snapshot/ -- the repository tree at head_sha
|
||||
type MountSource struct {
|
||||
baseDir string
|
||||
}
|
||||
@@ -81,11 +72,8 @@ func (s *MountSource) Diff(_ context.Context, _, _ string, _ int) (string, error
|
||||
return string(data), nil
|
||||
}
|
||||
|
||||
// Snapshot copies the prefetched snapshot tree into destDir and returns the
|
||||
// head SHA it was measured against. This is a local filesystem copy inside
|
||||
// the same container -- no network call, no credential -- since the daemon
|
||||
// already extracted the archive into baseDir/snapshot before the container
|
||||
// started.
|
||||
// Snapshot copies the prefetched snapshot into destDir and returns its head
|
||||
// SHA.
|
||||
func (s *MountSource) Snapshot(_ context.Context, _, _ string, _ int, destDir string) (string, error) {
|
||||
m, err := s.readMetadata()
|
||||
if err != nil {
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
// Package prsource implements workflow.PRSource: fetching an arbitrary
|
||||
// external pull request's metadata, diff and a read-only snapshot of its
|
||||
// head, for the pr-review pipeline. It is
|
||||
// the PR-under-review counterpart to worktree.Manager's use as the task's
|
||||
// own Trees: that path only ever reaches the task's own worktree, never a
|
||||
// third-party PR being reviewed.
|
||||
//
|
||||
// Every call goes over the forge's HTTP API -- never a git-shell checkout. The
|
||||
// pipeline's Stage.Run bodies execute inside the sandboxed archie-agent
|
||||
// process, which holds no forge credential and no git-level credential either;
|
||||
// a git clone would need one.
|
||||
// Package prsource fetches a pull request's metadata, diff and head snapshot
|
||||
// over the forge HTTP API.
|
||||
package prsource
|
||||
|
||||
import (
|
||||
@@ -19,11 +10,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
)
|
||||
|
||||
// PullRequest is the pull request fields Metadata, Diff and Snapshot need:
|
||||
// title, body, and the head commit SHA the diff's line numbers and the
|
||||
// snapshot are both measured against. It mirrors forge.PullRequest's shape
|
||||
// so callers can pass that type directly without this package importing
|
||||
// internal/forge.
|
||||
// PullRequest is the PR's title, body and head SHA.
|
||||
type PullRequest struct {
|
||||
Title string
|
||||
Body string
|
||||
|
||||
Reference in new issue
Block a user