Skip to content

Allow only block messages #258

@fGrennon

Description

@fGrennon

I'm trying to send a message using only blocks, but the action don't accept this. Have an default to fields, text, title, footer and authors.

The message structure don't allow the blocks inside the message, always the blocks push at the end of the message.

slack/src/slack.ts

Lines 229 to 269 in c97e3fd

const pretextTemplate = Handlebars.compile(opts?.pretext || '')
const titleTemplate = Handlebars.compile(opts?.title || '')
const defaultText = `${
'*<{{{workflowUrl}}}|Workflow _{{workflow}}_ ' +
'job _{{jobName}}_ triggered by _{{eventName}}_ is _{{jobStatus}}_>* ' +
'for <{{refUrl}}|`{{ref}}`>\n'
}${description ? '<{{diffUrl}}|`{{diffRef}}`> - {{{description}}}' : ''}`
const textTemplate = Handlebars.compile(message || opts?.text || defaultText)
const defaultFallback = `[GitHub]: [{{repositoryName}}] {{workflow}} {{eventName}} ${
action ? '{{action}} ' : ''
}{{jobStatus}}`
const fallbackTemplate = Handlebars.compile(opts?.fallback || defaultFallback)
const defaultFields = Object.entries(jobSteps).length
? [
{
title: 'Job Steps',
value: '{{#each jobSteps}}{{icon this.outcome}} {{@key}}\n{{~/each}}',
short: false,
if: 'always()'
}
]
: []
const filteredFields: object[] = []
for (const field of opts?.fields || defaultFields) {
const field_if = field?.if || 'always()'
if (field_if === 'always()' || field_if.startsWith(jobStatus.toLowerCase())) {
filteredFields.push({
title: field.title,
value: field.value,
short: JSON.parse(field.short.toString())
})
}
}
const fieldsTemplate = Handlebars.compile(JSON.stringify(filteredFields))
const defaultFooter = '<{{repositoryUrl}}|{{repositoryName}}> #{{runNumber}}'
const footerTemplate = Handlebars.compile(opts?.footer || defaultFooter)

slack/src/slack.ts

Lines 334 to 359 in c97e3fd

const attachments: MessageAttachment[] = [
{
mrkdwn_in: ['pretext' as const, 'text' as const, 'fields' as const],
color: jobColor(jobStatus, opts?.colors),
pretext,
author_name: sender?.login,
author_link: sender?.html_url,
author_icon: sender?.avatar_url,
title,
title_link: opts?.title_link,
text,
fields,
fallback,
footer,
footer_icon: DEFAULT_FOOTER_ICON,
ts: ts.toString()
}
]
if (opts?.blocks) {
attachments.push({
color: jobColor(jobStatus, opts?.colors),
fallback,
blocks
})
}

The feature i propose is omit the default values and only build the message with blocks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions