Skip to content
Open
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
15 changes: 10 additions & 5 deletions _data/links/Children/Main/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,17 @@
"website": "https://padlet.com/redirect?url=https%3A%2F%2Fschool.booksgiant.com%2Flogin%2Fhe"
},
{
"displayName": "Foo-babysit",
"name": "BrainPop",
"displayName": "BrainPop",
"shortDescription": "תכנים חינוכיים עם קוד חינמי",
"description": "קוד: בריינפופ23",
"url": "https://il.brainpop.com/",
"website": "https://il.brainpop.com/"
"shortDescription": "FooFoo-Baz",
"description": "helloFoo-world",
"tags": [
"החמ'ל המתוק",
"הילדים/ראשי",
"באר213111",
"FooBaz",
"עולם שלום"
]
},
{
"displayName": "simplesteps",
Expand Down
35 changes: 17 additions & 18 deletions scripts/generatePullRequestForNewInitiative.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = async ({github, context}) => {
return text.substring(indexOfJsonStart + jsonStartMarker.length, indexOfJsonEnd);
}

async function createOrUpdatePullRequestAsync(branch, name) {
async function createOrUpdatePullRequestAsync(update, branch, name) {

const existingResponse = await github.rest.pulls.list({
owner: context.repo.owner,
Expand All @@ -40,7 +40,7 @@ module.exports = async ({github, context}) => {
}

const newResponse = await github.rest.pulls.create({
title: `New Initiative: ${name} [Suggested by ${process.env.ISSUE_AUTHOR}]`,
title: `${update ? "Update" : "New"} Initiative: ${name} [Suggested by ${process.env.ISSUE_AUTHOR}]`,
owner: context.repo.owner,
repo: context.repo.repo,
head: branch,
Expand Down Expand Up @@ -151,18 +151,18 @@ See GitHub Action logs for more details: ${context.serverUrl}/${context.repo.own
const linksJsonString = await fs.readFile(linkJsonFileName, "utf8");
const upperlinksJsonString = linksJsonString.toLocaleUpperCase("en-us");

for (const prop in newInitiativeJson) {
for (const propName in newInitiativeJson) {

const value = newInitiativeJson[prop];
if (typeof value !== "string") {
const value = newInitiativeJson[propName];
if (propName === "initiativeValidationDetails" || typeof value !== "string") {
continue;
}

const PropValueUpper = value.toLocaleUpperCase("en-us");
if (upperlinksJsonString.indexOf(PropValueUpper) !== -1) {
await warnAndCommentAsync(
`Initiative might already exist!
The value of property \`${prop}\` (\`${value}\`) is already present in \`${linkJsonFileName}\`:
The value of property \`${propName}\` (\`${value}\`) is already present in \`${linkJsonFileName}\`:
\`\`\`json
${linksJsonString}
\`\`\`
Expand All @@ -178,24 +178,21 @@ ${linksJsonString}
return false;
}

async function updateExistingInitiativeAsync(categoryJson, newInitiativeJson) {
async function getExistingInitiativeIndexAsync(categoryJson, newInitiativeJson) {
const initiativeName = newInitiativeJson.name;

if (!(initiativeName?.trim())) {
await warnAndCommentAsync("For update, you must provide a name that matches the name of an existing initiative", "no initiative name provided", newInitiativeJson);
return false;
return -1;
}

const existingCategoryIndex = categoryJson.links.findIndex((link =>
link.name?.localeCompare(initiativeName, undefined, { sensitivity: 'accent' }) === 0
))
const existingCategoryIndex = categoryJson.links.findIndex(link => link.name?.localeCompare(initiativeName, undefined, { sensitivity: 'accent' }) === 0)
if (existingCategoryIndex === -1) {
await warnAndCommentAsync(`Could not find existing initiative '${initiativeName}' in category '${category}'`, "initiative not found", newInitiativeJson);
return false;
return -1;
}

categoryJson.links[existingCategoryIndex] = newInitiativeJson;
return true;
return existingCategoryIndex;
}

const tempFolder = process.env.TEMP || "/tmp";
Expand Down Expand Up @@ -237,7 +234,7 @@ ${linksJsonString}
return;
}

let categoryLinksJsonFile;
let categoryJson, categoryLinksJsonFile;
try {
categoryLinksJsonFile = `${process.env.GITHUB_WORKSPACE}/_data/links/${category}/links.json`;
console.log("resolved category links file: " + categoryLinksJsonFile);
Expand All @@ -250,10 +247,12 @@ ${linksJsonString}
}

if (updateInitiative) {
const edited = await updateExistingInitiativeAsync(categoryJson, newInitiativeJson, newInitiativeJson)
if (!edited) {
const existingInitiativeIndex = await getExistingInitiativeIndexAsync(categoryJson, newInitiativeJson, newInitiativeJson)
if (existingInitiativeIndex === -1) {
return;
}

categoryJson.links[existingInitiativeIndex] = newInitiativeJson;
}
else {
categoryJson.links.push(newInitiativeJson);
Expand All @@ -271,7 +270,7 @@ ${linksJsonString}

let pr;
try {
pr = await createOrUpdatePullRequestAsync(branch, newInitiativeJson.name || "???");
pr = await createOrUpdatePullRequestAsync(updateInitiative, branch, newInitiativeJson.name || "???");
}
catch (e) {
return await warnAndCommentAsync("Could not create pull request", e, newInitiativeJson);
Expand Down