codyfight-webhook

1.0.10 • Public • Published

codyfight-webhook

Codyfight webhook utility for sending deployment notifications to Discord or any other webhook service.

Installation

yarn add codyfight-webhook

or

npm install codyfight-webhook

Usage - Discord Webhook

discordWebhook.js

This file contains utility functions for sending Discord webhook messages.

Functions

  • sendDiscordMessage(webhookUrl: string, messageType: string, pipelineUrl: string): Promise<void>

    • Sends a Discord webhook message with the specified webhook URL and message type.
    • Parameters:
      • webhookUrl: The URL of the Discord webhook.
      • messageType: The type of message to send (success or failure).
      • pipelineUrl: The URL of the pipeline.
    • Returns: Promise<void>

discord.js

This file is the main interface for sending Discord webhook messages using the discordWebhook.js utility functions.

It Provides a command-line interface for sending Discord webhook messages.

Command-line Usage

node discord.js -u <webhookUrl> -p <pipelineUrl> -t <messageType>

Options

  • -u, --url <webhookUrl>: Specifies the URL of the Discord webhook. (Required)
  • -p, --pipeline <pipelineUrl>: Specifies the URL of the pipeline. (Required)
  • -t, --type <messageType>: Specifies the type of message to send (success or failure). Default is success. (Optional)

Examples

  1. Send a success message to a Discord webhook:

    node discord.js -u <webhookUrl> -p <pipelineUrl>
  2. Send a failure message to a Discord webhook:

    node discord.js -u <webhookUrl> -p <pipelineUrl> -t failure

AWS CodeBuild Integration

Important: If you are using AWS CodeBuild, you can use the following node.js script to wrap the discord.js script and send Discord webhook notifications after each CodeBuild run.

send_discord_notification.js

const { runDiscordNotification } = require("codyfight-webhook");
runDiscordNotification();

Make sure the environment variables BRANCH_NAME, WEBHOOK_DISCORD_URL and WEBHOOK_PIPELINE_URL are set in your CodeBuild project.

buildspec.yml

To integrate the Discord webhook notification into your AWS CodeBuild pipeline, add the following commands to the post_build phase of your buildspec.yml file:

version: 0.2

env:
  variables:
    BRANCH_NAME: '#{SourceVariables.BranchName}'

  parameter-store:
    WEBHOOK_DISCORD_URL: '/CodeBuild/codyfight-web-prod/WEBHOOK_DISCORD_URL'
    WEBHOOK_PIPELINE_URL: '/CodeBuild/codyfight-web-prod/WEBHOOK_PIPELINE_URL'
    # ... other environment variables

phases:
  # ... other phases

  post_build:
    on-failure: ABORT
    commands:
      - node send_discord_notification.js

Make sure to replace send_discord_notification.js with the filename of your script.

With these instructions, your Discord webhook notification will be sent after each CodeBuild run, indicating whether the build was successful or failed.

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i codyfight-webhook

    Weekly Downloads

    64

    Version

    1.0.10

    License

    ISC

    Unpacked Size

    8.98 kB

    Total Files

    7

    Last publish

    Collaborators

    • driule
    • tomas.balsys
    • vinimartdev