Skip to content

Commit b81a186

Browse files
committed
handle org being nil and other coderabbit comment
1 parent b20e7b1 commit b81a186

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

backend/controllers/github_api.go

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ func LinkGithubInstallationToOrgApi(c *gin.Context) {
3333
if errors.Is(err, gorm.ErrRecordNotFound) {
3434
log.Printf("could not find organisation: %v", err)
3535
c.JSON(http.StatusNotFound, gin.H{"status": "Could not find organisation: " + organisationId})
36+
} else {
37+
log.Printf("database error while finding organisation: %v", err)
38+
c.JSON(http.StatusInternalServerError, gin.H{"status": "Internal server error"})
3639
}
3740
return
3841
}

backend/models/orgs.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,12 @@ func (p *Project) MapToJsonStruct() interface{} {
126126
}
127127
}
128128
func (r *Repo) MapToJsonStruct() interface{} {
129-
129+
OrganisationName := func() string {
130+
if r.Organisation == nil {
131+
return ""
132+
}
133+
return r.Organisation.Name
134+
}
130135
return struct {
131136
Id uint `json:"id"`
132137
Name string `json:"name"`
@@ -142,7 +147,7 @@ func (r *Repo) MapToJsonStruct() interface{} {
142147
RepoUrl: r.RepoUrl,
143148
VCS: string(r.VCS),
144149
OrganisationID: r.OrganisationID,
145-
OrganisationName: r.Organisation.Name,
150+
OrganisationName: OrganisationName(),
146151
}
147152
}
148153

0 commit comments

Comments
 (0)