Skip to content
Open
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
30 changes: 22 additions & 8 deletions src/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,14 @@ ${diff.markdown}
</details>`;
}

return [title(diff, repo.doc, repo.hub, repo.branch)]
return [title(diff, docName(diff, repo.doc, repo.hub, repo.branch))]
.concat([viewDiffLink(diff)])
.concat([text, emptySpace])
.concat([poweredByBump, bumpDiffComment(repo.docDigest, digest)])
.join('\n');
}

function title(diff: DiffResponse, doc: string, hub?: string, branch?: string): string {
let docName = [hub, doc].filter((e) => e).join('/');
// Capitalize doc name
docName = docName.charAt(0).toUpperCase() + docName.slice(1);
if (branch) {
docName = `${docName} (branch: ${branch})`;
}
function title(diff: DiffResponse, docName: string): string {
const structureTitle = `### 🤖 ${docName} API structural change detected`;
const contentTitle = `### ℹ️ ${docName} API content change detected`;
const breakingTitle = `### 🚨 Breaking ${docName} API change detected`;
Expand All @@ -61,3 +55,23 @@ function viewDiffLink(diff: DiffResponse): string {
return '';
}
}

function docName(
diff: DiffResponse & { doc_name?: string },

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cf PR description

About retro-compatibiliy:
Even if DiffResponse.doc_name will be included in the next release of bump-cli, field is missing for previous versions.

I handled the retro-compatibility with a bump.DiffResponse & { doc_name?: string } but I'm not very proud, WDYT dear reviewer?

doc: string,
hub?: string,
branch?: string,
): string {
const docNameFromDiff = diff.doc_name;
let name: string;
if (docNameFromDiff) {
name = docNameFromDiff;
} else {
name = [hub, doc].filter((e) => e).join('/');
name = name.charAt(0).toUpperCase() + name.slice(1);
}
if (branch) {
name = `${name} (branch: ${branch})`;
}
return name;
}
43 changes: 41 additions & 2 deletions tests/diff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,44 @@ describe('diff.ts', () => {
* three


</details>

###### _Powered by [Bump.sh](https://bump.sh)_
<!-- Bump.sh digest=${digest} doc=${docDigest} -->`,
digest,
);
});

test('test github diff run process (with doc_name)', async () => {
const result: bump.DiffResponse & { doc_name?: string } = {
id: '123abc',
markdown: `* one
* two
* three
`,
public_url: 'https://bump.sh/doc/my-doc/changes/654',
breaking: false,
doc_name: 'My API Documentation',
};
const digest = '4b81e612cafa6580f8ad3bfe9e970b2d961f58c2';

const repo = new Repo('id-42', '', 'v2');
const docDigest = shaDigest(['id-42', '', 'v2']);

await diff.run(result, repo);

expect(repo.createOrUpdateComment).toHaveBeenCalledWith(
`### 🤖 My API Documentation (branch: v2) API structural change detected

[Preview documentation](https://bump.sh/doc/my-doc/changes/654)

<details open><summary>Structural change details</summary>

* one
* two
* three


</details>

###### _Powered by [Bump.sh](https://bump.sh)_
Expand All @@ -69,10 +107,11 @@ describe('diff.ts', () => {
});

test('test github diff with no structural change', async () => {
const result: bump.DiffResponse = {
const result: bump.DiffResponse & { doc_name?: string } = {
id: '123abc',
public_url: 'https://bump.sh/doc/my-doc/changes/654',
breaking: false,
doc_name: 'My API Documentation',
};
const digest = '3999a0fe6ad27841bd6342128f7028ab2cea1c57';

Expand All @@ -81,7 +120,7 @@ describe('diff.ts', () => {
await diff.run(result, repo);

expect(repo.createOrUpdateComment).toHaveBeenCalledWith(
`### ℹ️ My-hub/hello (branch: v1) API content change detected
`### ℹ️ My API Documentation (branch: v1) API content change detected

[Preview documentation](https://bump.sh/doc/my-doc/changes/654)

Expand Down
Loading