From 111c284aea9c316d358458400771ab08603e7032 Mon Sep 17 00:00:00 2001 From: rafawelsh Date: Mon, 30 Aug 2021 13:56:30 -0700 Subject: [PATCH 01/15] refactor: adding lastest challenge to correct space --- javascript/add_challenge_to_spaces.js | 23 +++-- javascript/js_actions.js | 141 +++++++++++++++++++------- 2 files changed, 116 insertions(+), 48 deletions(-) diff --git a/javascript/add_challenge_to_spaces.js b/javascript/add_challenge_to_spaces.js index 0900458..0446c17 100644 --- a/javascript/add_challenge_to_spaces.js +++ b/javascript/add_challenge_to_spaces.js @@ -6,17 +6,22 @@ const YAML = require("js-yaml"); const { postQuestion } = require("./js_actions.js"); try { - const raw = fs.readFileSync("./topics.yaml"); + const raw = fs.readFileSync("../topics.yaml"); const data = YAML.load(raw); - Object.values(data).forEach((item) => { - if (!item.posted) { - postQuestion(item); - item.posted = true; - } - }); - let newData = YAML.dump(data); - fs.writeFileSync("./topics.yaml", newData, "utf8"); + const lengthOfYAMLfile = Object.values(data).length; + const latestQuestion = data[lengthOfYAMLfile]; + postQuestion(latestQuestion, lengthOfYAMLfile); + + // Object.values(data).forEach((item) => { + // if (!item.posted) { + // postQuestion(item); + // item.posted = true; + // } + // }); + + // let newData = YAML.dump(data); + // fs.writeFileSync("./topics.yaml", newData, "utf8"); } catch (err) { console.log(err); } diff --git a/javascript/js_actions.js b/javascript/js_actions.js index 4a14f68..9526f44 100644 --- a/javascript/js_actions.js +++ b/javascript/js_actions.js @@ -1,49 +1,112 @@ const fetch = require("node-fetch"); -const API_TOKEN = process.env.API_TOKEN; -const COMMUNITY_ID = process.env.COMMUNITY_ID; -const CIRCLE_COMMUNITY_PATH = process.env.CIRCLE_COMMUNITY_PATH; -const BEGGINER_SPACE_ID = process.env.BEGGINER_SPACE_ID; -const MEDIUM_SPACE_ID = process.env.MEDIUM_SPACE_ID; -const ADVANCED_SPACE_ID = process.env.ADVANCED_SPACE_ID; +const postQuestion = async (question, questionNumber) => { + const { title, difficulty, source, body, author_name } = question; -const postQuestion = async (question) => { + console.log(body); + console.log(title); + // author_email.join(""); + console.log(difficulty); -const { title, difficulty, body, author_email } = question; + const requestOptions = { + method: "POST", + headers: { Authorization: `eefCFAfzz3yAZZUfBdw2Ba2M` }, + }; -console.log(difficulty); -const requestOptions = { - method: "POST", - headers: { Authorization: API_TOKEN }, -}; + const questionDifficulties = { + Beginner: 140192, + Medium: 140193, + }; -const questionDifficulties = { - Beginner: BEGGINER_SPACE_ID, - Medium: MEDIUM_SPACE_ID, - Advanced: ADVANCED_SPACE_ID, -}; + let space_id = questionDifficulties[difficulty]; + + let community_id = 11548; + + //post sections + let urlTitle = `Interview Prep Challenge #${questionNumber}: ${title}&`; + let urlBody = ` + πŸ‘πŸ‘ Thanks to ${author_name} for the question!πŸ‘πŸ‘
+ Difficulty Level: ${difficulty}
+ Sourced from: ${source}
+ ${body} + &`; + + const url = formatPostBody(urlTitle, urlBody); + //url creation + function formatPostBody(title, body) { + const post_url = `https://app.circle.so/api/v1/posts?community_id=${community_id}&space_id=${space_id}&`; + const post_title = `name=${title}&`; + const post_body = `internal_custom_html=${body}&`; + const post_url_ending_params = `is_comments_enabled=true&is_liking_enabled=true&is_truncation_disabled=false`; -const SPACE_ID = questionDifficulties[difficulty]; - -// url creation -const post_url = `${CIRCLE_COMMUNITY_PATH}/api/v1/posts?community_id=${COMMUNITY_ID}&SPACE_ID=${SPACE_ID}&`; -const post_title = `name=${title}&`; -const post_body = `body=${body}&`; -const post_url_ending_params = `is_comments_enabled=true&is_liking_enabled=true&is_truncation_disabled=true`; -const post_author = `&user_email=${author_email}`; - -const url_pieces = [post_url, post_title, post_body, post_url_ending_params]; -if (author_email) { - url_pieces.append(post_author); -} -const url = encodeURI(url_pieces.join("")); - -await fetch(url, requestOptions) - .then((response) => response.json()) - .then((result) => { - console.log(result); - }) - .catch((error) => console.log("error", error)); + const url_pieces = [ + post_url, + post_title, + post_body, + post_url_ending_params, + ]; + + console.log(post_title); + console.log(post_body); + return encodeURI(url_pieces.join("")); + } + console.log({ url }); + + await fetch(url, requestOptions) + .then((response) => response.json()) + .then((result) => { + console.log(result.success); + // console.log({ result }); + }) + .catch((error) => console.log("error", error)); }; module.exports = { postQuestion }; + +// const API_TOKEN = process.env.API_TOKEN; +// const COMMUNITY_ID = process.env.COMMUNITY_ID; +// const CIRCLE_COMMUNITY_PATH = process.env.CIRCLE_COMMUNITY_PATH; +// const BEGGINER_SPACE_ID = process.env.BEGGINER_SPACE_ID; +// const MEDIUM_SPACE_ID = process.env.MEDIUM_SPACE_ID; +// const ADVANCED_SPACE_ID = process.env.ADVANCED_SPACE_ID; + +// const postQuestion = async (question) => { + +// const { title, difficulty, body, author_email } = question; + +// console.log(difficulty); +// const requestOptions = { +// method: "POST", +// headers: { Authorization: API_TOKEN }, +// }; + +// const questionDifficulties = { +// Beginner: BEGGINER_SPACE_ID, +// Medium: MEDIUM_SPACE_ID, +// Advanced: ADVANCED_SPACE_ID, +// }; + +// const SPACE_ID = questionDifficulties[difficulty]; + +// // url creation +// const post_url = `${CIRCLE_COMMUNITY_PATH}/api/v1/posts?community_id=${COMMUNITY_ID}&SPACE_ID=${SPACE_ID}&`; +// const post_title = `name=${title}&`; +// const post_body = `body=${body}&`; +// const post_url_ending_params = `is_comments_enabled=true&is_liking_enabled=true&is_truncation_disabled=true`; +// const post_author = `&user_email=${author_email}`; + +// const url_pieces = [post_url, post_title, post_body, post_url_ending_params]; +// if (author_email) { +// url_pieces.append(post_author); +// } +// const url = encodeURI(url_pieces.join("")); + +// await fetch(url, requestOptions) +// .then((response) => response.json()) +// .then((result) => { +// console.log(result); +// }) +// .catch((error) => console.log("error", error)); +// }; + +// module.exports = { postQuestion }; From 3d2fc05090714e6b2eb14b29b1a07a019739b34c Mon Sep 17 00:00:00 2001 From: rafawelsh Date: Mon, 30 Aug 2021 20:58:59 -0700 Subject: [PATCH 02/15] refactor: adding questions to correct space with github actions --- .gitignore | 2 +- javascript/add_challenge_to_spaces.js | 11 --- javascript/js_actions.js | 111 ++++++++------------------ 3 files changed, 35 insertions(+), 89 deletions(-) diff --git a/.gitignore b/.gitignore index f6760c7..c290399 100644 --- a/.gitignore +++ b/.gitignore @@ -129,4 +129,4 @@ dmypy.json .pyre/ # Node -/node_modules \ No newline at end of file +/node_modules diff --git a/javascript/add_challenge_to_spaces.js b/javascript/add_challenge_to_spaces.js index 0446c17..f35630b 100644 --- a/javascript/add_challenge_to_spaces.js +++ b/javascript/add_challenge_to_spaces.js @@ -8,20 +8,9 @@ const { postQuestion } = require("./js_actions.js"); try { const raw = fs.readFileSync("../topics.yaml"); const data = YAML.load(raw); - const lengthOfYAMLfile = Object.values(data).length; const latestQuestion = data[lengthOfYAMLfile]; postQuestion(latestQuestion, lengthOfYAMLfile); - - // Object.values(data).forEach((item) => { - // if (!item.posted) { - // postQuestion(item); - // item.posted = true; - // } - // }); - - // let newData = YAML.dump(data); - // fs.writeFileSync("./topics.yaml", newData, "utf8"); } catch (err) { console.log(err); } diff --git a/javascript/js_actions.js b/javascript/js_actions.js index 9526f44..53dc45b 100644 --- a/javascript/js_actions.js +++ b/javascript/js_actions.js @@ -1,42 +1,51 @@ const fetch = require("node-fetch"); +const API_TOKEN = process.env.API_TOKEN; +const COMMUNITY_ID = process.env.COMMUNITY_ID; +const CIRCLE_COMMUNITY_PATH = process.env.CIRCLE_COMMUNITY_PATH; +const BEGGINER_SPACE_ID = process.env.BEGGINER_SPACE_ID; +const MEDIUM_SPACE_ID = process.env.MEDIUM_SPACE_ID; +const ADVANCED_SPACE_ID = process.env.ADVANCED_SPACE_ID; + const postQuestion = async (question, questionNumber) => { const { title, difficulty, source, body, author_name } = question; - console.log(body); - console.log(title); - // author_email.join(""); - console.log(difficulty); - const requestOptions = { method: "POST", - headers: { Authorization: `eefCFAfzz3yAZZUfBdw2Ba2M` }, + headers: { Authorization: API_TOKEN }, }; const questionDifficulties = { - Beginner: 140192, - Medium: 140193, + Beginner: BEGGINER_SPACE_ID, + Medium: MEDIUM_SPACE_ID, + Advanced: ADVANCED_SPACE_ID, }; - let space_id = questionDifficulties[difficulty]; - - let community_id = 11548; + const SPACE_ID = questionDifficulties[difficulty]; //post sections - let urlTitle = `Interview Prep Challenge #${questionNumber}: ${title}&`; - let urlBody = ` - πŸ‘πŸ‘ Thanks to ${author_name} for the question!πŸ‘πŸ‘
- Difficulty Level: ${difficulty}
- Sourced from: ${source}
- ${body} - &`; + let titleHTML = `Interview Prep Challenge ${questionNumber}: ${title}`; + let bodyHTML = ` + πŸ‘πŸ‘

Thanks to ${author_name} for the question!πŸ‘πŸ‘


+
+ Difficulty Level: ${difficulty}
+ Sourced from: ${source}
+
+ ${body}
+
+ This question was submitted in the YearOne Open Source project, to submit a topic, go to github.com/YearOne-Prep/YearOne-prep-challenges +

+ Don't forget to let us know that you've completed this question! + Leave a comment below πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡ + `; - const url = formatPostBody(urlTitle, urlBody); //url creation - function formatPostBody(title, body) { - const post_url = `https://app.circle.so/api/v1/posts?community_id=${community_id}&space_id=${space_id}&`; - const post_title = `name=${title}&`; - const post_body = `internal_custom_html=${body}&`; + const url = encodeURI(formatPostBody(titleHTML, bodyHTML)); + + function formatPostBody(titleSection, bodySection) { + const post_url = `${CIRCLE_COMMUNITY_PATH}/api/v1/posts?community_id=${COMMUNITY_ID}&SPACE_ID=${SPACE_ID}&`; + const post_title = `name=${titleSection}&`; + const post_body = `internal_custom_html=${bodySection}&`; const post_url_ending_params = `is_comments_enabled=true&is_liking_enabled=true&is_truncation_disabled=false`; const url_pieces = [ @@ -46,67 +55,15 @@ const postQuestion = async (question, questionNumber) => { post_url_ending_params, ]; - console.log(post_title); - console.log(post_body); - return encodeURI(url_pieces.join("")); + return url_pieces.join(""); } - console.log({ url }); await fetch(url, requestOptions) .then((response) => response.json()) .then((result) => { - console.log(result.success); - // console.log({ result }); + console.log(result); }) .catch((error) => console.log("error", error)); }; module.exports = { postQuestion }; - -// const API_TOKEN = process.env.API_TOKEN; -// const COMMUNITY_ID = process.env.COMMUNITY_ID; -// const CIRCLE_COMMUNITY_PATH = process.env.CIRCLE_COMMUNITY_PATH; -// const BEGGINER_SPACE_ID = process.env.BEGGINER_SPACE_ID; -// const MEDIUM_SPACE_ID = process.env.MEDIUM_SPACE_ID; -// const ADVANCED_SPACE_ID = process.env.ADVANCED_SPACE_ID; - -// const postQuestion = async (question) => { - -// const { title, difficulty, body, author_email } = question; - -// console.log(difficulty); -// const requestOptions = { -// method: "POST", -// headers: { Authorization: API_TOKEN }, -// }; - -// const questionDifficulties = { -// Beginner: BEGGINER_SPACE_ID, -// Medium: MEDIUM_SPACE_ID, -// Advanced: ADVANCED_SPACE_ID, -// }; - -// const SPACE_ID = questionDifficulties[difficulty]; - -// // url creation -// const post_url = `${CIRCLE_COMMUNITY_PATH}/api/v1/posts?community_id=${COMMUNITY_ID}&SPACE_ID=${SPACE_ID}&`; -// const post_title = `name=${title}&`; -// const post_body = `body=${body}&`; -// const post_url_ending_params = `is_comments_enabled=true&is_liking_enabled=true&is_truncation_disabled=true`; -// const post_author = `&user_email=${author_email}`; - -// const url_pieces = [post_url, post_title, post_body, post_url_ending_params]; -// if (author_email) { -// url_pieces.append(post_author); -// } -// const url = encodeURI(url_pieces.join("")); - -// await fetch(url, requestOptions) -// .then((response) => response.json()) -// .then((result) => { -// console.log(result); -// }) -// .catch((error) => console.log("error", error)); -// }; - -// module.exports = { postQuestion }; From 76d9cfc47698a83c1382e1f0d1d8dbca2be435a0 Mon Sep 17 00:00:00 2001 From: rafawelsh Date: Tue, 31 Aug 2021 13:45:02 -0700 Subject: [PATCH 03/15] refactor: importing functions fbetween files --- javascript/add_challenge_to_spaces.js | 2 +- javascript/js_actions.js | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/javascript/add_challenge_to_spaces.js b/javascript/add_challenge_to_spaces.js index f35630b..a7e379a 100644 --- a/javascript/add_challenge_to_spaces.js +++ b/javascript/add_challenge_to_spaces.js @@ -3,7 +3,7 @@ const fs = require("fs"); const YAML = require("js-yaml"); //import actions -const { postQuestion } = require("./js_actions.js"); +import { postQuestion } from "./js_actions.js"; try { const raw = fs.readFileSync("../topics.yaml"); diff --git a/javascript/js_actions.js b/javascript/js_actions.js index 53dc45b..7a85bf8 100644 --- a/javascript/js_actions.js +++ b/javascript/js_actions.js @@ -5,7 +5,6 @@ const COMMUNITY_ID = process.env.COMMUNITY_ID; const CIRCLE_COMMUNITY_PATH = process.env.CIRCLE_COMMUNITY_PATH; const BEGGINER_SPACE_ID = process.env.BEGGINER_SPACE_ID; const MEDIUM_SPACE_ID = process.env.MEDIUM_SPACE_ID; -const ADVANCED_SPACE_ID = process.env.ADVANCED_SPACE_ID; const postQuestion = async (question, questionNumber) => { const { title, difficulty, source, body, author_name } = question; @@ -18,7 +17,6 @@ const postQuestion = async (question, questionNumber) => { const questionDifficulties = { Beginner: BEGGINER_SPACE_ID, Medium: MEDIUM_SPACE_ID, - Advanced: ADVANCED_SPACE_ID, }; const SPACE_ID = questionDifficulties[difficulty]; From 38c2a57bf623f3d74446cd9d809ece22b230642b Mon Sep 17 00:00:00 2001 From: rafawelsh Date: Tue, 31 Aug 2021 14:12:24 -0700 Subject: [PATCH 04/15] refactor: importing functions fbetween files --- javascript/add_challenge_to_spaces.js | 4 ++-- javascript/package.json | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/javascript/add_challenge_to_spaces.js b/javascript/add_challenge_to_spaces.js index a7e379a..5c8c9d4 100644 --- a/javascript/add_challenge_to_spaces.js +++ b/javascript/add_challenge_to_spaces.js @@ -1,6 +1,6 @@ //Import dependcies -const fs = require("fs"); -const YAML = require("js-yaml"); +import { fs } from "fs"; +import { YAML } from "js-yaml"; //import actions import { postQuestion } from "./js_actions.js"; diff --git a/javascript/package.json b/javascript/package.json index d6a08cb..38956df 100644 --- a/javascript/package.json +++ b/javascript/package.json @@ -2,5 +2,6 @@ "dependencies": { "js-yaml": "^4.1.0", "node-fetch": "^2.6.1" - } -} + }, + "type": "module" +} \ No newline at end of file From f3dfc360a01ff147f1f4de13a78178892fc55b16 Mon Sep 17 00:00:00 2001 From: rafawelsh Date: Tue, 31 Aug 2021 14:17:27 -0700 Subject: [PATCH 05/15] refactor: importing functions fbetween files --- javascript/js_actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/js_actions.js b/javascript/js_actions.js index 7a85bf8..c65e47a 100644 --- a/javascript/js_actions.js +++ b/javascript/js_actions.js @@ -1,4 +1,4 @@ -const fetch = require("node-fetch"); +import { fetch } from "node-fetch"; const API_TOKEN = process.env.API_TOKEN; const COMMUNITY_ID = process.env.COMMUNITY_ID; From feaecc852a4320ce228b6226938d1358ca7e4d82 Mon Sep 17 00:00:00 2001 From: rafawelsh Date: Tue, 31 Aug 2021 14:25:44 -0700 Subject: [PATCH 06/15] refactor: importing functions fbetween files --- javascript/add_challenge_to_spaces.js | 4 ++-- javascript/js_actions.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/javascript/add_challenge_to_spaces.js b/javascript/add_challenge_to_spaces.js index 5c8c9d4..a7e379a 100644 --- a/javascript/add_challenge_to_spaces.js +++ b/javascript/add_challenge_to_spaces.js @@ -1,6 +1,6 @@ //Import dependcies -import { fs } from "fs"; -import { YAML } from "js-yaml"; +const fs = require("fs"); +const YAML = require("js-yaml"); //import actions import { postQuestion } from "./js_actions.js"; diff --git a/javascript/js_actions.js b/javascript/js_actions.js index c65e47a..7a85bf8 100644 --- a/javascript/js_actions.js +++ b/javascript/js_actions.js @@ -1,4 +1,4 @@ -import { fetch } from "node-fetch"; +const fetch = require("node-fetch"); const API_TOKEN = process.env.API_TOKEN; const COMMUNITY_ID = process.env.COMMUNITY_ID; From cfabc2d0112e4cdabe5d0ec4b7660c874c6fc0ea Mon Sep 17 00:00:00 2001 From: rafawelsh Date: Tue, 31 Aug 2021 14:56:53 -0700 Subject: [PATCH 07/15] changed node-fetch package --- javascript/js_actions.js | 2 +- package-lock.json | 94 ++++++++++++++++++++++++++++++++++++++++ package.json | 5 +++ 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 package-lock.json create mode 100644 package.json diff --git a/javascript/js_actions.js b/javascript/js_actions.js index 7a85bf8..e629aa4 100644 --- a/javascript/js_actions.js +++ b/javascript/js_actions.js @@ -1,4 +1,4 @@ -const fetch = require("node-fetch"); +import fetch from "node-fetch"; const API_TOKEN = process.env.API_TOKEN; const COMMUNITY_ID = process.env.COMMUNITY_ID; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..2319d17 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,94 @@ +{ + "name": "yearOneβ€”Challenges", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "dependencies": { + "node-fetch": "^3.0.0" + } + }, + "node_modules/data-uri-to-buffer": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-3.0.1.tgz", + "integrity": "sha512-WboRycPNsVw3B3TL559F7kuBUM4d8CgMEvk6xEJlOp7OBPjt6G7z8WMWlD2rOFZLk6OYfFIUGsCOWzcQH9K2og==", + "engines": { + "node": ">= 6" + } + }, + "node_modules/fetch-blob": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.1.2.tgz", + "integrity": "sha512-hunJbvy/6OLjCD0uuhLdp0mMPzP/yd2ssd1t2FCJsaA7wkWhpbp9xfuNVpv7Ll4jFhzp6T4LAupSiV9uOeg0VQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "dependencies": { + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, + "node_modules/node-fetch": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.0.0.tgz", + "integrity": "sha512-bKMI+C7/T/SPU1lKnbQbwxptpCrG9ashG+VkytmXCPZyuM9jB6VU+hY0oi4lC8LxTtAeWdckNCTa3nrGsAdA3Q==", + "dependencies": { + "data-uri-to-buffer": "^3.0.1", + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" + } + }, + "node_modules/web-streams-polyfill": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.1.0.tgz", + "integrity": "sha512-wO9r1YnYe7kFBLHyyVEhV1H8VRWoNiNnuP+v/HUUmSTaRF8F93Kmd3JMrETx0f11GXxRek6OcL2QtjFIdc5WYw==", + "engines": { + "node": ">= 8" + } + } + }, + "dependencies": { + "data-uri-to-buffer": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-3.0.1.tgz", + "integrity": "sha512-WboRycPNsVw3B3TL559F7kuBUM4d8CgMEvk6xEJlOp7OBPjt6G7z8WMWlD2rOFZLk6OYfFIUGsCOWzcQH9K2og==" + }, + "fetch-blob": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.1.2.tgz", + "integrity": "sha512-hunJbvy/6OLjCD0uuhLdp0mMPzP/yd2ssd1t2FCJsaA7wkWhpbp9xfuNVpv7Ll4jFhzp6T4LAupSiV9uOeg0VQ==", + "requires": { + "web-streams-polyfill": "^3.0.3" + } + }, + "node-fetch": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.0.0.tgz", + "integrity": "sha512-bKMI+C7/T/SPU1lKnbQbwxptpCrG9ashG+VkytmXCPZyuM9jB6VU+hY0oi4lC8LxTtAeWdckNCTa3nrGsAdA3Q==", + "requires": { + "data-uri-to-buffer": "^3.0.1", + "fetch-blob": "^3.1.2" + } + }, + "web-streams-polyfill": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.1.0.tgz", + "integrity": "sha512-wO9r1YnYe7kFBLHyyVEhV1H8VRWoNiNnuP+v/HUUmSTaRF8F93Kmd3JMrETx0f11GXxRek6OcL2QtjFIdc5WYw==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..ad62037 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "node-fetch": "^3.0.0" + } +} From 75c1daad37bc414e812b0ad6541c31386e6a146c Mon Sep 17 00:00:00 2001 From: rafawelsh Date: Tue, 31 Aug 2021 14:58:19 -0700 Subject: [PATCH 08/15] changed node-fetch package --- .github/workflows/node.js.yml | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 5c4a6a8..c6790cd 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -6,28 +6,24 @@ name: Node.js CI on: workflow_dispatch: push: - branches: [ main ] + branches: [main] jobs: build: - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [16.x] steps: - - uses: actions/checkout@v2 - - name: Use Node.js - uses: actions/setup-node@v2 - with: - node-version: '12.x' - - name: Install dependencies - run: npm install js-yaml node-fetch - - name: Run Daily File - run: node javascript/add_challenge_to_spaces.js - env: - API_TOKEN: ${{ secrets.API_TOKEN }} - COMMUNITY_ID: ${{ secrets.COMMUNITY_ID }} - CIRCLE_COMMUNITY_PATH: ${{ secrets.CIRCLE_COMMUNITY_PATH }} - DAILY_SPACE_ID: ${{ secrets.DAILY_SPACE_ID }} + - uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v2 + with: + node-version: "12.x" + - name: Install dependencies + run: npm install js-yaml node-fetch + - name: Run Daily File + run: node javascript/add_challenge_to_spaces.js + env: + API_TOKEN: ${{ secrets.API_TOKEN }} + COMMUNITY_ID: ${{ secrets.COMMUNITY_ID }} + CIRCLE_COMMUNITY_PATH: ${{ secrets.CIRCLE_COMMUNITY_PATH }} + DAILY_SPACE_ID: ${{ secrets.DAILY_SPACE_ID }} From 29cd46f7e341cff920d4b9e807b750740b709427 Mon Sep 17 00:00:00 2001 From: rafawelsh Date: Tue, 31 Aug 2021 15:00:03 -0700 Subject: [PATCH 09/15] back to require in js files --- javascript/add_challenge_to_spaces.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/add_challenge_to_spaces.js b/javascript/add_challenge_to_spaces.js index a7e379a..f35630b 100644 --- a/javascript/add_challenge_to_spaces.js +++ b/javascript/add_challenge_to_spaces.js @@ -3,7 +3,7 @@ const fs = require("fs"); const YAML = require("js-yaml"); //import actions -import { postQuestion } from "./js_actions.js"; +const { postQuestion } = require("./js_actions.js"); try { const raw = fs.readFileSync("../topics.yaml"); From dc92733a94286066b782544c1ee985e3de9961c7 Mon Sep 17 00:00:00 2001 From: rafawelsh Date: Tue, 31 Aug 2021 15:02:07 -0700 Subject: [PATCH 10/15] changed fs && YAML to imports --- javascript/add_challenge_to_spaces.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/javascript/add_challenge_to_spaces.js b/javascript/add_challenge_to_spaces.js index f35630b..c0b64b7 100644 --- a/javascript/add_challenge_to_spaces.js +++ b/javascript/add_challenge_to_spaces.js @@ -1,6 +1,6 @@ //Import dependcies -const fs = require("fs"); -const YAML = require("js-yaml"); +import fs from "fs"; +import YAML from "js-yaml"; //import actions const { postQuestion } = require("./js_actions.js"); From 6c0c9be4685f406c2d6dd14e2ca26aacffc7205d Mon Sep 17 00:00:00 2001 From: rafawelsh Date: Tue, 31 Aug 2021 15:03:37 -0700 Subject: [PATCH 11/15] changed fs && YAML to imports --- javascript/add_challenge_to_spaces.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/add_challenge_to_spaces.js b/javascript/add_challenge_to_spaces.js index c0b64b7..6dd8c90 100644 --- a/javascript/add_challenge_to_spaces.js +++ b/javascript/add_challenge_to_spaces.js @@ -3,7 +3,7 @@ import fs from "fs"; import YAML from "js-yaml"; //import actions -const { postQuestion } = require("./js_actions.js"); +import { postQuestion } from "./js_actions.js"; try { const raw = fs.readFileSync("../topics.yaml"); From 31be819aea81cf719292140803facdd8b24a0283 Mon Sep 17 00:00:00 2001 From: rafawelsh Date: Wed, 1 Sep 2021 12:56:07 -0700 Subject: [PATCH 12/15] change in importing postQuestion --- javascript/add_challenge_to_spaces.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/add_challenge_to_spaces.js b/javascript/add_challenge_to_spaces.js index 6dd8c90..9c13e68 100644 --- a/javascript/add_challenge_to_spaces.js +++ b/javascript/add_challenge_to_spaces.js @@ -3,7 +3,7 @@ import fs from "fs"; import YAML from "js-yaml"; //import actions -import { postQuestion } from "./js_actions.js"; +import postQuestion from "./js_actions.js"; try { const raw = fs.readFileSync("../topics.yaml"); From b744c2c2b6291cc7492a762e234bab2f7e4ba81e Mon Sep 17 00:00:00 2001 From: rafawelsh Date: Wed, 1 Sep 2021 12:59:59 -0700 Subject: [PATCH 13/15] export change postQuestion --- javascript/js_actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/js_actions.js b/javascript/js_actions.js index e629aa4..b4527c4 100644 --- a/javascript/js_actions.js +++ b/javascript/js_actions.js @@ -64,4 +64,4 @@ const postQuestion = async (question, questionNumber) => { .catch((error) => console.log("error", error)); }; -module.exports = { postQuestion }; +export default postQuestion; From 5d06b81f9d8964ac0f14ee543acb0b149e9f0f1a Mon Sep 17 00:00:00 2001 From: rafawelsh Date: Wed, 1 Sep 2021 13:05:37 -0700 Subject: [PATCH 14/15] changed file lookup for topics.yaml --- javascript/add_challenge_to_spaces.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/add_challenge_to_spaces.js b/javascript/add_challenge_to_spaces.js index 9c13e68..63b97f2 100644 --- a/javascript/add_challenge_to_spaces.js +++ b/javascript/add_challenge_to_spaces.js @@ -6,7 +6,7 @@ import YAML from "js-yaml"; import postQuestion from "./js_actions.js"; try { - const raw = fs.readFileSync("../topics.yaml"); + const raw = fs.readFileSync("../../topics.yaml"); const data = YAML.load(raw); const lengthOfYAMLfile = Object.values(data).length; const latestQuestion = data[lengthOfYAMLfile]; From 661dc84d8ff7ccac723dbd498ec2dd240244733c Mon Sep 17 00:00:00 2001 From: rafawelsh Date: Wed, 1 Sep 2021 13:28:34 -0700 Subject: [PATCH 15/15] chaned file lookup for topics.yaml 2 --- javascript/add_challenge_to_spaces.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/add_challenge_to_spaces.js b/javascript/add_challenge_to_spaces.js index 63b97f2..0b5edb5 100644 --- a/javascript/add_challenge_to_spaces.js +++ b/javascript/add_challenge_to_spaces.js @@ -6,7 +6,7 @@ import YAML from "js-yaml"; import postQuestion from "./js_actions.js"; try { - const raw = fs.readFileSync("../../topics.yaml"); + const raw = fs.readFileSync("././topics.yaml"); const data = YAML.load(raw); const lengthOfYAMLfile = Object.values(data).length; const latestQuestion = data[lengthOfYAMLfile];