Skip to content

Commit

Permalink
Added dedicated files for header and sections
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Scholz committed Sep 19, 2023
1 parent 8f9b19e commit eea0f18
Show file tree
Hide file tree
Showing 7 changed files with 321 additions and 117 deletions.
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ inputs:
imageAltText:
description: 'Optional imageAltText. Alternative in case the image cannot be shown.'
required: false
createSection:
description: 'Optional createSection. Specify whether the section should be shown or not.'
required: false
default: 'true'
collapsibleSection:
description: 'Optional collapsibleSection. Specify whether the section is collapsible.'
required: false
default: 'true'
uncollapsibleWidgetsCount:
description: 'Optional uncollapsibleWidgetsCount. Specify the amount of uncollapsible widgets within the sections.'
required: false
default: '1'

runs:
using: node20
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
190 changes: 159 additions & 31 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions src/cardHeader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import * as core from '@actions/core'
import * as github from '@actions/github'

export function createCardV2Header(): Record<string, string> {
const cardHeader: Record<string, string> = {}

const headerTitle = getHeaderTitle()
const headerSubtitle = getHeaderSubTitle()
const headerImageUrl = getHeaderImageUrl()

cardHeader.title = headerTitle
if (headerSubtitle) {
cardHeader.subtitle = headerSubtitle
}
if (headerImageUrl) {
cardHeader.imageUrl = headerImageUrl
cardHeader.imageType = getHeaderImageType()
const headerImageAltText = getHeaderImageAltText()
if (headerImageAltText) {
cardHeader.imageAltText = headerImageAltText
}
}

return cardHeader
}

function getHeaderTitle(): string {
const inputTitle = core.getInput('title')
const jobStatus = core.getInput('jobStatus')
if (inputTitle.length !== 0) {
return `${inputTitle} ${jobStatus}`
}

return `${github.context.action} ${jobStatus}`
}

function getHeaderSubTitle(): string | undefined {
const inputSubTitle = core.getInput('subtitle')
if (inputSubTitle.length !== 0) {
return inputSubTitle
}
return undefined
}

function getHeaderImageUrl(): string | undefined {
const inputImageUrl = core.getInput('imageUrl')
if (inputImageUrl.length !== 0) {
return inputImageUrl
}
return undefined
}

function getHeaderImageType(): string {
const inputImageType = core.getInput('imageType')
if (inputImageType.length !== 0) {
return inputImageType
}
return 'CIRCLE'
}

function getHeaderImageAltText(): string | undefined {
const inputImageAltText = core.getInput('imageAltText')
if (inputImageAltText.length !== 0) {
return inputImageAltText
}
return undefined
}
71 changes: 71 additions & 0 deletions src/cardSection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import * as core from '@actions/core'
import * as github from '@actions/github'

export function createCardV2Section(): object[] {
const repoPath = `${github.context.repo.owner}/${github.context.repo.repo}`
const collapsibleSection = core.getBooleanInput('collapsibleSection')
const uncollapsibleWidgetsCount = getNumberResultAndValidate(
'uncollapsibleWidgetsCount'
)
return [
{
header: 'Contact Info',
collapsible: collapsibleSection,
uncollapsibleWidgetsCount,
widgets: [
{
decoratedText: {
startIcon: {
knownIcon: 'STAR'
},
text: repoPath
}
},
{
buttonList: {
buttons: [
{
text: 'Go to repo',
onClick: {
openLink: {
url: `https://github.com/${repoPath}`
}
}
},
{
text: 'Go to action run',
onClick: {
openLink: {
url: `https://github.com/${repoPath}/actions/runs/${github.context.runNumber}/job/${github.context.runId}`
}
}
}
]
}
}
]
}
]
}

function getNumberResultAndValidate(propertyName?: string): number | undefined {
if (!propertyName) {
return undefined
}

const value = core.getInput(propertyName)
const number = Number(value)
if (isNaN(number)) {
throw new Error(`${propertyName} needs to be a number`)
}

return getNumberOrUndefined(value)
}

function getNumberOrUndefined(value: string): number | undefined {
if (!value || value === '') return undefined

const result = Number(value)
if (isNaN(result)) return undefined
return result
}
Loading

0 comments on commit eea0f18

Please sign in to comment.