| banksean | bdc6889 | 2025-07-28 17:28:13 -0700 | [diff] [blame] | 1 | import { html, TemplateResult } from "lit"; |
| 2 | import { customElement, property, state } from "lit/decorators.js"; |
| 3 | import { ExternalMessage } from "../types"; |
| 4 | import { SketchTailwindElement } from "./sketch-tailwind-element"; |
| 5 | import type { WorkflowRunEvent } from "@octokit/webhooks-types"; |
| 6 | |
| 7 | @customElement("sketch-external-message") |
| 8 | export class SketchExternalMessage extends SketchTailwindElement { |
| 9 | @property() message: ExternalMessage | null = null; |
| 10 | @property() open: boolean; |
| 11 | @property() summaryContent: TemplateResult | string = ""; |
| 12 | @property() detailsContent: TemplateResult | string = ""; |
| 13 | @state() detailsVisible: boolean = false; |
| 14 | |
| 15 | _toggleDetails(e: Event) { |
| 16 | e.stopPropagation(); |
| 17 | this.detailsVisible = !this.detailsVisible; |
| 18 | } |
| 19 | |
| 20 | constructor() { |
| 21 | super(); |
| 22 | } |
| 23 | |
| 24 | render() { |
| 25 | if (this.message?.message_type === "github_workflow_run") { |
| 26 | const run = this.message.body as WorkflowRunEvent; |
| 27 | this.summaryContent = html`<svg |
| 28 | class="inline-block w-4 h-4" |
| 29 | viewBox="0 0 16 16" |
| 30 | width="16" |
| 31 | height="16" |
| 32 | > |
| 33 | <path |
| 34 | fill="currentColor" |
| 35 | d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z" |
| 36 | ></path> |
| 37 | </svg> |
| 38 | <span |
| 39 | class="inline-flex items-center px-1.5 py-1 |
| 40 | ${run.workflow_run.conclusion === "success" |
| 41 | ? "bg-green-600/10 text-green-600" |
| 42 | : run.workflow_run.conclusion === "failure" |
| 43 | ? "bg-red-600/10 text-red-600" |
| 44 | : "bg-gray-600/10 text-gray-600"} |
| 45 | rounded-md text-xs flex-shrink-0 transition-colors" |
| 46 | >${run.workflow.name} - |
| 47 | ${run.workflow_run.conclusion || run.workflow_run.status}</span |
| 48 | > |
| banksean | 66f45a6 | 2025-07-30 13:11:25 -0700 | [diff] [blame] | 49 | on ${run.workflow_run.head_branch} at |
| 50 | ${run.workflow_run.head_sha.substring(0, 7)}`; |
| banksean | bdc6889 | 2025-07-28 17:28:13 -0700 | [diff] [blame] | 51 | |
| 52 | this.detailsContent = html` |
| 53 | <div class="flex items-center gap-2"> |
| 54 | <span class="text-gray-700 dark:text-gray-300">Workflow ID:</span> |
| 55 | <span class="font-mono font-medium text-gray-800 dark:text-gray-200">${run.workflow_run.id}</span> |
| 56 | </div> |
| 57 | <div class="flex items-center gap-2"> |
| 58 | bg-gray-600/10 text-gray-600 |
| 59 | {{end}} |
| 60 | rounded-md text-xs flex-shrink-0 transition-colors'><a target="_blank" |
| 61 | rel="noopener noreferrer"href="${run.workflow_run.html_url}">${run.workflow.name} - ${run.workflow_run.conclusion}</a> |
| 62 | on ${run.workflow_run.head_branch} at ${run.workflow_run.head_commit}</span> |
| 63 | </span>`; |
| 64 | |
| 65 | this.detailsContent = html` |
| 66 | <div class="flex items-center gap-2"> |
| 67 | <span class="text-gray-700 dark:text-gray-300">Workflow Run ID:</span> |
| 68 | <span class="font-mono font-medium text-gray-800 dark:text-gray-200" |
| 69 | >${run.workflow_run.id}</span |
| 70 | > |
| 71 | </div> |
| 72 | <div class="flex items-center gap-2"> |
| 73 | <span class="text-gray-700 dark:text-gray-300">Status:</span> |
| 74 | <span class="font-mono font-medium text-gray-800 dark:text-gray-200" |
| 75 | >${run.workflow_run.status}</span |
| 76 | > |
| 77 | </div> |
| 78 | <div class="flex items-center gap-2"> |
| 79 | <span class="text-gray-700 dark:text-gray-300">Conclusion:</span> |
| 80 | <span class="font-mono font-medium text-gray-800 dark:text-gray-200" |
| 81 | >${run.workflow_run.conclusion}</span |
| 82 | > |
| 83 | </div> |
| 84 | <div class="flex items-center gap-2"> |
| 85 | <span class="text-gray-700 dark:text-gray-300">Run URL:</span> |
| 86 | <a |
| 87 | class="text-blue-600 dark:text-blue-400 hover:underline" |
| 88 | href="${run.workflow_run.html_url}" |
| 89 | target="_blank" |
| 90 | rel="noopener noreferrer" |
| 91 | > |
| 92 | ${run.workflow_run.html_url} |
| 93 | </a> |
| 94 | </div> |
| 95 | `; |
| 96 | } |
| 97 | |
| 98 | return html` |
| 99 | <div class="block max-w-full w-full box-border overflow-hidden"> |
| 100 | <div class="flex flex-col w-full"> |
| 101 | <div |
| 102 | class="flex w-full box-border py-1.5 px-2 pl-3 items-center gap-2 cursor-pointer rounded relative overflow-hidden flex-wrap hover:bg-black/[0.02] dark:hover:bg-white/[0.05]" |
| 103 | @click=${this._toggleDetails} |
| 104 | > |
| 105 | <span |
| 106 | class="whitespace-nowrap flex-grow flex-shrink text-gray-700 dark:text-gray-300 font-mono text-xs px-1 min-w-[50px] max-w-[calc(100%-150px)] inline-block" |
| 107 | >${this.summaryContent}</span |
| 108 | > |
| 109 | </div> |
| 110 | <div |
| 111 | class="${this.detailsVisible |
| 112 | ? "block" |
| 113 | : "hidden"} p-2 bg-black/[0.02] dark:bg-white/[0.05] mt-px border-t border-black/[0.05] dark:border-white/[0.1] font-mono text-xs text-gray-800 dark:text-gray-200 rounded-b max-w-full w-full box-border overflow-hidden" |
| 114 | > |
| 115 | ${this.detailsContent |
| 116 | ? html`<div class="mb-2">${this.detailsContent}</div>` |
| 117 | : ""} |
| 118 | </div> |
| 119 | </div> |
| 120 | </div> |
| 121 | `; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | declare global { |
| 126 | interface HTMLElementTagNameMap { |
| 127 | "sketch-notification-message": SketchExternalMessage; |
| 128 | } |
| 129 | } |