|
8 | 8 | ) |
9 | 9 |
|
10 | 10 | const ( |
11 | | - RepoUrl = "https://github.com/HyperloopUPV-H8/JSON_ADE.git" // URL of the ADJ repository |
| 11 | + RepoUrl = "https://github.com/HyperloopUPV-H8/JSON_ADE.git" // URL of the ADJ repository |
| 12 | + RepoPath = "./JSON_ADE/" // Path where the ADJ repository is cloned |
12 | 13 | ) |
13 | 14 |
|
14 | 15 | func NewADJ() (*ADJ, error) { |
@@ -40,27 +41,37 @@ func NewADJ() (*ADJ, error) { |
40 | 41 | } |
41 | 42 |
|
42 | 43 | func downloadADJ() (json.RawMessage, json.RawMessage, error) { |
43 | | - _, err := git.PlainClone("", false, &git.CloneOptions{ |
44 | | - URL: RepoUrl, |
45 | | - }) |
46 | | - if err != nil { |
47 | | - return nil, nil, err |
| 44 | + if !checkRepo() { |
| 45 | + _, err := git.PlainClone(RepoPath, true, &git.CloneOptions{ |
| 46 | + URL: RepoUrl, |
| 47 | + }) |
| 48 | + if err != nil { |
| 49 | + return nil, nil, err |
| 50 | + } |
48 | 51 | } |
49 | 52 |
|
50 | 53 | // The BoardIds are applied in the NewADJ function by the getBoardIds function |
51 | | - info, err := os.ReadFile("general_info.json") |
| 54 | + info, err := os.ReadFile(RepoPath + "general_info.json") |
52 | 55 | if err != nil { |
53 | 56 | return nil, nil, err |
54 | 57 | } |
55 | 58 |
|
56 | | - boardsList, err := os.ReadFile("boards.json") |
| 59 | + boardsList, err := os.ReadFile(RepoPath + "boards.json") |
57 | 60 | if err != nil { |
58 | 61 | return nil, nil, err |
59 | 62 | } |
60 | 63 |
|
61 | 64 | return info, boardsList, nil |
62 | 65 | } |
63 | 66 |
|
| 67 | +func checkRepo() bool { |
| 68 | + if _, err := os.Stat(RepoPath); os.IsNotExist(err) { |
| 69 | + return false |
| 70 | + } |
| 71 | + |
| 72 | + return true |
| 73 | +} |
| 74 | + |
64 | 75 | func getBoards(info Info, boardsList map[string]string) (map[string]Board, error) { |
65 | 76 | var boards map[string]Board |
66 | 77 | for boardName, boardPath := range boardsList { |
|
0 commit comments