Skip to content
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
22 changes: 11 additions & 11 deletions dist/build.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions dist/merge.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions dist/preview.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/__snapshots__/comment.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`printComment > should print comment 1`] = `
"<h3>✱ Stainless preview builds</h3>
"<h3>✱ Stainless preview builds for test-project</h3>

This PR will update the <code>test-project</code> SDKs with the following commit message.

Expand Down
5 changes: 3 additions & 2 deletions src/comment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ describe("printComment", () => {
});

it("should print no changes comment", () => {
expect(printComment({ noChanges: true })).toMatchInlineSnapshot(`
"<h3>✱ Stainless preview builds</h3>
expect(printComment({ noChanges: true, projectName: "fake project" }))
.toMatchInlineSnapshot(`
"<h3>✱ Stainless preview builds for fake project</h3>

No changes were made to the SDKs.

Expand Down
27 changes: 18 additions & 9 deletions src/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import {
sortDiagnostics,
} from "./outcomes";

const COMMENT_TITLE = MD.Heading(
`${MD.Symbol.HeavyAsterisk} Stainless preview builds`,
);
const COMMENT_TITLE = (projectName: string | null) =>
MD.Heading(
`${MD.Symbol.HeavyAsterisk} Stainless preview builds${projectName ? ` for ${projectName}` : ""}`,
);

const COMMENT_FOOTER_DIVIDER = MD.Comment("stainless-preview-footer");

Expand Down Expand Up @@ -41,8 +42,11 @@ export function printComment({
outcomes,
}:
| ({ noChanges?: never } & Omit<PrintCommentOptions, "noChanges">)
| ({ noChanges: true } & {
[K in keyof Omit<PrintCommentOptions, "noChanges">]?: never;
| ({ noChanges: true; projectName: string } & {
[K in keyof Omit<
Omit<PrintCommentOptions, "noChanges">,
"projectName"
>]?: never;
})) {
const Blocks = (() => {
if (noChanges) {
Expand Down Expand Up @@ -84,7 +88,7 @@ export function printComment({
.replace(/\.\d+Z$/, " UTC");

const fullComment = MD.Dedent`
${COMMENT_TITLE}
${COMMENT_TITLE(projectName)}

${Blocks}

Expand Down Expand Up @@ -564,11 +568,16 @@ export function parseCommitMessages(body?: string | null): {
: {};
}

export async function retrieveComment(prNumber: number) {
export async function retrieveComment(prNumber: number, projectName: string) {
const comments = await api().listComments(prNumber);

const existingComment = comments.find((comment) =>
comment.body?.includes(COMMENT_TITLE),
const existingComment = comments.find(
(comment) =>
comment.body?.includes(COMMENT_TITLE(projectName)) ||
// backwards compatibility for comments that don't include the project name
// TODO: remove this fallback eventually
(!comment.body?.includes(COMMENT_TITLE(null) + " for") &&
comment.body?.includes(COMMENT_TITLE(null))),
);

if (!existingComment) {
Expand Down
4 changes: 3 additions & 1 deletion src/merge.run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ export async function runMerge(
}

const comment =
makeComment && prNumber ? await retrieveComment(prNumber) : null;
makeComment && prNumber
? await retrieveComment(prNumber, projectName)
: null;
const commitMessage =
comment?.commitMessage ??
makeCommitMessageConventional(defaultCommitMessage);
Expand Down
8 changes: 5 additions & 3 deletions src/preview.run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export async function runPreview(
if (makeComment) {
logger.group("Updating comment");

const commentBody = printComment({ noChanges: true });
const commentBody = printComment({ noChanges: true, projectName });

await upsertComment(prNumber, {
body: commentBody,
Expand All @@ -163,7 +163,9 @@ export async function runPreview(

logger.groupEnd();

const initialComment = makeComment ? await retrieveComment(prNumber) : null;
const initialComment = makeComment
? await retrieveComment(prNumber, projectName)
: null;
let commitMessage =
initialComment?.commitMessage ??
makeCommitMessageConventional(defaultCommitMessage);
Expand Down Expand Up @@ -215,7 +217,7 @@ export async function runPreview(
const { outcomes, baseOutcomes } = latestRun;

// In case the comment was updated between polls:
const comment = await retrieveComment(prNumber);
const comment = await retrieveComment(prNumber, projectName);
commitMessage = comment?.commitMessage ?? commitMessage;
targetCommitMessages =
comment?.targetCommitMessages ?? targetCommitMessages;
Expand Down
Loading