Skip to content

Commit 6b94edc

Browse files
chore: improve codebase structure and fix workflow fail
1 parent e1c55ce commit 6b94edc

15 files changed

+432
-367
lines changed

dist/index.js

Lines changed: 161 additions & 118 deletions
Large diffs are not rendered by default.

dist/utils/createArticlesReadme.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"use strict";
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
var desc = Object.getOwnPropertyDescriptor(m, k);
5+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6+
desc = { enumerable: true, get: function() { return m[k]; } };
7+
}
8+
Object.defineProperty(o, k2, desc);
9+
}) : (function(o, m, k, k2) {
10+
if (k2 === undefined) k2 = k;
11+
o[k2] = m[k];
12+
}));
13+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14+
Object.defineProperty(o, "default", { enumerable: true, value: v });
15+
}) : function(o, v) {
16+
o["default"] = v;
17+
});
18+
var __importStar = (this && this.__importStar) || function (mod) {
19+
if (mod && mod.__esModule) return mod;
20+
var result = {};
21+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22+
__setModuleDefault(result, mod);
23+
return result;
24+
};
25+
Object.defineProperty(exports, "__esModule", { value: true });
26+
exports.createArticlesReadme = void 0;
27+
const core = __importStar(require("@actions/core"));
28+
const fs = __importStar(require("fs"));
29+
const git_1 = require("./git");
30+
const performGitActions_1 = require("./performGitActions");
31+
const conventionalCommits = core.getInput("conventionalCommits") === "true" || true;
32+
async function createArticlesReadme(articles, outputDir, branch) {
33+
// Create content for README.md
34+
let readmeContent = "";
35+
const readmePath = `${outputDir}/README.md`;
36+
if (fs.existsSync(readmePath)) {
37+
readmeContent = fs.readFileSync(readmePath, "utf8");
38+
}
39+
const hasTableOfContentsHeading = readmeContent.includes("# Table of Contents\n\n");
40+
// Set the commit message based on whether the heading exists
41+
let commitMessage = hasTableOfContentsHeading
42+
? "update readme with table of contents"
43+
: "create readme with table of contents";
44+
if (!hasTableOfContentsHeading) {
45+
readmeContent = "# Table of Contents\n\n";
46+
}
47+
for (const article of articles) {
48+
const fileName = (0, git_1.getFileNameFromTitle)(article.title).trim();
49+
const fileLink = `./${fileName}.md`;
50+
if (readmeContent.includes(`[${article.title}]`)) {
51+
console.log(`Skipping "${article.title}" because it already exists in the table of contents.`);
52+
continue;
53+
}
54+
// Add entry to README content
55+
readmeContent += `- [${article.title}](${fileLink.replace(/ /g, "%20")})\n`;
56+
}
57+
// Write README.md
58+
fs.writeFileSync(readmePath, readmeContent);
59+
if (conventionalCommits) {
60+
commitMessage = `chore: ${commitMessage.toLowerCase()}`;
61+
}
62+
(0, performGitActions_1.performGitActions)({
63+
commitMessage,
64+
path: readmePath,
65+
branch,
66+
noticeMessage: "README.md file created and committed"
67+
});
68+
}
69+
exports.createArticlesReadme = createArticlesReadme;

dist/utils/createMarkdownFile.js

Lines changed: 16 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ const fs = __importStar(require("fs"));
2929
const git_1 = require("./git");
3030
const parseMarkdownContent_1 = require("./parseMarkdownContent");
3131
const fetchDevArticleUsingId_1 = require("./fetchDevArticleUsingId");
32+
const performGitActions_1 = require("./performGitActions");
33+
const createArticlesReadme_1 = require("./createArticlesReadme");
3234
const conventionalCommits = core.getInput("conventionalCommits") === "true" || true;
3335
async function createMarkdownFile(articles, outputDir, branch, apiKey) {
3436
// output directory must exist
@@ -55,18 +57,13 @@ async function createMarkdownFile(articles, outputDir, branch, apiKey) {
5557
const markdownContent = (0, parseMarkdownContent_1.parseMarkdownContent)(article);
5658
// Write markdown content to file
5759
fs.writeFileSync(filePath, markdownContent);
58-
try {
59-
await (0, git_1.gitConfig)();
60-
await (0, git_1.gitAdd)(filePath);
61-
await (0, git_1.gitCommit)(commitMessage, filePath);
62-
await (0, git_1.gitPull)(branch);
63-
await (0, git_1.gitPush)(branch);
64-
core.notice(`Markdown file created and committed: ${filePath}`);
65-
}
66-
catch (error) {
67-
core.setFailed(`Failed to commit and push changes: ${error.message}`);
68-
}
69-
core.notice(`Markdown file created: ${filePath}`);
60+
(0, performGitActions_1.performGitActions)({
61+
commitMessage,
62+
path: filePath,
63+
branch
64+
// noticeMessage: "Markdown file created and committed"
65+
});
66+
// core.notice(`Markdown file created: ${filePath}`)
7067
}
7168
else {
7269
const existingContent = fs.readFileSync(filePath, "utf8");
@@ -82,17 +79,12 @@ async function createMarkdownFile(articles, outputDir, branch, apiKey) {
8279
if (conventionalCommits) {
8380
commitMessage = `chore: ${commitMessage.toLowerCase()}`;
8481
}
85-
try {
86-
await (0, git_1.gitConfig)();
87-
await (0, git_1.gitAdd)(filePath);
88-
await (0, git_1.gitCommit)(commitMessage, filePath);
89-
await (0, git_1.gitPull)(branch);
90-
await (0, git_1.gitPush)(branch);
91-
core.notice(`Markdown file created and committed: ${filePath}`);
92-
}
93-
catch (error) {
94-
core.setFailed(`Failed to commit and push changes: ${error.message}`);
95-
}
82+
(0, performGitActions_1.performGitActions)({
83+
commitMessage,
84+
path: filePath,
85+
branch,
86+
noticeMessage: "Markdown file created and committed"
87+
});
9688
}
9789
else {
9890
core.notice(`Markdown file already exists for "${article.title}" and it is not edited. Skipping.`);
@@ -101,49 +93,7 @@ async function createMarkdownFile(articles, outputDir, branch, apiKey) {
10193
}
10294
const tableOfContents = core.getInput("saveArticlesReadme") === "true" || false;
10395
if (tableOfContents) {
104-
await createArticlesReadme(articles, outputDir, branch);
96+
await (0, createArticlesReadme_1.createArticlesReadme)(articles, outputDir, branch);
10597
}
10698
}
10799
exports.createMarkdownFile = createMarkdownFile;
108-
async function createArticlesReadme(articles, outputDir, branch) {
109-
// Create content for README.md
110-
let readmeContent = "";
111-
const readmePath = `${outputDir}/README.md`;
112-
if (fs.existsSync(readmePath)) {
113-
readmeContent = fs.readFileSync(readmePath, "utf8");
114-
}
115-
const hasTableOfContentsHeading = readmeContent.includes("# Table of Contents\n\n");
116-
// Set the commit message based on whether the heading exists
117-
let commitMessage = hasTableOfContentsHeading
118-
? "update readme with table of contents"
119-
: "create readme with table of contents";
120-
if (!hasTableOfContentsHeading) {
121-
readmeContent = "# Table of Contents\n\n";
122-
}
123-
for (const article of articles) {
124-
const fileName = (0, git_1.getFileNameFromTitle)(article.title).trim();
125-
const fileLink = `./${fileName}.md`;
126-
if (readmeContent.includes(`[${article.title}]`)) {
127-
console.log(`Skipping "${article.title}" because it already exists in the table of contents.`);
128-
continue;
129-
}
130-
// Add entry to README content
131-
readmeContent += `- [${article.title}](${fileLink.replace(/ /g, "%20")})\n`;
132-
}
133-
// Write README.md
134-
fs.writeFileSync(readmePath, readmeContent);
135-
if (conventionalCommits) {
136-
commitMessage = `chore: ${commitMessage.toLowerCase()}`;
137-
}
138-
try {
139-
await (0, git_1.gitConfig)();
140-
await (0, git_1.gitAdd)(readmePath);
141-
await (0, git_1.gitCommit)(commitMessage, readmePath);
142-
await (0, git_1.gitPull)(branch);
143-
await (0, git_1.gitPush)(branch);
144-
core.notice("README.md file created and committed");
145-
}
146-
catch (error) {
147-
core.setFailed(`Failed to commit and push changes (readme articles): ${error}`);
148-
}
149-
}

dist/utils/createReadingList.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
2626
exports.createReadingList = void 0;
2727
const core = __importStar(require("@actions/core"));
2828
const fs = __importStar(require("fs"));
29-
const git_1 = require("./git");
29+
const performGitActions_1 = require("./performGitActions");
3030
async function createReadingList(articles, outputDir, branch) {
3131
const readTime = core.getInput("readTime") === "true" || false;
3232
const conventionalCommits = core.getInput("conventionalCommits") === "true" || true;
@@ -76,17 +76,12 @@ async function createReadingList(articles, outputDir, branch) {
7676
}
7777
}
7878
fs.writeFileSync(readmePath, existingContent);
79-
try {
80-
await (0, git_1.gitConfig)();
81-
await (0, git_1.gitAdd)(readmePath);
82-
await (0, git_1.gitCommit)(commitMessage, readmePath);
83-
await (0, git_1.gitPull)(branch);
84-
await (0, git_1.gitPush)(branch);
85-
core.notice(`reading list file created and committed`);
86-
}
87-
catch (error) {
88-
core.setFailed(`Failed to commit and push changes: ${error.message}`);
89-
}
79+
(0, performGitActions_1.performGitActions)({
80+
commitMessage,
81+
path: readmePath,
82+
branch,
83+
noticeMessage: "Reading list file created and committed"
84+
});
9085
core.notice(`Reading list updated in README.md`);
9186
}
9287
exports.createReadingList = createReadingList;

dist/utils/fetchDevToArticles.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,10 @@
11
"use strict";
2-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3-
if (k2 === undefined) k2 = k;
4-
var desc = Object.getOwnPropertyDescriptor(m, k);
5-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6-
desc = { enumerable: true, get: function() { return m[k]; } };
7-
}
8-
Object.defineProperty(o, k2, desc);
9-
}) : (function(o, m, k, k2) {
10-
if (k2 === undefined) k2 = k;
11-
o[k2] = m[k];
12-
}));
13-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14-
Object.defineProperty(o, "default", { enumerable: true, value: v });
15-
}) : function(o, v) {
16-
o["default"] = v;
17-
});
18-
var __importStar = (this && this.__importStar) || function (mod) {
19-
if (mod && mod.__esModule) return mod;
20-
var result = {};
21-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22-
__setModuleDefault(result, mod);
23-
return result;
24-
};
252
var __importDefault = (this && this.__importDefault) || function (mod) {
263
return (mod && mod.__esModule) ? mod : { "default": mod };
274
};
285
Object.defineProperty(exports, "__esModule", { value: true });
296
exports.fetchDevToArticles = void 0;
307
const node_fetch_1 = __importDefault(require("node-fetch"));
31-
const core = __importStar(require("@actions/core"));
328
async function fetchDevToArticles(apiKey, per_page) {
339
if (per_page === undefined)
3410
per_page = 999; // default is 30
@@ -51,7 +27,6 @@ async function fetchDevToArticles(apiKey, per_page) {
5127
articles = articles.concat(pageArticles);
5228
page++;
5329
}
54-
core.notice("Articles fetched and saved successfully.");
5530
return articles;
5631
}
5732
exports.fetchDevToArticles = fetchDevToArticles;

