@@ -29,6 +29,8 @@ const fs = __importStar(require("fs"));
29
29
const git_1 = require ( "./git" ) ;
30
30
const parseMarkdownContent_1 = require ( "./parseMarkdownContent" ) ;
31
31
const fetchDevArticleUsingId_1 = require ( "./fetchDevArticleUsingId" ) ;
32
+ const performGitActions_1 = require ( "./performGitActions" ) ;
33
+ const createArticlesReadme_1 = require ( "./createArticlesReadme" ) ;
32
34
const conventionalCommits = core . getInput ( "conventionalCommits" ) === "true" || true ;
33
35
async function createMarkdownFile ( articles , outputDir , branch , apiKey ) {
34
36
// output directory must exist
@@ -55,18 +57,13 @@ async function createMarkdownFile(articles, outputDir, branch, apiKey) {
55
57
const markdownContent = ( 0 , parseMarkdownContent_1 . parseMarkdownContent ) ( article ) ;
56
58
// Write markdown content to file
57
59
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}`)
70
67
}
71
68
else {
72
69
const existingContent = fs . readFileSync ( filePath , "utf8" ) ;
@@ -82,17 +79,12 @@ async function createMarkdownFile(articles, outputDir, branch, apiKey) {
82
79
if ( conventionalCommits ) {
83
80
commitMessage = `chore: ${ commitMessage . toLowerCase ( ) } ` ;
84
81
}
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
+ } ) ;
96
88
}
97
89
else {
98
90
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) {
101
93
}
102
94
const tableOfContents = core . getInput ( "saveArticlesReadme" ) === "true" || false ;
103
95
if ( tableOfContents ) {
104
- await createArticlesReadme ( articles , outputDir , branch ) ;
96
+ await ( 0 , createArticlesReadme_1 . createArticlesReadme ) ( articles , outputDir , branch ) ;
105
97
}
106
98
}
107
99
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
- }
0 commit comments