diff --git a/dist/index.js b/dist/index.js index 03f4534..cee9a1e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1636,7 +1636,7 @@ const serializers = { }, PushEvent: (item) => { return `🔥 Pushed to ${item.repo.name}`; - } + }, }; Toolkit.run( @@ -1686,70 +1686,34 @@ Toolkit.run( tools.log.info("Found less than 5 activities"); } - if (startIdx !== -1 && endIdx === -1) { - // Add one since the content needs to be inserted just after the initial comment - startIdx++; - content.forEach((line, idx) => - readmeContent.splice(startIdx + idx, 0, `${idx + 1}. ${line}`) - ); - - // Append comment - readmeContent.splice( - startIdx + content.length, - 0, - "" - ); + if (endIdx !== -1) { + const oldContent = readmeContent.slice(startIdx + 1, endIdx).join("\n"); - // Update README - fs.writeFileSync("./README.md", readmeContent.join("\n")); + const newContent = content + .map((line, idx) => `${idx + 1}. ${line}`) + .join("\n"); - // Commit to the remote repository - try { - await commitFile(); - } catch (err) { - tools.log.debug("Something went wrong"); - return tools.exit.failure(err); + if (oldContent.trim() === newContent.trim()) { + tools.exit.success("No changes detected"); } - tools.exit.success("Wrote to README"); + // Remove old content + readmeContent.slice(startIdx, endIdx + 1).forEach((line) => { + readmeContent.splice(startIdx + 1, 1); + }); } - const oldContent = readmeContent.slice(startIdx + 1, endIdx).join("\n"); - const newContent = content - .map((line, idx) => `${idx + 1}. ${line}`) - .join("\n"); - - if (oldContent.trim() === newContent.trim()) - tools.exit.success("No changes detected"); - + // Add one since the content needs to be inserted just after the initial comment startIdx++; + content.forEach((line, idx) => + readmeContent.splice(startIdx + idx, 0, `${idx + 1}. ${line}`) + ); - // Recent GitHub Activity content between the comments - const readmeActivitySection = readmeContent.slice(startIdx, endIdx); - if (!readmeActivitySection.length) { - content.some((line, idx) => { - // User doesn't have 5 public events - if (!line) { - return true; - } - readmeContent.splice(startIdx + idx, 0, `${idx + 1}. ${line}`); - }); - tools.log.success("Wrote to README"); - } else { - // It is likely that a newline is inserted after the comment (code formatter) - let count = 0; - - readmeActivitySection.some((line, idx) => { - // User doesn't have 5 public events - if (!content[count]) { - return true; - } - if (line !== "") { - readmeContent[startIdx + idx] = `${count + 1}. ${content[count]}`; - count++; - } - }); - tools.log.success("Updated README with the recent activity"); - } + // Append comment + readmeContent.splice( + startIdx + content.length, + 0, + "" + ); // Update README fs.writeFileSync("./README.md", readmeContent.join("\n")); @@ -1761,6 +1725,7 @@ Toolkit.run( tools.log.debug("Something went wrong"); return tools.exit.failure(err); } + tools.exit.success("Pushed to remote repository"); }, { diff --git a/index.js b/index.js index 0963dc1..159bcf2 100644 --- a/index.js +++ b/index.js @@ -99,7 +99,7 @@ const serializers = { }, PushEvent: (item) => { return `🔥 Pushed to ${item.repo.name}`; - } + }, }; Toolkit.run( @@ -149,70 +149,34 @@ Toolkit.run( tools.log.info("Found less than 5 activities"); } - if (startIdx !== -1 && endIdx === -1) { - // Add one since the content needs to be inserted just after the initial comment - startIdx++; - content.forEach((line, idx) => - readmeContent.splice(startIdx + idx, 0, `${idx + 1}. ${line}`) - ); + if (endIdx !== -1) { + const oldContent = readmeContent.slice(startIdx + 1, endIdx).join("\n"); - // Append comment - readmeContent.splice( - startIdx + content.length, - 0, - "" - ); + const newContent = content + .map((line, idx) => `${idx + 1}. ${line}`) + .join("\n"); - // Update README - fs.writeFileSync("./README.md", readmeContent.join("\n")); - - // Commit to the remote repository - try { - await commitFile(); - } catch (err) { - tools.log.debug("Something went wrong"); - return tools.exit.failure(err); + if (oldContent.trim() === newContent.trim()) { + tools.exit.success("No changes detected"); } - tools.exit.success("Wrote to README"); + // Remove old content + readmeContent.slice(startIdx, endIdx + 1).forEach((line) => { + readmeContent.splice(startIdx + 1, 1); + }); } - const oldContent = readmeContent.slice(startIdx + 1, endIdx).join("\n"); - const newContent = content - .map((line, idx) => `${idx + 1}. ${line}`) - .join("\n"); - - if (oldContent.trim() === newContent.trim()) - tools.exit.success("No changes detected"); - + // Add one since the content needs to be inserted just after the initial comment startIdx++; + content.forEach((line, idx) => + readmeContent.splice(startIdx + idx, 0, `${idx + 1}. ${line}`) + ); - // Recent GitHub Activity content between the comments - const readmeActivitySection = readmeContent.slice(startIdx, endIdx); - if (!readmeActivitySection.length) { - content.some((line, idx) => { - // User doesn't have 5 public events - if (!line) { - return true; - } - readmeContent.splice(startIdx + idx, 0, `${idx + 1}. ${line}`); - }); - tools.log.success("Wrote to README"); - } else { - // It is likely that a newline is inserted after the comment (code formatter) - let count = 0; - - readmeActivitySection.some((line, idx) => { - // User doesn't have 5 public events - if (!content[count]) { - return true; - } - if (line !== "") { - readmeContent[startIdx + idx] = `${count + 1}. ${content[count]}`; - count++; - } - }); - tools.log.success("Updated README with the recent activity"); - } + // Append comment + readmeContent.splice( + startIdx + content.length, + 0, + "" + ); // Update README fs.writeFileSync("./README.md", readmeContent.join("\n")); @@ -224,6 +188,7 @@ Toolkit.run( tools.log.debug("Something went wrong"); return tools.exit.failure(err); } + tools.exit.success("Pushed to remote repository"); }, {