Skip to content

Commit

Permalink
Merge branch 'develop' into enhancement/install-sharp
Browse files Browse the repository at this point in the history
# Conflicts:
#	package-lock.json
#	package.json
  • Loading branch information
simonbs committed Jul 22, 2024
2 parents 174725f + 48f158d commit cc0057c
Show file tree
Hide file tree
Showing 10 changed files with 977 additions and 453 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ updates:
directory: "/"
schedule:
interval: "weekly"
groups:
fontawesome:
patterns:
- "@fortawesome/*"
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<a href="https://github.com/shapehq/shape-docs/actions/workflows/build.yml"><img src="https://github.com/shapehq/shape-docs/actions/workflows/build.yml/badge.svg"></a>
<a href="https://github.com/shapehq/shape-docs/actions/workflows/test.yml"><img src="https://github.com/shapehq/shape-docs/actions/workflows/test.yml/badge.svg"></a>
<a href="https://github.com/shapehq/shape-docs/actions/workflows/lint.yml"><img src="https://github.com/shapehq/shape-docs/actions/workflows/lint.yml/badge.svg"></a>
<a href="https://github.com/shapehq/shape-docs/actions/workflows/build-docker-image"><img src="https://github.com/shapehq/shape-docs/actions/workflows/build-docker-image.yml/badge.svg"></a>
</div>

---
Expand All @@ -24,7 +25,7 @@

<hr />

Shape Docs makes managing and previewing OpenAPI documentation a breeze, streamlining spec-driven development. With GitHub-based authorization, you can easily control who accesses your docs. Shape Docs comments on pull requests that tweak your OpenAPI specs, giving you preview URLs to ensure every update is well-reviewed
Shape Docs makes managing and previewing OpenAPI documentation a breeze, streamlining spec-driven development. With GitHub-based authorization, you can easily control who accesses your docs. Shape Docs comments on pull requests that tweak your OpenAPI specs, giving you preview URLs to ensure every update is well-reviewed.

<div align="center">
<img width="600" src="https://github.com/shapehq/shape-docs/raw/main/wiki/home.png?raw=true" alt="Screenshot of Shape Docs"/>
Expand Down
147 changes: 143 additions & 4 deletions __test__/hooks/PullRequestCommenter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ test("It skips updating comment when the body has not changed", async () => {
expect(didUpdateComment).toBeFalsy()
})

test("It updates comment to remove file list when all relevant file changes were removed from the PR", async () => {
test("It updates comment to remove file list when all relevant file changes were removed from the PR", async () => {
let didAddComment = false
let didUpdateComment = false
let addedCommentBody: string | undefined
Expand Down Expand Up @@ -314,7 +314,7 @@ test("It updates comment to remove file list when all relevant file changes wer
expect(updatedCommentBody).not.toContain("openapi.yml")
})

test("It adds comment without file table if only project configuration was edited", async () => {
test("It adds comment if only project configuration was edited", async () => {
let didAddComment = false
let commentBody: string | undefined
const sut = new PullRequestCommenter({
Expand Down Expand Up @@ -364,6 +364,145 @@ test("It adds comment without file table if only project configuration was edite
ref: "main"
})
expect(didAddComment).toBeTruthy()
expect(commentBody).not.toContain("<table>")
expect(commentBody).not.toContain(".demo-docs.yml")
expect(commentBody).toContain("<table>")
expect(commentBody).toContain(".demo-docs.yml")
})

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",
gitHubAppId: "appid1234",
gitHubClient: {
async graphql() {
return {}
},
async getRepositoryContent() {
return { downloadURL: "https://example.com" }
},
async getPullRequestFiles() {
return [{
filename: "openapi.yml",
status: "changed"
}, {
filename: ".foo,yml",
status: "changed"
}]
},
async getPullRequestComments() {
return []
},
async addCommentToPullRequest(request) {
didAddComment = true
commentBody = request.body
},
async updatePullRequestComment() {}
}
})
await sut.commentPullRequest({
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryOwner: "acme",
repositoryName: "demo-openapi",
ref: "main"
})
expect(didAddComment).toBeTruthy()
expect(commentBody).toContain("<table>")
expect(commentBody).toContain("openapi.yml")
expect(commentBody).not.toContain(".foo.yml")
})

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",
gitHubAppId: "appid1234",
gitHubClient: {
async graphql() {
return {}
},
async getRepositoryContent() {
return { downloadURL: "https://example.com" }
},
async getPullRequestFiles() {
return [{
filename: "openapi.yml",
status: "changed"
}, {
filename: "foo/bar,yml",
status: "changed"
}]
},
async getPullRequestComments() {
return []
},
async addCommentToPullRequest(request) {
didAddComment = true
commentBody = request.body
},
async updatePullRequestComment() {}
}
})
await sut.commentPullRequest({
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryOwner: "acme",
repositoryName: "demo-openapi",
ref: "main"
})
expect(didAddComment).toBeTruthy()
expect(commentBody).toContain("<table>")
expect(commentBody).toContain("openapi.yml")
expect(commentBody).not.toContain("foo/bar.yml")
})

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",
gitHubAppId: "appid1234",
gitHubClient: {
async graphql() {
return {}
},
async getRepositoryContent() {
return { downloadURL: "https://example.com" }
},
async getPullRequestFiles() {
return [{
filename: ".foo.yml",
status: "changed"
}, {
filename: ".github/workflows/bar.yml",
status: "changed"
}]
},
async getPullRequestComments() {
return []
},
async addCommentToPullRequest(_request) {
didAddComment = true
},
async updatePullRequestComment() {}
}
})
await sut.commentPullRequest({
appInstallationId: 1234,
pullRequestNumber: 42,
repositoryOwner: "acme",
repositoryName: "demo-openapi",
ref: "main"
})
expect(didAddComment).toBeFalsy()
})
31 changes: 31 additions & 0 deletions __test__/utils/getBaseFilename.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { getBaseFilename } from "@/common"

test("It returns base filename for file in root", async () => {
const result = getBaseFilename("foo.yml")
expect(result).toEqual("foo")
})

test("It returns base filename for file path including dot", async () => {
const result = getBaseFilename("foo.bar.yml")
expect(result).toEqual("foo.bar")
})

test("It returns base filename for file in folder", async () => {
const result = getBaseFilename("foo/bar.yml")
expect(result).toEqual("bar")
})

test("It returns base filename when file path starts with a slash", async () => {
const result = getBaseFilename("/foo/bar.yml")
expect(result).toEqual("bar")
})

test("It returns base filename when file path does not contain an extension", async () => {
const result = getBaseFilename("foo")
expect(result).toEqual("foo")
})

test("It returns empty string for the empty string", async () => {
const result = getBaseFilename("")
expect(result).toEqual("")
})
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ module.exports = {
moduleFileExtensions: ["js", "ts"],
testEnvironment: "node",
testMatch: ["**/*.test.ts"],
extensionsToTreatAsEsm: [".ts"],
transform: {
"^.+\\.ts$": "ts-jest"
"^.+\\.tsx?$": ["ts-jest", { useESM: true }]
},
moduleNameMapper: {
"^@/(.*)$": "<rootDir>/src/$1"
Expand Down
Loading

0 comments on commit cc0057c

Please sign in to comment.