+
Skip to content

prettier update #112

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

Merged
merged 4 commits into from
Dec 1, 2021
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
26 changes: 20 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"$schema": "https://json.schemastore.org/eslintrc",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "script",
"ecmaFeatures": {
"jsx": true,
"modules": false,
"experimentalObjectRestSpread": true
}
},
"env": {
"browser": false,
"commonjs": true,
Expand All @@ -11,10 +20,10 @@
"plugin:jsdoc/recommended",
"plugin:prettier/recommended"
],
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"prettier",
"jsdoc"
],
"rules": {
"arrow-parens": [
"warn",
Expand All @@ -27,7 +36,10 @@
2
],
"no-extra-bind": "warn",
"no-extra-parens": "warn",
"no-extra-parens": [
"warn",
"functions"
],
"no-lonely-if": "warn",
"no-multiple-empty-lines": "warn",
"no-shadow": "warn",
Expand All @@ -48,6 +60,8 @@
"jsdoc/require-returns-type": "off",
"jsdoc/require-property-description": "off",
"jsdoc/require-param-description": "off",
"jsdoc/require-returns-description": "off"
"jsdoc/require-returns-description": "off",
"prettier/prettier": "error",
"arrow-body-style": "off"
}
}
10 changes: 3 additions & 7 deletions WordpressSync/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ const repeatCount = parseInt(process.argv.slice(2));
const indexCode = require("./index");
(async () => {
for (let step = 0; step < repeatCount; step++) {
console.log(`****** Iteration ${step+1} ******`)
await indexCode(
{ executionContext: { functionName: "debug" } },
null,
[]
);
}
console.log(`****** Iteration ${step + 1} ******`);
await indexCode({ executionContext: { functionName: "debug" } }, null, []);
}
})();
5 changes: 2 additions & 3 deletions WordpressSync/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ module.exports = async function (context, myTimer, activeEndpoints) {
x => !activeEndpoints?.length || activeEndpoints.includes(x.name)
);

const appName = context.executionContext.functionName;
const debugMode = process.env.debug?.toLowerCase() === "true";

