Skip to content

Commit 33c07cf

Browse files
simonbsulrikandersen
authored andcommitted
Revert "Removes FRAMNA_DOCS_BASE_URL"
This reverts commit 3cef0b2.
1 parent 204914d commit 33c07cf

File tree

5 files changed

+11
-28
lines changed

5 files changed

+11
-28
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
FRAMNA_DOCS_BASE_URL=http://localhost:3000
12
FRAMNA_DOCS_TITLE=Framna Docs
23
FRAMNA_DOCS_DESCRIPTION=Documentation for Framna's APIs
34
FRAMNA_DOCS_HELP_URL=https://github.com/shapehq/framna-docs/wiki

src/composition.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ export const gitHubHookHandler = new GitHubHookHandler({
195195
eventHandler: new PostCommentPullRequestEventHandler({
196196
pullRequestCommenter: new PullRequestCommenter({
197197
siteName: env.getOrThrow("FRAMNA_DOCS_TITLE"),
198+
domain: env.getOrThrow("FRAMNA_DOCS_BASE_URL"),
198199
repositoryNameSuffix: env.getOrThrow("REPOSITORY_NAME_SUFFIX"),
199200
projectConfigurationFilename: env.getOrThrow("FRAMNA_DOCS_PROJECT_CONFIGURATION_FILENAME"),
200201
gitHubAppId: env.getOrThrow("GITHUB_APP_ID"),

src/features/hooks/data/GitHubHookHandler.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ interface GitHubHookHandlerConfig {
1010
export default class GitHubHookHandler {
1111
private readonly webhooks: Webhooks
1212
private readonly pullRequestEventHandler: IPullRequestEventHandler
13-
private hostURL: string | undefined
1413

1514
constructor(config: GitHubHookHandlerConfig) {
1615
this.webhooks = new Webhooks({ secret: config.secret })
@@ -19,8 +18,6 @@ export default class GitHubHookHandler {
1918
}
2019

2120
async handle(req: NextRequest): Promise<void> {
22-
const url = new URL(req.url)
23-
this.hostURL = `${url.protocol}//${url.hostname}${url.port ? ":" + url.port : ""}`
2421
await this.webhooks.verifyAndReceive({
2522
id: req.headers.get("X-GitHub-Delivery") as string,
2623
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
@@ -38,11 +35,7 @@ export default class GitHubHookHandler {
3835
if (!payload.installation) {
3936
throw new Error("Payload does not contain information about the app installation.")
4037
}
41-
if (!this.hostURL) {
42-
throw new Error("hostURL was not stored as part of the webhook request.")
43-
}
4438
await this.pullRequestEventHandler.pullRequestOpened({
45-
hostURL: this.hostURL,
4639
appInstallationId: payload.installation.id,
4740
repositoryOwner: payload.repository.owner.login,
4841
repositoryName: payload.repository.name,
@@ -54,11 +47,7 @@ export default class GitHubHookHandler {
5447
if (!payload.installation) {
5548
throw new Error("Payload does not contain information about the app installation.")
5649
}
57-
if (!this.hostURL) {
58-
throw new Error("hostURL was not stored as part of the webhook request.")
59-
}
6050
await this.pullRequestEventHandler.pullRequestReopened({
61-
hostURL: this.hostURL,
6251
appInstallationId: payload.installation.id,
6352
repositoryOwner: payload.repository.owner.login,
6453
repositoryName: payload.repository.name,
@@ -70,11 +59,7 @@ export default class GitHubHookHandler {
7059
if (!payload.installation) {
7160
throw new Error("Payload does not contain information about the app installation.")
7261
}
73-
if (!this.hostURL) {
74-
throw new Error("hostURL was not stored as part of the webhook request.")
75-
}
7662
await this.pullRequestEventHandler.pullRequestSynchronized({
77-
hostURL: this.hostURL,
7863
appInstallationId: payload.installation.id,
7964
repositoryOwner: payload.repository.owner.login,
8065
repositoryName: payload.repository.name,

src/features/hooks/domain/IPullRequestEventHandler.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export interface IPullRequestOpenedEvent {
2-
readonly hostURL: string
32
readonly appInstallationId: number
43
readonly repositoryOwner: string
54
readonly repositoryName: string
@@ -8,7 +7,6 @@ export interface IPullRequestOpenedEvent {
87
}
98

109
export interface IPullRequestReopenedEvent {
11-
readonly hostURL: string
1210
readonly appInstallationId: number
1311
readonly repositoryOwner: string
1412
readonly repositoryName: string
@@ -17,7 +15,6 @@ export interface IPullRequestReopenedEvent {
1715
}
1816

1917
export interface IPullRequestSynchronizedEvent {
20-
readonly hostURL: string
2118
readonly appInstallationId: number
2219
readonly repositoryOwner: string
2320
readonly repositoryName: string

src/features/hooks/domain/PullRequestCommenter.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@ import { IGitHubClient, PullRequestFile } from "@/common"
22
import { getBaseFilename } from "@/common/utils"
33

44
export default class PullRequestCommenter {
5+
private readonly domain: string
56
private readonly siteName: string
67
private readonly repositoryNameSuffix: string
78
private readonly projectConfigurationFilename: string
89
private readonly gitHubAppId: string
910
private readonly gitHubClient: IGitHubClient
1011

1112
constructor(config: {
13+
domain: string
1214
siteName: string
1315
repositoryNameSuffix: string
1416
projectConfigurationFilename: string
1517
gitHubAppId: string
1618
gitHubClient: IGitHubClient
1719
}) {
20+
this.domain = config.domain
1821
this.siteName = config.siteName
1922
this.repositoryNameSuffix = config.repositoryNameSuffix
2023
this.projectConfigurationFilename = config.projectConfigurationFilename
@@ -23,7 +26,6 @@ export default class PullRequestCommenter {
2326
}
2427

2528
async commentPullRequest(request: {
26-
hostURL: string
2729
appInstallationId: number
2830
repositoryOwner: string
2931
repositoryName: string
@@ -33,7 +35,6 @@ export default class PullRequestCommenter {
3335
const files = this.getChangedFiles(await this.getYamlFiles(request))
3436
const commentBody = this.makeCommentBody({
3537
files,
36-
hostURL: request.hostURL,
3738
owner: request.repositoryOwner,
3839
repositoryName: request.repositoryName,
3940
ref: request.ref
@@ -72,7 +73,7 @@ export default class PullRequestCommenter {
7273
}
7374

7475
private async getYamlFiles(request: {
75-
appInstallationId: number
76+
appInstallationId: number,
7677
repositoryOwner: string
7778
repositoryName: string
7879
pullRequestNumber: number
@@ -87,7 +88,7 @@ export default class PullRequestCommenter {
8788
}
8889

8990
private async getExistingComment(request: {
90-
appInstallationId: number
91+
appInstallationId: number,
9192
repositoryOwner: string
9293
repositoryName: string
9394
pullRequestNumber: number
@@ -104,40 +105,38 @@ export default class PullRequestCommenter {
104105
}
105106

106107
private makeCommentBody(params: {
107-
hostURL: string
108108
files: PullRequestFile[]
109109
owner: string
110110
repositoryName: string
111111
ref: string
112112
}): string {
113-
const { hostURL, owner, repositoryName, ref } = params
113+
const { owner, repositoryName, ref } = params
114114
const projectId = this.getProjectId({ repositoryName })
115115
const tableHTML = this.makeFileTableHTML(params)
116116
let result = "### 📖 Documentation Preview"
117117
result += "\n\n"
118-
result += `The changes are now ready to previewed on <a href="${hostURL}/${owner}/${projectId}/${ref}">${this.siteName}</a> 🚀`
118+
result += `The changes are now ready to previewed on <a href="${this.domain}/${owner}/${projectId}/${ref}">${this.siteName}</a> 🚀`
119119
if (tableHTML) {
120120
result += "\n\n" + tableHTML
121121
}
122122
return result
123123
}
124124

125125
private makeFileTableHTML(params: {
126-
hostURL: string
127126
files: PullRequestFile[]
128127
owner: string
129128
repositoryName: string
130129
ref: string
131130
}) {
132-
const { hostURL, files, owner, repositoryName, ref } = params
131+
const { files, owner, repositoryName, ref } = params
133132
const rows: { filename: string, status: string, button: string }[] = []
134133
const projectId = this.getProjectId({ repositoryName })
135134
// Create rows for each file
136135
for (const file of files) {
137136
const status = this.getStatusText(file)
138137
let button = ""
139138
if (file.status != "removed") {
140-
let link = `${hostURL}/${owner}/${projectId}/${ref}`
139+
let link = `${this.domain}/${owner}/${projectId}/${ref}`
141140
if (!this.isProjectConfigurationFile(file.filename)) {
142141
link += `/${file.filename}`
143142
}

0 commit comments

Comments
 (0)