@@ -89,19 +89,67 @@ const checkFileExists = async (baseUrl, accessToken) => {
8989 } ;
9090} ;
9191
92+ const getUrl = (
93+ githubUsername ,
94+ repo ,
95+ directory ,
96+ rank ,
97+ directoryName ,
98+ fileName ,
99+ languageOfUserSolution ,
100+ isReadmeFile ,
101+ folderStructure
102+ ) => {
103+ let url = `https://api.github.com/repos/${ githubUsername } /${ repo } /contents/${
104+ directory ? directory + "/" : ""
105+ } `;
106+
107+ if ( folderStructure === "level-problem-language" ) {
108+ return (
109+ url + `${ rank } /${ directoryName } /${ isReadmeFile ? "README.md" : fileName } `
110+ ) ;
111+ } else if ( folderStructure === "language-level-problem" ) {
112+ return (
113+ url +
114+ `${ languageOfUserSolution } /${ rank } /${ directoryName } /${
115+ isReadmeFile ? "README.md" : fileName
116+ } `
117+ ) ;
118+ } else if ( folderStructure === "level-language-problem" ) {
119+ return (
120+ url +
121+ `${ rank } /${ languageOfUserSolution } /${ directoryName } /${
122+ isReadmeFile ? "README.md" : fileName
123+ } `
124+ ) ;
125+ }
126+ } ;
127+
92128const addOrUpdateSolution = async (
93129 githubUsername ,
94130 repo ,
95131 directory ,
96132 rank ,
97133 directoryName ,
98134 fileName ,
135+ languageOfUserSolution ,
99136 encodedSolution ,
100137 accessToken
101138) => {
102- const url = `https://api.github.com/repos/${ githubUsername } /${ repo } /contents/${
103- directory ? directory + "/" : ""
104- } ${ rank } /${ directoryName } /${ fileName } `;
139+ const { folderStructure = "level-problem-language" } =
140+ await chrome . storage . local . get ( "folderStructure" ) ;
141+
142+ const url = getUrl (
143+ githubUsername ,
144+ repo ,
145+ directory ,
146+ rank ,
147+ directoryName ,
148+ fileName ,
149+ languageOfUserSolution ,
150+ false ,
151+ folderStructure
152+ ) ;
105153
106154 const { fileExists, data : fileData } = await checkFileExists (
107155 url ,
@@ -141,7 +189,7 @@ const addOrUpdateSolution = async (
141189 ) ;
142190 return { success : true } ;
143191 } catch ( error ) {
144- console . log ( "Error pushing codewars solution to Github !" ) ;
192+ console . log ( "Error pushing codewars solution to GitHub !" ) ;
145193 return { success : false , error : error . message } ;
146194 }
147195} ;
@@ -152,12 +200,24 @@ const addReadme = async (
152200 directory ,
153201 rank ,
154202 directoryName ,
203+ languageOfUserSolution ,
155204 encodedReadMe ,
156205 accessToken
157206) => {
158- const url = `https://api.github.com/repos/${ githubUsername } /${ repo } /contents/${
159- directory ? directory + "/" : ""
160- } ${ rank } /${ directoryName } /README.md`;
207+ const { folderStructure = "level-problem-language" } =
208+ await chrome . storage . local . get ( "folderStructure" ) ;
209+
210+ const url = getUrl (
211+ githubUsername ,
212+ repo ,
213+ directory ,
214+ rank ,
215+ directoryName ,
216+ "README.md" ,
217+ languageOfUserSolution ,
218+ true ,
219+ folderStructure
220+ ) ;
161221
162222 const { fileExists } = await checkFileExists ( url , accessToken ) ;
163223 if ( fileExists ) {
0 commit comments