Skip to content

Commit 140b36a

Browse files
committed
Fix nil pointer exception in handleIssueCommentEvent when GitHub App installation is missing.
Signed-off-by: Lorenzo Buitizon <[email protected]>
1 parent a4c0d81 commit 140b36a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

backend/controllers/github_comment.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,45 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
7878
)
7979
return fmt.Errorf("error getting github app link")
8080
}
81+
if link == nil {
82+
slog.Error("GitHub app installation link not found",
83+
"installationId", installationId,
84+
)
85+
86+
// Try to get GitHub service to post error comment
87+
ghService, _, ghServiceErr := utils.GetGithubService(gh, installationId, repoFullName, repoOwner, repoName)
88+
if ghServiceErr != nil {
89+
slog.Error("Error getting GitHub service to post error comment",
90+
"installationId", installationId,
91+
"repoFullName", repoFullName,
92+
"error", ghServiceErr,
93+
)
94+
return fmt.Errorf("github app installation link not found and could not post error comment")
95+
}
96+
97+
// Post helpful error message to the user
98+
errorMsg := ":x: **Digger could not find the GitHub App installation record.**\n\n" +
99+
"This usually happens when:\n" +
100+
"• The GitHub App was not installed successfully\n" +
101+
"• The installation process did not complete the callback to Digger\n" +
102+
"• There was an issue with the GitHub App installation flow\n\n" +
103+
"Please ensure that:\n" +
104+
"1. The GitHub App is properly installed on your repository\n" +
105+
"2. The installation completed successfully and redirected to the callback URL\n" +
106+
"3. The repository is accessible to the GitHub App\n\n" +
107+
"If the issue persists, please contact support with this installation ID: " + fmt.Sprintf("%d", installationId)
108+
109+
_, commentErr := ghService.PublishComment(issueNumber, errorMsg)
110+
if commentErr != nil {
111+
slog.Error("Error posting installation not found comment",
112+
"issueNumber", issueNumber,
113+
"error", commentErr,
114+
)
115+
return fmt.Errorf("github app installation link not found and could not post error comment")
116+
}
117+
118+
return fmt.Errorf("github app installation link not found")
119+
}
81120
orgId := link.OrganisationId
82121

83122
if *payload.Action != "created" {

0 commit comments

Comments
 (0)