social()
Post the release on Twitter (X), Slack and Microsoft Teams from code, and read the result of each platform.
Signature
ts
function social(options?: Partial<SocialOptions>): Promise<SocialResult>Options: SocialOptions: bumpResult, from, to, dryRun, ai (force the AI on or off), slackFormat (summary or full), safetyCheck, suffix, force, groups, and the shared options config, configName and logLevel. Result: SocialResult, with one SocialNetworkResult per enabled platform.
Behavior
- Posts once per enabled platform (
social.<platform>.enabled), what the release ships: with abumpResult(aBumpResultTruthy, asbump()returns it), its versions; without, the versions of thepackage.jsonfiles and the commits since the previous tags (fromandtoset the range). See Social Media for the posts. resultsis empty when no platform is enabled or nothing is to announce. A post that fails gives{ platform, success: false, error }andhasErrors: true.social()does not reject: an error (the safety check, a missing config...) is returned as a result of theunknownplatform withhasErrors: true. Only a refused or cancelled prompt rejects, with aRelizyCancelError.results[].urlis the link of the tweet.- With
dryRun, nothing is posted and the AI is not called: the CLI flag--ai-previewhas no equivalent in the API. - The hooks get the release as third parameter (
HookContext) only with abumpResult. See Social Media.
Example
ts
import { social } from 'relizy'
// The current release, as `relizy social` posts it
const { results, hasErrors } = await social({ dryRun: process.env.CI !== 'true' })
for (const result of results) {
console.log(result.platform, result.success ? (result.url ?? 'posted') : result.error)
}
if (hasErrors) {
process.exitCode = 1
}