Skip to content

Commit cc4bcf4

Browse files
committed
feat(feed): add forked repo url
1 parent f4c481f commit cc4bcf4

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

src/pages/feed.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
{{ username }}
1616
</a>
1717
{{ action }}
18-
<template v-if="eventUrl">
19-
<span v-dompurify-html="eventUrl" />
20-
in
21-
</template>
18+
<span v-if="eventUrl" v-dompurify-html="eventUrl" />
2219
<a
2320
:href="`https://github.com/${repo}`"
2421
target="_blank"

src/store/events.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const TARGET_EVENTS = [
1818
const FILTERED_ACTIONS = [
1919
"labeled",
2020
"unlabeled"
21-
];
21+
] as const;
2222

2323
function getActionString({ type, payload }: RawEvent): string {
2424
switch (type) {
@@ -31,10 +31,16 @@ function getActionString({ type, payload }: RawEvent): string {
3131
}
3232
}
3333

34-
function formatIssueString({ issue }: RawEvent["payload"]): string | null {
35-
if (!issue) return null;
36-
const { html_url, number, title } = issue;
37-
return `<a href="${html_url}" rel="noopener noreferrer" title="Go to issue">#${number} ${title}</a>`;
34+
function composeEventUrl(event: RawEvent): string | null {
35+
if (event.type === "IssuesEvent" && event.payload.issue) {
36+
const { html_url, number, title } = event.payload.issue;
37+
return `<a href="${html_url}" rel="noopener noreferrer" title="Go to issue">#${number} ${title}</a> in `;
38+
}
39+
if (event.type === "ForkEvent" && "forkee" in event.payload) {
40+
const { html_url, full_name } = event.payload.forkee as { html_url: string, full_name: string };
41+
return `<a href="${html_url}" rel="noopener noreferrer" title="Go to forked repository">${full_name}</a> from `;
42+
}
43+
return null;
3844
}
3945

4046
interface FeedEvent {
@@ -82,7 +88,7 @@ export const useEventsStore = createGlobalState(() => {
8288
username: event.actor.display_login ?? event.actor.login,
8389
action: getActionString(event),
8490
repo: event.repo.name,
85-
eventUrl: event.type === "IssuesEvent" ? formatIssueString(event.payload) : undefined
91+
eventUrl: composeEventUrl(event)
8692
};
8793
acc.push(feedEvent);
8894
}

0 commit comments

Comments
 (0)