dist/utils/git.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async function gitAdd(filePath) {
4040
await exec.exec("git", ["add", filePath]);
4141
}
4242
catch (error) {
43-
core.setFailed(`Failed to complete git add: ${error.message}`);
43+
core.notice(`Failed to complete git add: ${error.message}`);
4444
}
4545
}
4646
exports.gitAdd = gitAdd;
@@ -58,7 +58,7 @@ async function gitCommit(message, filePath) {
5858
await exec.exec("git", ["commit", "-m", message, filePath]);
5959
}
6060
catch (error) {
61-
core.setFailed(`Failed to complete git commit: ${error.message}`);
61+
core.notice(`Failed to complete git commit: ${error.message}`);
6262
}
6363
}
6464
exports.gitCommit = gitCommit;
@@ -87,7 +87,7 @@ async function gitConfig() {
8787
]);
8888
}
8989
catch (error) {
90-
core.setFailed(`Failed to set up Git configuration: ${error.message}`);
90+
core.notice(`Failed to set up Git configuration: ${error.message}`);
9191
}
9292
}
9393
exports.gitConfig = gitConfig;

dist/utils/performGitActions.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"use strict";
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
var desc = Object.getOwnPropertyDescriptor(m, k);
5+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6+
desc = { enumerable: true, get: function() { return m[k]; } };
7+
}
8+
Object.defineProperty(o, k2, desc);
9+
}) : (function(o, m, k, k2) {
10+
if (k2 === undefined) k2 = k;
11+
o[k2] = m[k];
12+
}));
13+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14+
Object.defineProperty(o, "default", { enumerable: true, value: v });
15+
}) : function(o, v) {
16+
o["default"] = v;
17+
});
18+
var __importStar = (this && this.__importStar) || function (mod) {
19+
if (mod && mod.__esModule) return mod;
20+
var result = {};
21+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22+
__setModuleDefault(result, mod);
23+
return result;
24+
};
25+
Object.defineProperty(exports, "__esModule", { value: true });
26+
exports.performGitActions = void 0;
27+
const core = __importStar(require("@actions/core"));
28+
const git_1 = require("./git");
29+
async function performGitActions({ commitMessage, path, branch, noticeMessage }) {
30+
try {
31+
await (0, git_1.gitConfig)();
32+
await (0, git_1.gitAdd)(path);
33+
await (0, git_1.gitCommit)(commitMessage, path);
34+
await (0, git_1.gitPull)(branch);
35+
await (0, git_1.gitPush)(branch);
36+
if (noticeMessage)
37+
core.notice(noticeMessage);
38+
}
39+
catch (error) {
40+
core.notice(`Failed to commit and push changes: ${error.message}`);
41+
}
42+
}
43+
exports.performGitActions = performGitActions;

