Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow only block messages #258

Open
fGrennon opened this issue Feb 3, 2023 · 2 comments
Open

Allow only block messages #258

fGrennon opened this issue Feb 3, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@fGrennon
Copy link

fGrennon commented Feb 3, 2023

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.

@satterly
Copy link
Contributor

If you create a PR for this proposal I'll review it. Thanks.

@satterly satterly added the enhancement New feature or request label Feb 27, 2023
@GroovinChip
Copy link

@satterly doesn't look like the author is following up on this, would the team consider implementing it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants