MCPcopy Index your code
hub / github.com/aptly-dev/aptly / apiGraph

Function apiGraph

api/graph.go:36–94  ·  view source on GitHub ↗

@Summary Graph Output @Description **Generate dependency graph** @Description @Description Command graph generates graph of dependencies: @Description @Description * between snapshots and mirrors (what mirror was used to create each snapshot) @Description * between snapshots and local repos (what lo

(c *gin.Context)

Source from the content-addressed store, hash-verified

34// @Failure 500 {object} Error "Internal Server Error"
35// @Router /api/graph.{ext} [get]
36func apiGraph(c *gin.Context) {
37 var (
38 err error
39 output []byte
40 )
41
42 ext := c.Params.ByName("ext")
43 layout := c.Request.URL.Query().Get("layout")
44 factory := context.NewCollectionFactory()
45
46 graph, err := deb.BuildGraph(factory, layout)
47 if err != nil {
48 c.JSON(500, err)
49 return
50 }
51
52 buf := bytes.NewBufferString(graph.String())
53
54 if ext == "dot" || ext == "gv" {
55 // If the raw dot data is requested, return it as string.
56 // This allows client-side rendering rather than server-side.
57 c.String(200, buf.String())
58 return
59 }
60
61 command := exec.Command("dot", "-T"+ext)
62 command.Stderr = os.Stderr
63
64 stdin, err := command.StdinPipe()
65 if err != nil {
66 AbortWithJSONError(c, 500, err)
67 return
68 }
69
70 _, err = io.Copy(stdin, buf)
71 if err != nil {
72 AbortWithJSONError(c, 500, err)
73 return
74 }
75
76 err = stdin.Close()
77 if err != nil {
78 AbortWithJSONError(c, 500, err)
79 return
80 }
81
82 output, err = command.Output()
83 if err != nil {
84 AbortWithJSONError(c, 500, fmt.Errorf("unable to execute dot: %s (is graphviz package installed?)", err))
85 return
86 }
87
88 mimeType := mime.TypeByExtension("." + ext)
89 if mimeType == "" {
90 mimeType = "application/octet-stream"
91 }
92
93 c.Data(200, mimeType, output)

Callers

nothing calls this directly

Calls 9

BuildGraphFunction · 0.92
AbortWithJSONErrorFunction · 0.85
NewCollectionFactoryMethod · 0.80
GetMethod · 0.65
QueryMethod · 0.65
StringMethod · 0.65
CloseMethod · 0.65
ByNameMethod · 0.45
CopyMethod · 0.45

Tested by

no test coverage detected