Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions WordpressSync/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ const {
GitHubCredentials,
SourceEndpointConfigData
} = require("@cagov/wordpress-to-github/common");
const {
slackBotReportError,
slackBotChatPost,
slackBotReplyPost
} = require("../common/slackBot");
const SlackBot = require("@cagov/slack-connector");
const debugChannel = "C01DBP67MSQ"; // #testingbot
//const debugChannel = 'C01H6RB99E2'; //Carter debug
const endPointsJson = require("./endpoints.json");
Expand All @@ -25,6 +21,20 @@ const gitHubCredentials = {
token: `${process.env["GITHUB_TOKEN"]}`
};

const slackBotGetToken = () => {
const token = process.env["SLACKBOT_TOKEN"];

if (!token) {
//developers that don't set the creds can still use the rest of the code
console.error(
`You need local.settings.json to contain "SLACKBOT_TOKEN" to use slackbot features.`
);
return;
}

return token;
};

/**
*
* @param {{executionContext:{functionName:string}}} context
Expand All @@ -51,13 +61,8 @@ module.exports = async function (context, myTimer, activeEndpoints) {
try {
await doProcessEndpoints(work);
} catch (e) {
await slackBotReportError(
debugChannel,
`Error running ${appName}`,
e,
context,
myTimer
);
const slackBot = new SlackBot(slackBotGetToken(), debugChannel);
await slackBot.Error(e, myTimer);
}
};

Expand All @@ -84,7 +89,7 @@ const doProcessEndpoints = async work => {
gitHubCommitter
);

if (endpoint.ReportingChannel_Slack) {
if (endpoint.ReportingChannel_Slack && slackBotGetToken()) {
//Endpoint reporting channel enabled. Add a post for each commit report.
if (commitReports?.length) {
/** @type {string[]} */
Expand All @@ -97,25 +102,22 @@ const doProcessEndpoints = async work => {
);
});

const slackBot = new SlackBot(
slackBotGetToken(),
endpoint.ReportingChannel_Slack,
{ username: endpoint.name }
);

const allfileNames = [...new Set(mergeFileNames)];

const slackPostTS = (
await (
await slackBotChatPost(
endpoint.ReportingChannel_Slack,
`${endpoint.name} - _${allfileNames.join(", ")}_`
)
).json()
).ts;
await slackBot.Chat(`_${allfileNames.join(", ")}_`);

for (const commitReport of commitReports) {
const fileData = commitReport.Files.map(
x => `• ${x.status} - _${x.filename.split("/").slice(-1)[0]}_`
).join("\n");

await slackBotReplyPost(
endpoint.ReportingChannel_Slack,
slackPostTS,
await slackBot.Reply(
`<${commitReport.Commit.html_url}|${commitReport.Commit.message}>\n${fileData}`
);
}
Expand Down
197 changes: 0 additions & 197 deletions common/slackBot/index.js

This file was deleted.

33 changes: 21 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@cagov/slack-connector": "^0.0.1",
"@cagov/wordpress-to-github": "file:wordpress-to-github"
},
"devDependencies": {
Expand Down