Skip to content

Commit

Permalink
Drop use of lower-level custom HTML formatting
Browse files Browse the repository at this point in the history
Cleaner now to use hiccough-defined HTML output
  • Loading branch information
mikebroberts committed May 6, 2024
1 parent e36f848 commit ff47eb4
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 66 deletions.
12 changes: 4 additions & 8 deletions src/app/web/domainComponents/pushComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { latestCommitInPush } from '../../domain/github/githubPush'
import { commitCell, githubRepoUrl, repoCell } from './repoElementComponents'
import { userCell } from './userComponents'
import { GithubRepositoryElement } from '../../domain/types/GithubRepositoryElement'
import { inlineChildren, withOptions } from '../hiccough/hiccoughElement'
import { githubAnchor } from './genericComponents'

export type PushRowOptions = {
Expand Down Expand Up @@ -39,13 +38,10 @@ export function repoCellForPush(push: GithubPush) {
}

function branchCell(push: GithubRepositoryElement & Pick<GithubPush, 'ref'>) {
return withOptions(
inlineChildren,
td(
push.ref.split('/')[2],
`&nbsp;&nbsp;`,
githubAnchor(`${githubRepoUrl(push)}/tree/${push.ref.split('/')[2]}`)
)
return td(
push.ref.split('/')[2],
`&nbsp;`,
githubAnchor(`${githubRepoUrl(push)}/tree/${push.ref.split('/')[2]}`)
)
}

Expand Down
17 changes: 5 additions & 12 deletions src/app/web/domainComponents/repoElementComponents.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { GithubRepositoryElement } from '../../domain/types/GithubRepositoryElement'
import { inlineChildren, withOptions } from '../hiccough/hiccoughElement'
import { a, td } from '../hiccough/hiccoughElements'
import { githubAnchor } from './genericComponents'

Expand All @@ -11,10 +10,7 @@ export function repoCell({
}: GithubRepositoryElement & {
repoHtmlUrl: string
}) {
return withOptions(
inlineChildren,
td(a(`/app/account/${ownerId}/repo/${repoId}`, repoName), '&nbsp;&nbsp;', githubAnchor(repoHtmlUrl))
)
return td(a(`/app/account/${ownerId}/repo/${repoId}`, repoName), '&nbsp;', githubAnchor(repoHtmlUrl))
}

export function githubRepoUrl({
Expand All @@ -32,12 +28,9 @@ export function commitCell(
}
) {
const { repoHtmlUrl, message, sha } = event
return withOptions(
inlineChildren,
td(
message.length < 40 ? message : `${message.substring(0, 40)}...`,
'&nbsp;&nbsp;',
githubAnchor(`${repoHtmlUrl ?? githubRepoUrl(event)}/commit/${sha}`)
)
return td(
message.length < 40 ? message : `${message.substring(0, 40)}...`,
'&nbsp;',
githubAnchor(`${repoHtmlUrl ?? githubRepoUrl(event)}/commit/${sha}`)
)
}
6 changes: 1 addition & 5 deletions src/app/web/domainComponents/userComponents.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { td } from '../hiccough/hiccoughElements'
import { inlineChildren, withOptions } from '../hiccough/hiccoughElement'
import { githubAnchor } from './genericComponents'

export function userCell(actor?: { login: string }) {
return actor === undefined
? td()
: withOptions(
inlineChildren,
td(actor.login, `&nbsp;&nbsp;`, githubAnchor(`https://github.com/${actor.login}`))
)
: td(actor.login, `&nbsp;`, githubAnchor(`https://github.com/${actor.login}`))
}
23 changes: 8 additions & 15 deletions src/app/web/domainComponents/workflowComponents.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { GithubWorkflowRunEvent } from '../../domain/types/GithubWorkflowRunEvent'
import { GithubRepositoryElement } from '../../domain/types/GithubRepositoryElement'
import { inlineChildren, withOptions } from '../hiccough/hiccoughElement'
import { a, td, tr } from '../hiccough/hiccoughElements'
import { Clock, displayDateTime } from '../../util/dateAndTime'
import { githubAnchor } from './genericComponents'
Expand Down Expand Up @@ -55,16 +54,13 @@ export function workflowCell(
Pick<GithubWorkflowRunEvent, 'workflowHtmlUrl' | 'workflowId' | 'workflowName' | 'path'>
) {
const workflowPath = `${event.path.substring(event.path.indexOf('/') + 1)}`
return withOptions(
inlineChildren,
td(
a(
`/app/account/${event.ownerId}/repo/${event.repoId}/workflow/${event.workflowId}`,
event.workflowName ?? workflowPath
),
'&nbsp;&nbsp;',
githubAnchor(event.workflowHtmlUrl ?? `${githubRepoUrl(event)}/actions/${workflowPath}`)
)
return td(
a(
`/app/account/${event.ownerId}/repo/${event.repoId}/workflow/${event.workflowId}`,
event.workflowName ?? workflowPath
),
'&nbsp;',
githubAnchor(event.workflowHtmlUrl ?? `${githubRepoUrl(event)}/actions/${workflowPath}`)
)
}

Expand All @@ -77,10 +73,7 @@ const successfulRunResultCell = td('Success')
const failedRunResultCell = td('Failed')

export function workflowRunCell(clock: Clock, event: GithubWorkflowRunEvent) {
return withOptions(
inlineChildren,
td(displayDateTime(clock, event.updatedAt), '&nbsp;&nbsp;', githubAnchor(event.htmlUrl))
)
return td(displayDateTime(clock, event.updatedAt), '&nbsp;', githubAnchor(event.htmlUrl))
}

export function commitCellForWorkflowRunEvent(event: GithubWorkflowRunEvent) {
Expand Down
20 changes: 8 additions & 12 deletions src/app/web/views/showRepoView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { GithubWorkflowRunEvent } from '../../domain/types/GithubWorkflowRunEven
import { githubAnchor } from '../domainComponents/genericComponents'
import { GithubRepository } from '../../domain/types/GithubRepository'
import { h3, h4, table, tbody, th, thead, tr } from '../hiccough/hiccoughElements'
import { inlineChildren, withOptions } from '../hiccough/hiccoughElement'
import { pageViewResultWithoutHtmx } from './viewResultWrappers'
import { workflowRow } from '../domainComponents/workflowComponents'
import { pushRow } from '../domainComponents/pushComponents'
Expand All @@ -17,17 +16,14 @@ export function createShowRepoResponse(
activity: GithubActivity[]
) {
const contents = [
withOptions(
inlineChildren,
h3(
`Repository: ${repo.ownerName}/${repo.name}`,
`&nbsp;&nbsp;`,
githubAnchor(
githubRepoUrl({
...repo,
repoName: repo.name
})
)
h3(
`Repository: ${repo.ownerName}/${repo.name}`,
`&nbsp;`,
githubAnchor(
githubRepoUrl({
...repo,
repoName: repo.name
})
)
),
h4('GitHub Actions Status'),
Expand Down
54 changes: 45 additions & 9 deletions test/local/functional/web/latestActivity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,32 @@ test('latest-activity', async () => {
</thead>
<tbody>
<tr class="success">
<td><a href="/app/account/162483619/repo/768206479">org-test-repo-one</a>&nbsp;&nbsp;<a href="https://github.com/cicada-test-org/org-test-repo-one"><i class='bi bi-github' style='color: #6e5494'></i></a></td>
<td><a href="/app/account/162483619/repo/768206479/workflow/88647110">Test Repo One Workflow</a>&nbsp;&nbsp;<a href="https://github.com/cicada-test-org/org-test-repo-one/actions/workflows/test.yml"><i class='bi bi-github' style='color: #6e5494'></i></a></td>
<td>
<a href="/app/account/162483619/repo/768206479">org-test-repo-one</a>
&nbsp;
<a href="https://github.com/cicada-test-org/org-test-repo-one"><i class='bi bi-github' style='color: #6e5494'></i></a>
</td>
<td>
<a href="/app/account/162483619/repo/768206479/workflow/88647110">Test Repo One Workflow</a>
&nbsp;
<a href="https://github.com/cicada-test-org/org-test-repo-one/actions/workflows/test.yml"><i class='bi bi-github' style='color: #6e5494'></i></a>
</td>
<td>Success</td>
<td>2024-03-06T19:25:42Z&nbsp;&nbsp;<a href="https://github.com/cicada-test-org/org-test-repo-one/actions/runs/8177622236"><i class='bi bi-github' style='color: #6e5494'></i></a></td>
<td>mikebroberts&nbsp;&nbsp;<a href="https://github.com/mikebroberts"><i class='bi bi-github' style='color: #6e5494'></i></a></td>
<td>Test Repo One Workflow&nbsp;&nbsp;<a href="https://github.com/cicada-test-org/org-test-repo-one/commit/8c3aa1cb0316ea23abeb2612457edb80868f53c8"><i class='bi bi-github' style='color: #6e5494'></i></a></td>
<td>
2024-03-06T19:25:42Z
&nbsp;
<a href="https://github.com/cicada-test-org/org-test-repo-one/actions/runs/8177622236"><i class='bi bi-github' style='color: #6e5494'></i></a>
</td>
<td>
mikebroberts
&nbsp;
<a href="https://github.com/mikebroberts"><i class='bi bi-github' style='color: #6e5494'></i></a>
</td>
<td>
Test Repo One Workflow
&nbsp;
<a href="https://github.com/cicada-test-org/org-test-repo-one/commit/8c3aa1cb0316ea23abeb2612457edb80868f53c8"><i class='bi bi-github' style='color: #6e5494'></i></a>
</td>
</tr>
</tbody>
</table>
Expand All @@ -136,11 +156,27 @@ test('latest-activity', async () => {
</thead>
<tbody>
<tr class="info">
<td><a href="/app/account/162483619/repo/768206479">org-test-repo-one</a>&nbsp;&nbsp;<a href="https://github.com/cicada-test-org/org-test-repo-one"><i class='bi bi-github' style='color: #6e5494'></i></a></td>
<td>main&nbsp;&nbsp;<a href="https://github.com/cicada-test-org/org-test-repo-one/tree/main"><i class='bi bi-github' style='color: #6e5494'></i></a></td>
<td>
<a href="/app/account/162483619/repo/768206479">org-test-repo-one</a>
&nbsp;
<a href="https://github.com/cicada-test-org/org-test-repo-one"><i class='bi bi-github' style='color: #6e5494'></i></a>
</td>
<td>
main
&nbsp;
<a href="https://github.com/cicada-test-org/org-test-repo-one/tree/main"><i class='bi bi-github' style='color: #6e5494'></i></a>
</td>
<td>2024-03-06T17:00:40Z</td>
<td>mikebroberts&nbsp;&nbsp;<a href="https://github.com/mikebroberts"><i class='bi bi-github' style='color: #6e5494'></i></a></td>
<td>test workflow&nbsp;&nbsp;<a href="https://github.com/cicada-test-org/org-test-repo-one/commit/8c3aa1cb0316ea23abeb2612457edb80868f53c8"><i class='bi bi-github' style='color: #6e5494'></i></a></td>
<td>
mikebroberts
&nbsp;
<a href="https://github.com/mikebroberts"><i class='bi bi-github' style='color: #6e5494'></i></a>
</td>
<td>
test workflow
&nbsp;
<a href="https://github.com/cicada-test-org/org-test-repo-one/commit/8c3aa1cb0316ea23abeb2612457edb80868f53c8"><i class='bi bi-github' style='color: #6e5494'></i></a>
</td>
</tr>
</tbody>
</table>
Expand Down
30 changes: 25 additions & 5 deletions test/local/functional/web/viewRepo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ test('view-repo', async () => {
<body>
<div class="container" id="toplevel">
<h2>Cicada</h2>
<h3>Repository: cicada-test-org/org-test-repo-one&nbsp;&nbsp;<a href="https://github.com/cicada-test-org/org-test-repo-one"><i class='bi bi-github' style='color: #6e5494'></i></a></h3>
<h3>
Repository: cicada-test-org/org-test-repo-one
&nbsp;
<a href="https://github.com/cicada-test-org/org-test-repo-one"><i class='bi bi-github' style='color: #6e5494'></i></a>
</h3>
<h4>GitHub Actions Status</h4>
<table class="table">
<thead>
Expand Down Expand Up @@ -120,10 +124,26 @@ test('view-repo', async () => {
<tbody>
<tr class="success">
<td>Successful Run</td>
<td><a href="/app/account/162483619/repo/768206479/workflow/88647110">Test Repo One Workflow</a>&nbsp;&nbsp;<a href="https://github.com/cicada-test-org/org-test-repo-one/actions/workflows/test.yml"><i class='bi bi-github' style='color: #6e5494'></i></a></td>
<td>2024-03-06T19:25:42Z&nbsp;&nbsp;<a href="https://github.com/cicada-test-org/org-test-repo-one/actions/runs/8177622236"><i class='bi bi-github' style='color: #6e5494'></i></a></td>
<td>mikebroberts&nbsp;&nbsp;<a href="https://github.com/mikebroberts"><i class='bi bi-github' style='color: #6e5494'></i></a></td>
<td>Test Repo One Workflow&nbsp;&nbsp;<a href="https://github.com/cicada-test-org/org-test-repo-one/commit/8c3aa1cb0316ea23abeb2612457edb80868f53c8"><i class='bi bi-github' style='color: #6e5494'></i></a></td>
<td>
<a href="/app/account/162483619/repo/768206479/workflow/88647110">Test Repo One Workflow</a>
&nbsp;
<a href="https://github.com/cicada-test-org/org-test-repo-one/actions/workflows/test.yml"><i class='bi bi-github' style='color: #6e5494'></i></a>
</td>
<td>
2024-03-06T19:25:42Z
&nbsp;
<a href="https://github.com/cicada-test-org/org-test-repo-one/actions/runs/8177622236"><i class='bi bi-github' style='color: #6e5494'></i></a>
</td>
<td>
mikebroberts
&nbsp;
<a href="https://github.com/mikebroberts"><i class='bi bi-github' style='color: #6e5494'></i></a>
</td>
<td>
Test Repo One Workflow
&nbsp;
<a href="https://github.com/cicada-test-org/org-test-repo-one/commit/8c3aa1cb0316ea23abeb2612457edb80868f53c8"><i class='bi bi-github' style='color: #6e5494'></i></a>
</td>
</tr>
</tbody>
</table>
Expand Down

0 comments on commit ff47eb4

Please sign in to comment.