Skip to content

Commit c6a89e2

Browse files
committed
adj config hotfix
1 parent d52244b commit c6a89e2

3 files changed

Lines changed: 28 additions & 21 deletions

File tree

backend/cmd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func main() {
101101

102102
// <--- ADJ --->
103103

104-
adj, err := adj_module.NewADJ(config.Adj.Branch)
104+
adj, err := adj_module.NewADJ(config.Adj.Branch, config.Adj.Test)
105105
if err != nil {
106106
trace.Fatal().Err(err).Msg("setting up ADJ")
107107
}

backend/internal/adj/adj.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const (
1414
RepoPath = "./adj/" // Path where the ADJ repository is cloned
1515
)
1616

17-
func NewADJ(AdjBranch string) (ADJ, error) {
18-
infoRaw, boardsRaw, err := downloadADJ(AdjBranch)
17+
func NewADJ(AdjBranch string, test bool) (ADJ, error) {
18+
infoRaw, boardsRaw, err := downloadADJ(AdjBranch, test)
1919
if err != nil {
2020
return ADJ{}, err
2121
}
@@ -69,15 +69,16 @@ func NewADJ(AdjBranch string) (ADJ, error) {
6969
return adj, nil
7070
}
7171

72-
func downloadADJ(AdjBranch string) (json.RawMessage, json.RawMessage, error) {
72+
func downloadADJ(AdjBranch string, test bool) (json.RawMessage, json.RawMessage, error) {
7373
updateRepo(AdjBranch)
7474

75-
// The BoardIds are applied in the NewADJ function by the getBoardIds function
76-
//Execute the script testadj.py (fix bug)
77-
test := exec.Command("python3", "testadj.py")
78-
out, err := test.CombinedOutput()
79-
if err != nil || len(out) != 0 {
80-
log.Fatalf("python test failed:\nError: %v\nOutput: %s\n", err, string(out))
75+
//Execute the script testadj.py if indicated in config.toml
76+
if test {
77+
test := exec.Command("python3", "testadj.py")
78+
out, err := test.CombinedOutput()
79+
if err != nil || len(out) != 0 {
80+
log.Fatalf("python test failed:\nError: %v\nOutput: %s\n", err, string(out))
81+
}
8182
}
8283

8384
info, err := os.ReadFile(RepoPath + "general_info.json")

backend/pkg/adj/adj.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package adj
22

33
import (
44
"encoding/json"
5+
"log"
56
"os"
7+
"os/exec"
68

79
"github.com/HyperloopUPV-H8/h9-backend/internal/utils"
810
)
@@ -12,8 +14,8 @@ const (
1214
RepoPath = "./adj/" // Path where the ADJ repository is cloned
1315
)
1416

15-
func NewADJ(AdjBranch string) (ADJ, error) {
16-
infoRaw, boardsRaw, err := downloadADJ(AdjBranch)
17+
func NewADJ(AdjBranch string, test bool) (ADJ, error) {
18+
infoRaw, boardsRaw, err := downloadADJ(AdjBranch, test)
1719
if err != nil {
1820
return ADJ{}, err
1921
}
@@ -36,21 +38,17 @@ func NewADJ(AdjBranch string) (ADJ, error) {
3638
}
3739
}
3840

39-
type BoardList struct {
40-
Boards map[string]string `json:"boards"`
41-
}
42-
43-
var boardsList BoardList
41+
var boardsList map[string]string
4442
if err := json.Unmarshal(boardsRaw, &boardsList); err != nil {
4543
return ADJ{}, err
4644
}
4745

48-
boards, err := getBoards(boardsList.Boards)
46+
boards, err := getBoards(boardsList)
4947
if err != nil {
5048
return ADJ{}, err
5149
}
5250

53-
info.BoardIds, err = getBoardIds(boardsList.Boards)
51+
info.BoardIds, err = getBoardIds(boardsList)
5452
if err != nil {
5553
return ADJ{}, err
5654
}
@@ -71,10 +69,18 @@ func NewADJ(AdjBranch string) (ADJ, error) {
7169
return adj, nil
7270
}
7371

74-
func downloadADJ(AdjBranch string) (json.RawMessage, json.RawMessage, error) {
72+
func downloadADJ(AdjBranch string, test bool) (json.RawMessage, json.RawMessage, error) {
7573
updateRepo(AdjBranch)
7674

77-
// The BoardIds are applied in the NewADJ function by the getBoardIds function
75+
//Execute the script testadj.py if indicated in config.toml
76+
if test {
77+
test := exec.Command("python3", "testadj.py")
78+
out, err := test.CombinedOutput()
79+
if err != nil || len(out) != 0 {
80+
log.Fatalf("python test failed:\nError: %v\nOutput: %s\n", err, string(out))
81+
}
82+
}
83+
7884
info, err := os.ReadFile(RepoPath + "general_info.json")
7985
if err != nil {
8086
return nil, nil, err

0 commit comments

Comments
 (0)