Skip to content

Commit 10e7096

Browse files
AmirSa12Aslemammad
andauthored
chore: logs to inspect data (#404)
Co-authored-by: Mohammad Bagher Abiyat <[email protected]>
1 parent dc80b37 commit 10e7096

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

packages/app/server/routes/publish.post.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export default eventHandler(async (event) => {
3636
}
3737
const runId = Number(runIdHeader);
3838
const workflowsBucket = useWorkflowsBucket(event);
39+
const debugBucket = useDebugBucket(event);
3940
const workflowData = await workflowsBucket.getItem(key);
41+
const webhookDebugData = await debugBucket.getItem(key);
4042

4143
if (!workflowData) {
4244
throw createError({
@@ -323,6 +325,7 @@ export default eventHandler(async (event) => {
323325
workflowData,
324326
key,
325327
runId,
328+
webhookDebug: webhookDebugData,
326329
},
327330
};
328331
});

packages/app/server/routes/webhook.post.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { PullRequestEvent } from "@octokit/webhooks-types";
22
import type { HandlerFunction } from "@octokit/webhooks/dist-types/types";
3-
import type { PullRequestData, WorkflowData } from "../types";
3+
import type { PullRequestData, WorkflowData, WebhookDebugData } from "../types";
44
import { hash } from "ohash";
55

66
// mark a PR as a PR :)
@@ -16,6 +16,7 @@ export default eventHandler(async (event) => {
1616
const { test } = useRuntimeConfig(event);
1717
const workflowsBucket = useWorkflowsBucket(event);
1818
const pullRequestNumbersBucket = usePullRequestNumbersBucket(event);
19+
const debugBucket = useDebugBucket(event);
1920

2021
const workflowHandler: HandlerFunction<"workflow_run", unknown> = async ({
2122
payload,
@@ -51,9 +52,8 @@ export default eventHandler(async (event) => {
5152
await pullRequestNumbersBucket.hasItem(oldPrDataHash);
5253

5354
const isPullRequest = isNewPullRequest || isOldPullRequest;
54-
const prNumber = await pullRequestNumbersBucket.getItem(
55-
isNewPullRequest ? prKey : oldPrDataHash,
56-
);
55+
const lookupKey = isNewPullRequest ? prKey : oldPrDataHash;
56+
const prNumber = await pullRequestNumbersBucket.getItem(lookupKey);
5757

5858
const data: WorkflowData = {
5959
owner,
@@ -64,6 +64,27 @@ export default eventHandler(async (event) => {
6464

6565
// Publishing is only available throughout the lifetime of a workflow_job
6666
await workflowsBucket.setItem(hashKey, data);
67+
68+
const debugData: WebhookDebugData = {
69+
action: payload.action,
70+
head_branch: payload.workflow_run.head_branch,
71+
head_repository_full_name:
72+
payload.workflow_run.head_repository?.full_name || null,
73+
full_name: payload.repository.full_name,
74+
75+
isPullRequest,
76+
prNumber,
77+
prNumberType: typeof prNumber,
78+
isNewPullRequest,
79+
isOldPullRequest,
80+
81+
prKey,
82+
oldPrDataHash,
83+
lookupKey,
84+
data,
85+
};
86+
87+
await debugBucket.setItem(hashKey, debugData);
6788
}
6889
};
6990

packages/app/server/types.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,22 @@ export interface Cursor {
1414
timestamp: number;
1515
sha: string;
1616
}
17+
18+
export interface WebhookDebugData {
19+
webhookAction: string;
20+
originalHeadBranch: string | null;
21+
originalHeadRepository: string | null;
22+
originalRepositoryFullName: string | null;
23+
24+
isPullRequest: boolean;
25+
prNumber: number | null;
26+
prNumberType: string;
27+
isNewPullRequest: boolean;
28+
isOldPullRequest: boolean;
29+
30+
prKey: string;
31+
oldPrDataHash: string;
32+
lookupKey: string;
33+
34+
finalWorkflowData: WorkflowData;
35+
}

packages/app/server/utils/bucket.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { H3EventContext } from "h3";
2-
import type { Cursor, WorkflowData } from "../types";
2+
import type { Cursor, WorkflowData, WebhookDebugData } from "../types";
33
import { createStorage, joinKeys, prefixStorage } from "unstorage";
44
import cloudflareR2BindingDriver from "unstorage/drivers/cloudflare-r2-binding";
55
import { getR2Binding } from "unstorage/drivers/utils/cloudflare";
@@ -112,3 +112,11 @@ usePullRequestNumbersBucket.base = joinKeys(
112112
useBucket.base,
113113
usePullRequestNumbersBucket.key,
114114
);
115+
116+
export function useDebugBucket(event: Event) {
117+
const storage = useBucket(event);
118+
return prefixStorage<WebhookDebugData>(storage, useDebugBucket.key);
119+
}
120+
121+
useDebugBucket.key = "debug";
122+
useDebugBucket.base = joinKeys(useBucket.base, useDebugBucket.key);

0 commit comments

Comments
 (0)