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
2 changes: 0 additions & 2 deletions .github/workflows/stats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: pkg.pr.new stats

on:
push:
branches:
- main

jobs:
stats:
Expand Down
59 changes: 19 additions & 40 deletions packages/backend/server/routes/publish.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,46 +254,25 @@ export default eventHandler(async (event) => {
},
);
} else {
try {
await installation.request(
"POST /repos/{owner}/{repo}/issues/{issue_number}/comments",
{
owner: workflowData.owner,
repo: workflowData.repo,
issue_number: Number(workflowData.ref),
body: generatePullRequestPublishMessage(
origin,
templatesHtmlMap,
packagesWithoutPrefix,
workflowData,
compact,
onlyTemplates,
checkRunUrl,
packageManager,
comment === "update" ? "ref" : "sha",
),
},
);
} catch (error) {
throw createError({
statusCode: 500,
message: `Failed to create pull request comment. Details:
Error: ${error instanceof Error ? error.message : String(error)}
Context:
- Owner: ${workflowData.owner}
- Repo: ${workflowData.repo}
- Issue Number: ${Number(workflowData.ref)}
- Origin: ${origin}
- Templates: ${JSON.stringify(templatesHtmlMap)}
- Packages: ${packagesWithoutPrefix.join(', ')}
- Workflow Data: ${JSON.stringify(workflowData)}
- Compact: ${compact}
- Only Templates: ${onlyTemplates}
- Check Run URL: ${checkRunUrl}
- Package Manager: ${packageManager}
- Comment Type: ${comment === "update" ? "ref" : "sha"}`,
});
}
await installation.request(
"POST /repos/{owner}/{repo}/issues/{issue_number}/comments",
{
owner: workflowData.owner,
repo: workflowData.repo,
issue_number: Number(workflowData.ref),
body: generatePullRequestPublishMessage(
origin,
templatesHtmlMap,
packagesWithoutPrefix,
workflowData,
compact,
onlyTemplates,
checkRunUrl,
packageManager,
comment === "update" ? "ref" : "sha",
),
},
);
}
}
}
Expand Down
25 changes: 18 additions & 7 deletions packages/backend/server/routes/webhook.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export default eventHandler(async (event) => {
const { test } = useRuntimeConfig(event);
const workflowsBucket = useWorkflowsBucket(event);
const pullRequestNumbersBucket = usePullRequestNumbersBucket(event);
const cursorBucket = useCursorsBucket(event);

const workflowHandler: HandlerFunction<"workflow_run", unknown> = async ({
payload,
Expand All @@ -42,9 +41,20 @@ export default eventHandler(async (event) => {
full_name: payload.workflow_run.head_repository.full_name,
ref: payload.workflow_run.head_branch,
};
const prDataHash = hash(prData);
const isPullRequest = await pullRequestNumbersBucket.hasItem(prDataHash);
const prNumber = await pullRequestNumbersBucket.getItem(prDataHash);
// new: using the new key to avoid collision
const prKey = `${prData.full_name}:${prData.ref}`;
const isNewPullRequest = await pullRequestNumbersBucket.hasItem(prKey);

// old: the old of hashing the prData started to hit collision, so we need to use the new one (e.g. https://github.com/element-plus/element-plus/actions/runs/12351113750/job/34465376908)
const oldPrDataHash = hash(prData);
const isOldPullRequest = await pullRequestNumbersBucket.hasItem(
oldPrDataHash,
);

const isPullRequest = isNewPullRequest || isOldPullRequest;
const prNumber = await pullRequestNumbersBucket.getItem(
isNewPullRequest ? prKey : oldPrDataHash,
);

const data: WorkflowData = {
owner,
Expand All @@ -64,15 +74,16 @@ export default eventHandler(async (event) => {
const pullRequestHandler: HandlerFunction<"pull_request", unknown> = async ({
payload,
}) => {
const [owner, repo] = payload.repository.full_name.split("/");
// TODO: functions that generate these kinda keys
const key: PullRequestData = {
full_name: payload.pull_request.head.repo?.full_name!,
ref: payload.pull_request.head.ref,
};
const prDataHash = hash(key);
if (prMarkEvents.includes(payload.action)) {
await pullRequestNumbersBucket.setItem(prDataHash, payload.number);
await pullRequestNumbersBucket.setItem(
`${key.full_name}:${key.ref}`,
payload.number,
);
}
};

Expand Down
Loading