-
Notifications
You must be signed in to change notification settings - Fork 0
/
ghe_v3.3.go
76 lines (67 loc) · 1.68 KB
/
ghe_v3.3.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// SPDX-FileCopyrightText: 2022 Weston Schmidt <[email protected]>
// SPDX-License-Identifier: Apache-2.0
package githubfs
import (
"context"
"fmt"
"io/fs"
"strings"
)
// getGitDirV3_3 fetches a single directory via the github API. This isn't fast,
// but there are conditions where it is advantageous over fetching everything
// all at once.
//
// Github Enterprise v3.3 doesn't support size.
func getGitDirV3_3(gfs *FS, d *dir) error {
path := strings.Join(d.path, "/")
vars := map[string]any{
"owner": d.org,
"repo": d.repo,
"exp": d.branch + ":" + path,
}
/*
query {
repository(name: "repo", owner: "org") {
object(expression: "main:") {
... on Tree {
entries {
name
mode
}
}
}
}
}
*/
var query struct {
Repository struct {
Object struct {
Tree struct {
Entries []struct {
Name string
Mode int
}
} `graphql:"... on Tree"`
} `graphql:"object(expression: $exp)"`
} `graphql:"repository(name: $repo, owner: $owner)"`
}
if err := gfs.gqlClient.Query(context.Background(), &query, vars); err != nil {
return err
}
for _, entry := range query.Repository.Object.Tree.Entries {
url := strings.Join([]string{gfs.rawUrl, d.org, d.repo, d.branch, path, entry.Name}, "/")
switch entry.Mode {
case ghModeFile:
d.addFile(entry.Name, withUrl(url))
case ghModeExecutable:
d.addFile(entry.Name, withUrl(url), withMode(fs.FileMode(0755)))
case ghModeDirectory:
d.newDir(entry.Name, withFetcher(getGitDirV3_3))
case ghModeSubmodule: // TODO
case ghModeSymlink: // TODO
default:
return fmt.Errorf("unknown file mode")
}
}
return nil
}