dist/utils/synchronizeReadingList.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
2626
exports.synchronizeReadingList = void 0;
2727
const fs = __importStar(require("fs"));
2828
const core = __importStar(require("@actions/core"));
29-
const git_1 = require("./git");
29+
const performGitActions_1 = require("./performGitActions");
3030
async function synchronizeReadingList(readingList, outputDir, branch) {
3131
const readmePath = `./${outputDir}/README.md`;
3232
let commitMessage = "synchronize reading list";
@@ -67,20 +67,15 @@ async function synchronizeReadingList(readingList, outputDir, branch) {
6767
console.log(`Removed these articles from the reading list: ${removedArticles.join(", ")}`);
6868
}
6969
fs.writeFileSync(readmePath, updatedContent);
70-
try {
71-
await (0, git_1.gitConfig)();
72-
await (0, git_1.gitAdd)(readmePath);
73-
await (0, git_1.gitCommit)(commitMessage, readmePath);
74-
await (0, git_1.gitPull)(branch);
75-
await (0, git_1.gitPush)(branch);
76-
}
77-
catch (error) {
78-
core.setFailed(`Failed to commit and push changes: ${error.message}`);
79-
}
70+
(0, performGitActions_1.performGitActions)({
71+
commitMessage,
72+
path: readmePath,
73+
branch
74+
});
8075
core.notice(`Reading list synchronized successfully.`);
8176
}
8277
catch (error) {
83-
core.setFailed(`Failed to synchronize reading list: ${error.message}`);
78+
core.notice(`Failed to synchronize reading list: ${error.message}`);
8479
}
8580
}
8681
exports.synchronizeReadingList = synchronizeReadingList;

0 commit comments

Comments
 (0)