gm1003

webhook moment

Oct 14th, 2021
656
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const github = require("@actions/github");
  2. const core = require("@actions/core");
  3. const webhook = require("webhook-discord");
  4.  
  5. async function run() {
  6.   const webhookUrl = core.getInput("webhookUrl").replace("/github", "");
  7.   const hook = new webhook.Webhook(webhookUrl);
  8.  
  9.   const context = github.context;
  10.   const payload = context.payload;
  11.  
  12.   let text = "";
  13.  
  14.   for (const commit of payload.commits) {
  15.     text += `[\`${commit.id.substring(0, 7)}\`](${commit.url}) ${
  16.       commit.message.includes("!private")
  17.         ? "\`This commit has been marked as private!\`"
  18.         : commit.message
  19.     }\n`;
  20.   }
  21.  
  22.   const sender = payload.sender.login;
  23.   const repo = payload.repository.name;
  24.   const branch = context.ref.replace("refs/heads/", "");
  25.   const senderUrl = `<${payload.sender.html_url}>`;
  26.   const repoUrl = `<${payload.repository.html_url}>`;
  27.   const branchUrl = `<${repoUrl}/tree/${branch}>`;
  28.  
  29.   text += `- [${sender}](${senderUrl}) on [${repo}](${repoUrl})/[${branch}](${branchUrl})`;
  30.  
  31.   const msg = new webhook.MessageBuilder()
  32.     .setName(payload.sender.login)
  33.     .setAvatar(payload.sender.avatar_url)
  34.     .setText(text);
  35.  
  36.   hook.send(msg);
  37. }
  38.  
  39. run();
RAW Paste Data