const work = endpointsFiltered.filter(
Expand Down Expand Up @@ -98,8 +97,8 @@ const doProcessEndpoints = async work => {
mergeFileNames.push(
...x.Files.map(
//Remove file extension, and remove resolution postfix
x =>
x.filename
f =>
f.filename
.split("/")
.slice(-1)[0]
.split(".")[0]
Expand Down
208 changes: 104 additions & 104 deletions WordpressSyncHttpTrigger/index.js
Original file line number Diff line number Diff line change
@@ -1,104 +1,104 @@
// @ts-check
const { sleep } = require("@cagov/wordpress-to-github/gitTreeCommon");
const SlackBot = require("@cagov/slack-connector");
const endpoints = require("../WordpressSync/endpoints.json");
const debugChannel = "C02G6PETB9B"; //#wordpress-sync-http-trigger
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;
};
/**
* @typedef {object} Response
* @property {number} [status]
* @property {*} [body]
* @property {{"Content-Type":string}} [headers]
*/
/**
* @param {{executionContext:{functionName:string},res:Response}} context
* @param {{method:string,headers:{"user-agent":string},query?:{code?:string},params:{},body:{slug?:string,trigger?:string}}} req
*/
module.exports = async function (context, req) {
if (req.method !== "POST") {
context.res = {
body: `Service is running, but is expecting a POST.`
};
return;
}
const slack = new SlackBot(slackBotGetToken(), debugChannel);
try {
const TriggerName = req.body?.trigger || "(Trigger)";
const SlugName = req.body?.slug || "(slug)";
await slack.Chat(`Notification received - ${SlugName} - ${TriggerName}`);
//clean out "code" value display
const redactedOutput = JSON.stringify(req, null, 2).replace(
new RegExp(req.query.code, "g"),
`${req.query?.code?.substring(0, 3)}[...]`
);
await slack.Reply(`\n\n*Full Details*\n\`\`\`${redactedOutput}\`\`\``);
//Find endpoints that match the requestor
const postAgent = req.headers["user-agent"];
const activeEndpoints = endpoints.data.projects.filter(
x =>
x.enabled &&
x.WordPressSource?.url &&
postAgent.includes(x.WordPressSource.url)
);
//if you find matches...congrats...report for now
if (activeEndpoints.length) {
await slack.Reply(
`${
activeEndpoints.length
} matching endpoint(s) found ...${activeEndpoints
.map(x => x.name)
.join(", ")}`
);
await sleep(10 * 1000); // let's wait 10 seconds before processing to try to avoid sync issues with the WP database
//run the indexpage async
const indexCode = require("../WordpressSync");
await indexCode(
{
executionContext: {
functionName: "WordpressSyncHttpTrigger"
}
},
null,
activeEndpoints.map(x => x.name)
);
await slack.Reply(`Done.`);
} else {
await slack.Reply(`No endpoints found for...${postAgent}`);
await slack.ReactionAdd("no_entry");
}
context.res = {
status: 204 //OK - No content
};
} catch (e) {
await slack.Error(e, req);
context.res = {
status: 500,
body: `Error - ${e.message}`
};
}
};
// @ts-check
const { sleep } = require("@cagov/wordpress-to-github/gitTreeCommon");
const SlackBot = require("@cagov/slack-connector");
const endpoints = require("../WordpressSync/endpoints.json");

const debugChannel = "C02G6PETB9B"; //#wordpress-sync-http-trigger

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;
};

/**
* @typedef {object} Response
* @property {number} [status]
* @property {*} [body]
* @property {{"Content-Type":string}} [headers]
*/

/**
* @param {{executionContext:{functionName:string},res:Response}} context
* @param {{method:string,headers:{"user-agent":string},query?:{code?:string},params:{},body:{slug?:string,trigger?:string}}} req
*/
module.exports = async function (context, req) {
if (req.method !== "POST") {
context.res = {
body: `Service is running, but is expecting a POST.`
};
return;
}
const slack = new SlackBot(slackBotGetToken(), debugChannel);

try {
const TriggerName = req.body?.trigger || "(Trigger)";
const SlugName = req.body?.slug || "(slug)";
await slack.Chat(`Notification received - ${SlugName} - ${TriggerName}`);

//clean out "code" value display
const redactedOutput = JSON.stringify(req, null, 2).replace(
new RegExp(req.query.code, "g"),
`${req.query?.code?.substring(0, 3)}[...]`
);

await slack.Reply(`\n\n*Full Details*\n\`\`\`${redactedOutput}\`\`\``);

//Find endpoints that match the requestor
const postAgent = req.headers["user-agent"];
const activeEndpoints = endpoints.data.projects.filter(
x =>
x.enabled &&
x.WordPressSource?.url &&
postAgent.includes(x.WordPressSource.url)
);

//if you find matches...congrats...report for now
if (activeEndpoints.length) {
await slack.Reply(
`${
activeEndpoints.length
} matching endpoint(s) found ...${activeEndpoints
.map(x => x.name)
.join(", ")}`
);

await sleep(10 * 1000); // let's wait 10 seconds before processing to try to avoid sync issues with the WP database

//run the indexpage async
const indexCode = require("../WordpressSync");
await indexCode(
{
executionContext: {
functionName: "WordpressSyncHttpTrigger"
}
},
null,
activeEndpoints.map(x => x.name)
);
await slack.Reply(`Done.`);
} else {
await slack.Reply(`No endpoints found for...${postAgent}`);
await slack.ReactionAdd("no_entry");
}

context.res = {
status: 204 //OK - No content
};
} catch (e) {
await slack.Error(e, req);

context.res = {
status: 500,
body: `Error - ${e.message}`
};
}
};
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载