-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added dedicated files for header and sections
- Loading branch information
Simon Scholz
committed
Sep 19, 2023
1 parent
8f9b19e
commit eea0f18
Showing
7 changed files
with
321 additions
and
117 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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 | ||
} |
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,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 | ||
} |
Oops, something went wrong.