Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brings back FRAMNA_DOCS_BASE_URL #376

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FRAMNA_DOCS_BASE_URL=http://localhost:3000
FRAMNA_DOCS_TITLE=Framna Docs
FRAMNA_DOCS_DESCRIPTION=Documentation for Framna's APIs
FRAMNA_DOCS_HELP_URL=https://github.com/shapehq/framna-docs/wiki
Expand Down
6 changes: 0 additions & 6 deletions __test__/hooks/FilteringPullRequestEventHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ test("It calls pullRequestOpened(_:) when event is included", async () => {
}
})
await sut.pullRequestOpened({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryName: "demo-openapi",
Expand All @@ -44,7 +43,6 @@ test("It calls pullRequestReopened(_:) when event is included", async () => {
}
})
await sut.pullRequestReopened({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryName: "demo-openapi",
Expand All @@ -71,7 +69,6 @@ test("It calls pullRequestSynchronized(_:) when event is included", async () =>
}
})
await sut.pullRequestSynchronized({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryName: "demo-openapi",
Expand All @@ -98,7 +95,6 @@ test("It skips calling pullRequestOpened(_:) when event is not included", async
}
})
await sut.pullRequestOpened({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryName: "demo-openapi",
Expand All @@ -125,7 +121,6 @@ test("It skips calling pullRequestReopened(_:) when event is not included", asyn
}
})
await sut.pullRequestReopened({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryName: "demo-openapi",
Expand All @@ -152,7 +147,6 @@ test("It skips calling pullRequestSynchronized(_:) when event is not included",
}
})
await sut.pullRequestSynchronized({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryName: "demo-openapi",
Expand Down
3 changes: 0 additions & 3 deletions __test__/hooks/PostCommentPullRequestEventHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ test("It comments when opening a pull request", async () => {
}
})
await sut.pullRequestOpened({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryOwner: "acme",
Expand All @@ -30,7 +29,6 @@ test("It comments when reopening a pull request", async () => {
}
})
await sut.pullRequestReopened({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryOwner: "acme",
Expand All @@ -50,7 +48,6 @@ test("It comments when synchronizing a pull request", async () => {
}
})
await sut.pullRequestSynchronized({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryOwner: "acme",
Expand Down
22 changes: 10 additions & 12 deletions __test__/hooks/PullRequestCommenter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PullRequestCommenter } from "@/features/hooks/domain"
test("It adds comment when none exist", async () => {
let didAddComment = false
const sut = new PullRequestCommenter({
domain: "https://example.com",
siteName: "Demo Docs",
repositoryNameSuffix: "-openapi",
projectConfigurationFilename: ".demo-docs.yml",
Expand Down Expand Up @@ -30,7 +31,6 @@ test("It adds comment when none exist", async () => {
}
})
await sut.commentPullRequest({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryOwner: "acme",
Expand All @@ -44,6 +44,7 @@ test("It adds comment containing list of changed files", async () => {
let didAddComment = false
let commentBody: string | undefined
const sut = new PullRequestCommenter({
domain: "https://example.com",
siteName: "Demo Docs",
repositoryNameSuffix: "-openapi",
projectConfigurationFilename: ".demo-docs.yml",
Expand Down Expand Up @@ -75,7 +76,6 @@ test("It adds comment containing list of changed files", async () => {
}
})
await sut.commentPullRequest({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryOwner: "acme",
Expand All @@ -91,6 +91,7 @@ test("It adds comment containing list of changed files", async () => {
test("It skips adding comment when no YAML files were found in the PR", async () => {
let didAddComment = false
const sut = new PullRequestCommenter({
domain: "https://example.com",
siteName: "Demo Docs",
repositoryNameSuffix: "-openapi",
projectConfigurationFilename: ".demo-docs.yml",
Expand Down Expand Up @@ -118,7 +119,6 @@ test("It skips adding comment when no YAML files were found in the PR", async ()
}
})
await sut.commentPullRequest({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryOwner: "acme",
Expand All @@ -131,6 +131,7 @@ test("It skips adding comment when no YAML files were found in the PR", async ()
test("It updates comment when one already exists", async () => {
let didUpdateComment = false
const sut = new PullRequestCommenter({
domain: "https://example.com",
siteName: "Demo Docs",
repositoryNameSuffix: "-openapi",
projectConfigurationFilename: ".demo-docs.yml",
Expand Down Expand Up @@ -165,7 +166,6 @@ test("It updates comment when one already exists", async () => {
}
})
await sut.commentPullRequest({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryOwner: "acme",
Expand All @@ -179,6 +179,7 @@ test("It skips updating comment when the body has not changed", async () => {
let addedCommentBody: string | undefined
let didUpdateComment = false
const sut = new PullRequestCommenter({
domain: "https://example.com",
siteName: "Demo Docs",
repositoryNameSuffix: "-openapi",
projectConfigurationFilename: ".demo-docs.yml",
Expand Down Expand Up @@ -219,7 +220,6 @@ test("It skips updating comment when the body has not changed", async () => {
})
// Add a comment.
await sut.commentPullRequest({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryOwner: "acme",
Expand All @@ -228,7 +228,6 @@ test("It skips updating comment when the body has not changed", async () => {
})
// Attempt to update a comment. This is skipped because the body has not changed.
await sut.commentPullRequest({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryOwner: "acme",
Expand All @@ -245,6 +244,7 @@ test("It updates comment to remove file list when all relevant file changes were
let addedCommentBody: string | undefined
let updatedCommentBody: string | undefined
const sut = new PullRequestCommenter({
domain: "https://example.com",
siteName: "Demo Docs",
repositoryNameSuffix: "-openapi",
projectConfigurationFilename: ".demo-docs.yml",
Expand Down Expand Up @@ -292,7 +292,6 @@ test("It updates comment to remove file list when all relevant file changes were
})
// Add a comment.
await sut.commentPullRequest({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryOwner: "acme",
Expand All @@ -301,7 +300,6 @@ test("It updates comment to remove file list when all relevant file changes were
})
// Attempt to update a comment. This is skipped because the body has not changed.
await sut.commentPullRequest({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryOwner: "acme",
Expand All @@ -320,6 +318,7 @@ test("It adds comment if only project configuration was edited", async () => {
let didAddComment = false
let commentBody: string | undefined
const sut = new PullRequestCommenter({
domain: "https://example.com",
siteName: "Demo Docs",
repositoryNameSuffix: "-openapi",
projectConfigurationFilename: ".demo-docs.yml",
Expand Down Expand Up @@ -358,7 +357,6 @@ test("It adds comment if only project configuration was edited", async () => {
}
})
await sut.commentPullRequest({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryOwner: "acme",
Expand All @@ -374,6 +372,7 @@ test("It ignores files starting with a dot", async () => {
let didAddComment = false
let commentBody: string | undefined
const sut = new PullRequestCommenter({
domain: "https://example.com",
siteName: "Demo Docs",
repositoryNameSuffix: "-openapi",
projectConfigurationFilename: ".demo-docs.yml",
Expand Down Expand Up @@ -405,7 +404,6 @@ test("It ignores files starting with a dot", async () => {
}
})
await sut.commentPullRequest({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryOwner: "acme",
Expand All @@ -422,6 +420,7 @@ test("It ignores files in directories", async () => {
let didAddComment = false
let commentBody: string | undefined
const sut = new PullRequestCommenter({
domain: "https://example.com",
siteName: "Demo Docs",
repositoryNameSuffix: "-openapi",
projectConfigurationFilename: ".demo-docs.yml",
Expand Down Expand Up @@ -453,7 +452,6 @@ test("It ignores files in directories", async () => {
}
})
await sut.commentPullRequest({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryOwner: "acme",
Expand All @@ -469,6 +467,7 @@ test("It ignores files in directories", async () => {
test("It does not post comment if changes only include ignored filenames", async () => {
let didAddComment = false
const sut = new PullRequestCommenter({
domain: "https://example.com",
siteName: "Demo Docs",
repositoryNameSuffix: "-openapi",
projectConfigurationFilename: ".demo-docs.yml",
Expand Down Expand Up @@ -499,7 +498,6 @@ test("It does not post comment if changes only include ignored filenames", async
}
})
await sut.commentPullRequest({
hostURL: "https://localhost:3000",
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryOwner: "acme",
Expand Down
1 change: 1 addition & 0 deletions src/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export const gitHubHookHandler = new GitHubHookHandler({
eventHandler: new PostCommentPullRequestEventHandler({
pullRequestCommenter: new PullRequestCommenter({
siteName: env.getOrThrow("FRAMNA_DOCS_TITLE"),
domain: env.getOrThrow("FRAMNA_DOCS_BASE_URL"),
repositoryNameSuffix: env.getOrThrow("REPOSITORY_NAME_SUFFIX"),
projectConfigurationFilename: env.getOrThrow("FRAMNA_DOCS_PROJECT_CONFIGURATION_FILENAME"),
gitHubAppId: env.getOrThrow("GITHUB_APP_ID"),
Expand Down
15 changes: 0 additions & 15 deletions src/features/hooks/data/GitHubHookHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ interface GitHubHookHandlerConfig {
export default class GitHubHookHandler {
private readonly webhooks: Webhooks
private readonly pullRequestEventHandler: IPullRequestEventHandler
private hostURL: string | undefined

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

async handle(req: NextRequest): Promise<void> {
const url = new URL(req.url)
this.hostURL = `${url.protocol}//${url.hostname}${url.port ? ":" + url.port : ""}`
await this.webhooks.verifyAndReceive({
id: req.headers.get("X-GitHub-Delivery") as string,
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
Expand All @@ -38,11 +35,7 @@ export default class GitHubHookHandler {
if (!payload.installation) {
throw new Error("Payload does not contain information about the app installation.")
}
if (!this.hostURL) {
throw new Error("hostURL was not stored as part of the webhook request.")
}
await this.pullRequestEventHandler.pullRequestOpened({
hostURL: this.hostURL,
appInstallationId: payload.installation.id,
repositoryOwner: payload.repository.owner.login,
repositoryName: payload.repository.name,
Expand All @@ -54,11 +47,7 @@ export default class GitHubHookHandler {
if (!payload.installation) {
throw new Error("Payload does not contain information about the app installation.")
}
if (!this.hostURL) {
throw new Error("hostURL was not stored as part of the webhook request.")
}
await this.pullRequestEventHandler.pullRequestReopened({
hostURL: this.hostURL,
appInstallationId: payload.installation.id,
repositoryOwner: payload.repository.owner.login,
repositoryName: payload.repository.name,
Expand All @@ -70,11 +59,7 @@ export default class GitHubHookHandler {
if (!payload.installation) {
throw new Error("Payload does not contain information about the app installation.")
}
if (!this.hostURL) {
throw new Error("hostURL was not stored as part of the webhook request.")
}
await this.pullRequestEventHandler.pullRequestSynchronized({
hostURL: this.hostURL,
appInstallationId: payload.installation.id,
repositoryOwner: payload.repository.owner.login,
repositoryName: payload.repository.name,
Expand Down
3 changes: 0 additions & 3 deletions src/features/hooks/domain/IPullRequestEventHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export interface IPullRequestOpenedEvent {
readonly hostURL: string
readonly appInstallationId: number
readonly repositoryOwner: string
readonly repositoryName: string
Expand All @@ -8,7 +7,6 @@ export interface IPullRequestOpenedEvent {
}

export interface IPullRequestReopenedEvent {
readonly hostURL: string
readonly appInstallationId: number
readonly repositoryOwner: string
readonly repositoryName: string
Expand All @@ -17,7 +15,6 @@ export interface IPullRequestReopenedEvent {
}

export interface IPullRequestSynchronizedEvent {
readonly hostURL: string
readonly appInstallationId: number
readonly repositoryOwner: string
readonly repositoryName: string
Expand Down
Loading
Loading