Skip to content

Commit 1f40c8c

Browse files
authored
fix repos endpoint (#1642)
* fix repos endpoint * fix runs page * add ui pages behind DIGGER_LEGACY_UI flag
1 parent 7740052 commit 1f40c8c

File tree

7 files changed

+61
-58
lines changed

7 files changed

+61
-58
lines changed

backend/controllers/projects.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ func CreateRunForProject(c *gin.Context) {
573573
return
574574
}
575575

576-
c.JSON(http.StatusOK, run.MapToJsonStruct())
576+
c.JSON(http.StatusOK, "")
577577
}
578578

579579
func UpdateCommentsForBatchGroup(gh utils.GithubClientProvider, batch *models.DiggerBatch, serializedJobs []orchestrator_scheduler.SerializedJob) error {

backend/models/storage.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,16 @@ func (db *Database) GetProjectRunsForOrg(orgId int) ([]ProjectRun, error) {
112112
}
113113

114114
func (db *Database) GetProjectRunsFromContext(c *gin.Context, orgIdKey string) ([]ProjectRun, bool) {
115-
loggedInOrganisationId, exists := c.Get(orgIdKey)
115+
loggedInOrganisationId := c.GetUint(orgIdKey)
116116

117117
log.Printf("getProjectRunsFromContext, org id: %v\n", loggedInOrganisationId)
118118

119-
if !exists {
119+
if loggedInOrganisationId == 0 {
120120
c.String(http.StatusForbidden, "Not allowed to access this resource")
121121
return nil, false
122122
}
123123

124-
runs, err := db.GetProjectRunsForOrg(loggedInOrganisationId.(int))
124+
runs, err := db.GetProjectRunsForOrg(int(loggedInOrganisationId))
125125
if err != nil {
126126
return nil, false
127127
}

ee/backend/controllers/web.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"html/template"
55
"log"
66
"net/http"
7-
"os"
87
"strconv"
98
"strings"
109

@@ -62,18 +61,11 @@ func (web *WebController) ReposPage(c *gin.Context) {
6261
return
6362
}
6463

65-
githubAppId := os.Getenv("GITHUB_APP_ID")
66-
githubApp, err := models.DB.GetGithubApp(githubAppId)
67-
if err != nil {
68-
c.String(http.StatusInternalServerError, "Failed to find GitHub app")
69-
return
70-
}
71-
7264
pageContext := services.GetMessages(c)
7365

7466
maps.Copy(pageContext, gin.H{
75-
"Repos": repos,
76-
"GithubApp": githubApp,
67+
"Repos": repos,
68+
//"GithubApp": githubApp,
7769
})
7870
c.HTML(http.StatusOK, "repos.tmpl", pageContext)
7971
}
@@ -83,12 +75,10 @@ func (web *WebController) RunsPage(c *gin.Context) {
8375
if !done {
8476
return
8577
}
86-
87-
pageContext := services.GetMessages(c)
88-
maps.Copy(pageContext, gin.H{
78+
context := gin.H{
8979
"Runs": runs,
90-
})
91-
c.HTML(http.StatusOK, "runs.tmpl", pageContext)
80+
}
81+
c.HTML(http.StatusOK, "runs.tmpl", context)
9282
}
9383

9484
func (web *WebController) PoliciesPage(c *gin.Context) {

ee/backend/main.go

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ func main() {
3838
r := bootstrap.Bootstrap(templates, diggerController)
3939
cfg := config.DiggerConfig
4040

41-
// redirect to projects by default
42-
r.GET("/", func(context *gin.Context) {
43-
context.Redirect(http.StatusFound, "/projects")
44-
})
45-
4641
eeController := controllers.DiggerEEController{
4742
GitlabProvider: utils.GitlabClientProvider{},
4843
CiBackendProvider: ci_backends2.EEBackendProvider{},
@@ -51,33 +46,47 @@ func main() {
5146
r.POST("/get-spec", eeController.GetSpec)
5247
r.POST("/gitlab-webhook", eeController.GitlabWebHookHandler)
5348

54-
web := controllers.WebController{Config: cfg}
55-
projectsGroup := r.Group("/projects")
56-
projectsGroup.Use(middleware.GetWebMiddleware())
57-
projectsGroup.GET("/", web.ProjectsPage)
58-
projectsGroup.GET("/:projectid/details", web.ProjectDetailsPage)
59-
projectsGroup.POST("/:projectid/details", web.ProjectDetailsUpdatePage)
60-
61-
runsGroup := r.Group("/runs")
62-
runsGroup.Use(middleware.GetWebMiddleware())
63-
runsGroup.GET("/", web.RunsPage)
64-
runsGroup.GET("/:runid/details", web.RunDetailsPage)
65-
66-
reposGroup := r.Group("/repos")
67-
reposGroup.Use(middleware.GetWebMiddleware())
68-
reposGroup.GET("/", web.ReposPage)
69-
70-
repoGroup := r.Group("/repo")
71-
repoGroup.Use(middleware.GetWebMiddleware())
72-
repoGroup.GET("/", web.ReposPage)
73-
74-
policiesGroup := r.Group("/policies")
75-
policiesGroup.Use(middleware.GetWebMiddleware())
76-
policiesGroup.GET("/", web.PoliciesPage)
77-
policiesGroup.GET("/add", web.AddPolicyPage)
78-
policiesGroup.POST("/add", web.AddPolicyPage)
79-
policiesGroup.GET("/:policyid/details", web.PolicyDetailsPage)
80-
policiesGroup.POST("/:policyid/details", web.PolicyDetailsUpdatePage)
49+
legacyUiShown := os.Getenv("DIGGER_LEGACY_UI")
50+
if legacyUiShown != "" {
51+
// redirect to projects by default
52+
r.GET("/", func(context *gin.Context) {
53+
context.Redirect(http.StatusFound, "/projects")
54+
})
55+
56+
web := controllers.WebController{Config: cfg}
57+
projectsGroup := r.Group("/projects")
58+
projectsGroup.Use(middleware.GetWebMiddleware())
59+
projectsGroup.GET("/", web.ProjectsPage)
60+
projectsGroup.GET("/:projectid/details", web.ProjectDetailsPage)
61+
projectsGroup.POST("/:projectid/details", web.ProjectDetailsUpdatePage)
62+
63+
runsGroup := r.Group("/runs")
64+
runsGroup.Use(middleware.GetWebMiddleware())
65+
runsGroup.GET("/", web.RunsPage)
66+
runsGroup.GET("/:runid/details", web.RunDetailsPage)
67+
68+
reposGroup := r.Group("/repos")
69+
reposGroup.Use(middleware.GetWebMiddleware())
70+
reposGroup.GET("/", web.ReposPage)
71+
72+
repoGroup := r.Group("/repo")
73+
repoGroup.Use(middleware.GetWebMiddleware())
74+
repoGroup.GET("/", web.ReposPage)
75+
76+
policiesGroup := r.Group("/policies")
77+
policiesGroup.Use(middleware.GetWebMiddleware())
78+
policiesGroup.GET("/", web.PoliciesPage)
79+
policiesGroup.GET("/add", web.AddPolicyPage)
80+
policiesGroup.POST("/add", web.AddPolicyPage)
81+
policiesGroup.GET("/:policyid/details", web.PolicyDetailsPage)
82+
policiesGroup.POST("/:policyid/details", web.PolicyDetailsUpdatePage)
83+
} else {
84+
r.GET("/", func(c *gin.Context) {
85+
c.HTML(http.StatusOK, "healthy.tmpl", gin.H{})
86+
return
87+
})
88+
89+
}
8190

8291
jobArtefactsGroup := r.Group("/job_artefacts")
8392
jobArtefactsGroup.Use(middleware.GetApiMiddleware())

ee/backend/templates/healthy.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<html>
2+
<body>
3+
<h1>Digger is up and running</h1>
4+
<p>Congratulations!</p>
5+
</body>
6+
</html>

ee/backend/templates/repos.tmpl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div class="container-fluid">
44
<div class="card shadow">
55
<div class="card-header py-3">
6-
<p class="text-primary m-0 fw-bold">Projects</p>
6+
<p class="text-primary m-0 fw-bold">Repositories</p>
77
</div>
88
<div class="card-body">
99

@@ -20,18 +20,14 @@
2020
<tbody>
2121
{{ range .Repos }}
2222
<tr>
23-
<td>{{ .Name}}</td>
23+
<td>{{ .RepoFullName}}</td>
2424
<td>{{.Organisation.Name}}</td>
2525
</tr>
2626
{{ end }}
2727
</tbody>
2828
</table>
2929
</div>
30-
<div class="row">
31-
<div class="d-sm-flex justify-content-between align-items-center mb-4">
32-
<a class="btn btn-primary" role="button" href="{{.GithubApp.GithubAppUrl}}">Configure GitHub repos</a>
33-
</div>
34-
</div>
30+
3531
</div>
3632
</div>
3733
</div>

ee/backend/templates/runs.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<thead>
1414
<tr>
1515
<th>Project Name</th>
16+
<th>Repo </th>
1617
<th>Status</th>
1718
<th>Command</th>
1819
<th>Started at</th>
@@ -23,6 +24,7 @@
2324
{{ range .Runs }}
2425
<tr>
2526
<td>{{ .Project.Name }}</td>
27+
<td>{{ .Project.Repo.RepoFullName }}</td>
2628
<td>{{ .Status }}</td>
2729
<td>{{ .Command }}</td>
2830
<td>{{ .StartedAt | formatAsDate }}</td>

0 commit comments

Comments
 (0)