Browse Source

feat(PRPage): custom display of commit events

display summary of 317 commit event
master
DanConwayDev 2 years ago
parent
commit
eca198799f
No known key found for this signature in database
GPG Key ID: 68E15486D73F75E1
  1. 3
      package.json
  2. 53
      src/lib/components/events/content/Kind317.svelte
  3. 2
      src/lib/components/prs/type.ts
  4. 1
      src/lib/stores/PR.ts
  5. 3
      src/lib/stores/PRs.ts
  6. 9
      src/lib/wrappers/EventCard.svelte
  7. 3
      src/routes/repo/[repo_id]/pr/[pr_id]/+page.svelte
  8. 5
      yarn.lock

3
package.json

@ -51,7 +51,8 @@ @@ -51,7 +51,8 @@
"@nostr-dev-kit/ndk-svelte": "^1.3.0",
"@nostr-dev-kit/ndk-svelte-components": "^1.3.0",
"daisyui": "^4.4",
"dayjs": "^1.11.10"
"dayjs": "^1.11.10",
"parse-diff": "^0.11.1"
},
"resolutions": {
"jackspeak": "2.1.1"

53
src/lib/components/events/content/Kind317.svelte

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
<script lang="ts">
import type { NDKTag } from "@nostr-dev-kit/ndk";
import parseDiff from "parse-diff";
export let content: string = "";
export let tags: NDKTag[] = [];
export let lite: boolean = true;
let commit_id = extractTagContent("commit") || "[unknown commit_id]";
let commit_message = extractTagContent("description") || "[untitled]";
let files = parseDiff(content);
function extractTagContent(name: string): string | undefined {
let tag = tags.find((tag) => tag[0] === name);
return tag ? tag[1] : undefined;
}
</script>
<div class="">
<div class="bg-base-300 rounded-t p-1 flex">
<article class="ml-2 prose font-mono flex-grow">
{commit_message}
</article>
<div class="text-xs text-neutral p-1 flex-none align-middle">
commit
</div>
</div>
<div class="bg-base-200 p-1 rounded-b">
<table class="table table-xs table-zebra">
<tr>
<td class="text-xs">Changes:</td>
</tr>
{#each files as file}
<tr>
<td>
<span
class:text-success={file.new}
class:text-error={file.deleted}
class="text-success"
>
{file.to || file.from}
</span>
</td>
<td class="text-right">
<span class="text-success">+{file.additions}</span>
<span class="text-error">- {file.deletions}</span>
</td>
</tr>
{/each}
</table>
</div>
</div>

2
src/lib/components/prs/type.ts

@ -5,6 +5,7 @@ import type { NDKEvent } from "@nostr-dev-kit/ndk"; @@ -5,6 +5,7 @@ import type { NDKEvent } from "@nostr-dev-kit/ndk";
export interface PRSummary {
title: string;
descritpion: string;
repo_id: string;
id: string;
comments: number;
@ -15,6 +16,7 @@ export interface PRSummary { @@ -15,6 +16,7 @@ export interface PRSummary {
export const summary_defaults: PRSummary = {
title: "",
descritpion: "",
repo_id: "",
id: "",
comments: 0,

1
src/lib/stores/PR.ts

@ -54,6 +54,7 @@ export let ensurePRFull = (repo_id: string, pr_id: string) => { @@ -54,6 +54,7 @@ export let ensurePRFull = (repo_id: string, pr_id: string) => {
summary: {
...full.summary,
title: event.tagValue("name") || "",
descritpion: event.tagValue("description") || "",
created_at: event.created_at,
comments: 0,
author: {

3
src/lib/stores/PRs.ts

@ -49,7 +49,6 @@ export let ensurePRSummaries = (repo_id: string) => { @@ -49,7 +49,6 @@ export let ensurePRSummaries = (repo_id: string) => {
if (event.kind == pr_kind
&& event.getMatchingTags("r").find(t => t[1] === `r-${repo_id}`)
) {
console.log(event);
pr_summaries.update(prs => {
return {
...prs,
@ -60,6 +59,7 @@ export let ensurePRSummaries = (repo_id: string) => { @@ -60,6 +59,7 @@ export let ensurePRSummaries = (repo_id: string) => {
id: event.id,
repo_id: repo_id,
title: event.tagValue("name") || "",
descritpion: event.tagValue("description") || "",
created_at: event.created_at,
comments: 0,
author: {
@ -76,7 +76,6 @@ export let ensurePRSummaries = (repo_id: string) => { @@ -76,7 +76,6 @@ export let ensurePRSummaries = (repo_id: string) => {
authors_unsubscribers.push(
ensureUser(event.pubkey).subscribe((u: User) => {
pr_summaries.update(prs => {
console.log('test');
return {
...prs,
summaries: prs.summaries.map(o => ({

9
src/lib/wrappers/EventCard.svelte

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
<script lang="ts">
import EventWrapper from "$lib/components/events/EventWrapper.svelte";
import Kind317 from "$lib/components/events/content/Kind317.svelte";
import type { User } from "$lib/components/users/type";
import { defaults as user_defaults } from "$lib/components/users/type";
import { ensureUser } from "$lib/stores/users";
@ -18,4 +19,10 @@ @@ -18,4 +19,10 @@
});
</script>
<EventWrapper author={$author}>{event.content}</EventWrapper>
<EventWrapper author={$author}>
{#if event.kind == 317}
<Kind317 content={event.content} tags={event.tags} />
{:else}
{event.content}
{/if}
</EventWrapper>

3
src/routes/repo/[repo_id]/pr/[pr_id]/+page.svelte

@ -22,6 +22,9 @@ @@ -22,6 +22,9 @@
<div class="flex">
<div class="w-2/3 mx-2">
<div class="prose my-3">
{$selected_pr_full.summary.descritpion}
</div>
{#if $selected_pr_full.pr_event}
<Thread event={$selected_pr_full.pr_event} />
{/if}

5
yarn.lock

@ -7676,6 +7676,11 @@ parent-module@^1.0.0: @@ -7676,6 +7676,11 @@ parent-module@^1.0.0:
dependencies:
callsites "^3.0.0"
parse-diff@^0.11.1:
version "0.11.1"
resolved "https://registry.yarnpkg.com/parse-diff/-/parse-diff-0.11.1.tgz#d93ca2d225abed280782bccb1476711ca9dd84f0"
integrity sha512-Oq4j8LAOPOcssanQkIjxosjATBIEJhCxMCxPhMu+Ci4wdNmAEdx0O+a7gzbR2PyKXgKPvRLIN5g224+dJAsKHA==
parse-json@^5.0.0, parse-json@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-5.2.0.tgz#c76fc66dee54231c962b22bcc8a72cf2f99753cd"

Loading…
Cancel
Save