MCPcopy Create free account
hub / github.com/alibaba/open-code-review / execute

Method execute

internal/tool/code_access.go:36–67  ·  view source on GitHub ↗
(ctx context.Context, args map[string]any, current *FileReader, run func(*FileReader) (string, error))

Source from the content-addressed store, hash-verified

34}
35
36func (access *CodeAccess) execute(ctx context.Context, args map[string]any, current *FileReader, run func(*FileReader) (string, error)) (string, error) {
37 rawSide, supplied := args["side"]
38 if access == nil {
39 if supplied {
40 return "", fmt.Errorf("side is not supported for this task")
41 }
42 return run(current)
43 }
44 side := "new"
45 if supplied {
46 var valid bool
47 side, valid = rawSide.(string)
48 if !valid || (side != "new" && side != "old") {
49 return "", fmt.Errorf("side must be new or old")
50 }
51 }
52 if side == "new" {
53 return run(&access.newReader)
54 }
55 prefix := "SIDE: old\nREVISION: " + access.oldReader.Ref + "\n"
56 if access.oldReader.Mode == ModeEmpty {
57 prefix = "SIDE: old\nSOURCE: empty-tree\n"
58 }
59 if err := ctx.Err(); err != nil {
60 return "", fmt.Errorf("%s%w", prefix, err)
61 }
62 content, err := run(&access.oldReader)
63 if err != nil {
64 return "", fmt.Errorf("%s%w", prefix, err)
65 }
66 return prefix + content, nil
67}

Callers

nothing calls this directly

Calls 2

runFunction · 0.50
ErrMethod · 0.45

Tested by

no test coverage detected