-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e036840
commit e36f848
Showing
11 changed files
with
284 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { a } from '../hiccough/hiccoughElements' | ||
|
||
export function githubAnchor(target: string) { | ||
return a(target, `<i class='bi bi-github' style='color: #6e5494'></i>`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Clock, displayDateTime } from '../../util/dateAndTime' | ||
import { GithubPush } from '../../domain/types/GithubPush' | ||
import { td, tr } from '../hiccough/hiccoughElements' | ||
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 = { | ||
showDescriptionCell?: boolean | ||
showRepoCell?: boolean | ||
} | ||
|
||
export function pushRow(clock: Clock, push: GithubPush, options?: PushRowOptions) { | ||
const { showDescriptionCell, showRepoCell } = { | ||
showDescriptionCell: false, | ||
showRepoCell: false, | ||
...options | ||
} | ||
|
||
const { dateTime }: { dateTime: string } = push | ||
return tr( | ||
{ class: 'info' }, | ||
showDescriptionCell ? pushDescriptionCell : undefined, | ||
showRepoCell ? repoCellForPush(push) : undefined, | ||
branchCell(push), | ||
td(displayDateTime(clock, dateTime)), | ||
userCell(push.actor), | ||
commitCellForPush(push) | ||
) | ||
} | ||
|
||
const pushDescriptionCell = td('Push') | ||
|
||
export function repoCellForPush(push: GithubPush) { | ||
return repoCell({ ...push, repoHtmlUrl: githubRepoUrl(push) }) | ||
} | ||
|
||
function branchCell(push: GithubRepositoryElement & Pick<GithubPush, 'ref'>) { | ||
return withOptions( | ||
inlineChildren, | ||
td( | ||
push.ref.split('/')[2], | ||
` `, | ||
githubAnchor(`${githubRepoUrl(push)}/tree/${push.ref.split('/')[2]}`) | ||
) | ||
) | ||
} | ||
|
||
function commitCellForPush(push: GithubPush) { | ||
// Use the message of the **last** commit | ||
const commit = latestCommitInPush(push) | ||
return commitCell({ | ||
...push, | ||
message: commit.message, | ||
sha: commit.sha | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { GithubRepositoryElement } from '../../domain/types/GithubRepositoryElement' | ||
import { inlineChildren, withOptions } from '../hiccough/hiccoughElement' | ||
import { a, td } from '../hiccough/hiccoughElements' | ||
import { githubAnchor } from './genericComponents' | ||
|
||
export function repoCell({ | ||
ownerId, | ||
repoId, | ||
repoName, | ||
repoHtmlUrl | ||
}: GithubRepositoryElement & { | ||
repoHtmlUrl: string | ||
}) { | ||
return withOptions( | ||
inlineChildren, | ||
td(a(`/app/account/${ownerId}/repo/${repoId}`, repoName), ' ', githubAnchor(repoHtmlUrl)) | ||
) | ||
} | ||
|
||
export function githubRepoUrl({ | ||
ownerName, | ||
repoName | ||
}: Pick<GithubRepositoryElement, 'ownerName' | 'repoName'>) { | ||
return `https://github.com/${ownerName}/${repoName}` | ||
} | ||
|
||
export function commitCell( | ||
event: GithubRepositoryElement & { | ||
message: string | ||
repoHtmlUrl?: string | ||
sha: string | ||
} | ||
) { | ||
const { repoHtmlUrl, message, sha } = event | ||
return withOptions( | ||
inlineChildren, | ||
td( | ||
message.length < 40 ? message : `${message.substring(0, 40)}...`, | ||
' ', | ||
githubAnchor(`${repoHtmlUrl ?? githubRepoUrl(event)}/commit/${sha}`) | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
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, ` `, githubAnchor(`https://github.com/${actor.login}`)) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
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' | ||
import { commitCell, githubRepoUrl, repoCell } from './repoElementComponents' | ||
import { runWasSuccessful } from '../../domain/github/githubWorkflowRunEvent' | ||
import { userCell } from './userComponents' | ||
|
||
export type WorkflowRowOptions = { | ||
showDescriptionCell?: boolean | ||
showRepoCell?: boolean | ||
showWorkflowCell?: boolean | ||
} | ||
|
||
export function workflowRow( | ||
clock: Clock, | ||
workflowRunEvent: GithubWorkflowRunEvent, | ||
options?: WorkflowRowOptions | ||
) { | ||
const { showDescriptionCell, showRepoCell, showWorkflowCell } = { | ||
showDescriptionCell: false, | ||
showRepoCell: false, | ||
showWorkflowCell: false, | ||
...options | ||
} | ||
|
||
return tr( | ||
{ class: workflowRunClass(workflowRunEvent) }, | ||
showDescriptionCell ? descriptionCell(workflowRunEvent) : undefined, | ||
showRepoCell ? repoCell(workflowRunEvent) : undefined, | ||
showWorkflowCell ? workflowCell(workflowRunEvent) : undefined, | ||
showDescriptionCell ? undefined : workflowResultCell(workflowRunEvent), | ||
workflowRunCell(clock, workflowRunEvent), | ||
userCell(workflowRunEvent.actor), | ||
commitCellForWorkflowRunEvent(workflowRunEvent) | ||
) | ||
} | ||
|
||
export function workflowRunClass(event: GithubWorkflowRunEvent) { | ||
// TOEventually - handle in progress | ||
return runWasSuccessful(event) ? 'success' : 'danger' | ||
} | ||
|
||
export function descriptionCell(event: GithubWorkflowRunEvent) { | ||
return runWasSuccessful(event) ? successfulRunDescriptionCell : failedRunDescriptionCell | ||
} | ||
|
||
const successfulRunDescriptionCell = td('Successful Run') | ||
const failedRunDescriptionCell = td('Failed Run') | ||
|
||
export function workflowCell( | ||
event: GithubRepositoryElement & | ||
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 | ||
), | ||
' ', | ||
githubAnchor(event.workflowHtmlUrl ?? `${githubRepoUrl(event)}/actions/${workflowPath}`) | ||
) | ||
) | ||
} | ||
|
||
export function workflowResultCell(event: GithubWorkflowRunEvent) { | ||
// TOEventually - handle in progress | ||
return runWasSuccessful(event) ? successfulRunResultCell : failedRunResultCell | ||
} | ||
|
||
const successfulRunResultCell = td('Success') | ||
const failedRunResultCell = td('Failed') | ||
|
||
export function workflowRunCell(clock: Clock, event: GithubWorkflowRunEvent) { | ||
return withOptions( | ||
inlineChildren, | ||
td(displayDateTime(clock, event.updatedAt), ' ', githubAnchor(event.htmlUrl)) | ||
) | ||
} | ||
|
||
export function commitCellForWorkflowRunEvent(event: GithubWorkflowRunEvent) { | ||
return commitCell({ | ||
...event, | ||
sha: event.headSha, | ||
message: event.displayTitle | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.