Skip to content

Commit a15e433

Browse files
committed
feat: enhance Alembic parsing and add Git pull functionality
1 parent ef0edee commit a15e433

3 files changed

Lines changed: 33 additions & 15 deletions

File tree

dist/index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function performPostRequest(requestUrl, payload, token) {
166166
}
167167
});
168168
}
169-
function parseAndCheckAlembic(response) {
169+
function parseAndCheckAlembic(response, source_directory) {
170170
return __awaiter(this, void 0, void 0, function* () {
171171
try {
172172
const output = response.output;
@@ -175,7 +175,7 @@ function parseAndCheckAlembic(response) {
175175
return false;
176176
}
177177
const lines = output.split("\r\n").filter((line) => line.trim() !== "");
178-
const alembicFound = lines.some((line) => line.includes("**Alembic found**"));
178+
const alembicFound = lines.some((line) => line.includes("****"));
179179
if (alembicFound) {
180180
console.log("Alembic found!");
181181
return true;
@@ -249,6 +249,13 @@ function run() {
249249
let web_app = yield setupWebApp(baseWebAppUrl, api_token, domain_name);
250250
// Virtual Environment and Database Setup
251251
const consoleRequestUrl = `${baseApiUrl}/consoles/${consoleId}/send_input/`;
252+
// Git Pull
253+
try {
254+
yield postConsoleInput(consoleRequestUrl, api_token, `git -C ${web_app.source_directory} pull\n`, "Repository Pulled.");
255+
}
256+
catch (error) {
257+
throw new Error(`Error during pulling repository: ${error.message}`);
258+
}
252259
if (framework_type == 'django') {
253260
try {
254261
yield postConsoleInput(consoleRequestUrl, api_token, `source ${web_app.virtualenv_path}/bin/activate\n`, "Virtual Environment Activated.");
@@ -268,14 +275,13 @@ function run() {
268275
else if (framework_type == 'flask') {
269276
try {
270277
const alembicIniPath = `${web_app.source_directory}/alembic.ini`;
271-
yield postConsoleInput(consoleRequestUrl, api_token, `if [ -f ${alembicIniPath} ]; then echo "**Alembic found**"; else echo "Alembic not found"; fi\n`, "Alembic configuration check completed.");
278+
yield postConsoleInput(consoleRequestUrl, api_token, `find ${web_app.source_directory} -type f -name "alembic.ini" -print\n`, "Alembic configuration check completed.");
272279
const alembicResponse = yield getLatestConsoleOutput(baseApiUrl, consoleId, api_token, "Alembic.ini Checking.");
273-
const isAlembicUsing = yield parseAndCheckAlembic(alembicResponse);
280+
const isAlembicUsing = yield parseAndCheckAlembic(alembicResponse, web_app.source_directory);
274281
yield postConsoleInput(consoleRequestUrl, api_token, `source ${web_app.virtualenv_path}/bin/activate\n`, "Virtual Environment Activated.");
275282
yield postConsoleInput(consoleRequestUrl, api_token, `pip install -r ${web_app.source_directory}/requirements.txt\n`, "Requirements Installed.");
276283
if (isAlembicUsing) {
277284
console.log("Alembic migration starting...");
278-
yield postConsoleInput(consoleRequestUrl, api_token, `source ${web_app.virtualenv_path}/bin/activate\n`, "Virtual Environment Activated.");
279285
yield postConsoleInput(consoleRequestUrl, api_token, `alembic upgrade head\n`, "Alembic migrations applied.");
280286
}
281287
}

lib/index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function performPostRequest(requestUrl, payload, token) {
159159
}
160160
});
161161
}
162-
function parseAndCheckAlembic(response) {
162+
function parseAndCheckAlembic(response, source_directory) {
163163
return __awaiter(this, void 0, void 0, function* () {
164164
try {
165165
const output = response.output;
@@ -168,7 +168,7 @@ function parseAndCheckAlembic(response) {
168168
return false;
169169
}
170170
const lines = output.split("\r\n").filter((line) => line.trim() !== "");
171-
const alembicFound = lines.some((line) => line.includes("**Alembic found**"));
171+
const alembicFound = lines.some((line) => line.includes("****"));
172172
if (alembicFound) {
173173
console.log("Alembic found!");
174174
return true;
@@ -242,6 +242,13 @@ function run() {
242242
let web_app = yield setupWebApp(baseWebAppUrl, api_token, domain_name);
243243
// Virtual Environment and Database Setup
244244
const consoleRequestUrl = `${baseApiUrl}/consoles/${consoleId}/send_input/`;
245+
// Git Pull
246+
try {
247+
yield postConsoleInput(consoleRequestUrl, api_token, `git -C ${web_app.source_directory} pull\n`, "Repository Pulled.");
248+
}
249+
catch (error) {
250+
throw new Error(`Error during pulling repository: ${error.message}`);
251+
}
245252
if (framework_type == 'django') {
246253
try {
247254
yield postConsoleInput(consoleRequestUrl, api_token, `source ${web_app.virtualenv_path}/bin/activate\n`, "Virtual Environment Activated.");
@@ -261,14 +268,13 @@ function run() {
261268
else if (framework_type == 'flask') {
262269
try {
263270
const alembicIniPath = `${web_app.source_directory}/alembic.ini`;
264-
yield postConsoleInput(consoleRequestUrl, api_token, `if [ -f ${alembicIniPath} ]; then echo "**Alembic found**"; else echo "Alembic not found"; fi\n`, "Alembic configuration check completed.");
271+
yield postConsoleInput(consoleRequestUrl, api_token, `find ${web_app.source_directory} -type f -name "alembic.ini" -print\n`, "Alembic configuration check completed.");
265272
const alembicResponse = yield getLatestConsoleOutput(baseApiUrl, consoleId, api_token, "Alembic.ini Checking.");
266-
const isAlembicUsing = yield parseAndCheckAlembic(alembicResponse);
273+
const isAlembicUsing = yield parseAndCheckAlembic(alembicResponse, web_app.source_directory);
267274
yield postConsoleInput(consoleRequestUrl, api_token, `source ${web_app.virtualenv_path}/bin/activate\n`, "Virtual Environment Activated.");
268275
yield postConsoleInput(consoleRequestUrl, api_token, `pip install -r ${web_app.source_directory}/requirements.txt\n`, "Requirements Installed.");
269276
if (isAlembicUsing) {
270277
console.log("Alembic migration starting...");
271-
yield postConsoleInput(consoleRequestUrl, api_token, `source ${web_app.virtualenv_path}/bin/activate\n`, "Virtual Environment Activated.");
272278
yield postConsoleInput(consoleRequestUrl, api_token, `alembic upgrade head\n`, "Alembic migrations applied.");
273279
}
274280
}

src/index.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ async function performPostRequest(requestUrl: string, payload: any, token?: stri
135135
}
136136
}
137137

138-
async function parseAndCheckAlembic(response: any): Promise<boolean> {
138+
async function parseAndCheckAlembic(response: any, source_directory: string): Promise<boolean> {
139139
try {
140140
const output: string = response.output;
141141

@@ -146,7 +146,7 @@ async function parseAndCheckAlembic(response: any): Promise<boolean> {
146146

147147
const lines = output.split("\r\n").filter((line) => line.trim() !== "");
148148

149-
const alembicFound = lines.some((line) => line.includes("**Alembic found**"));
149+
const alembicFound = lines.some((line) => line.includes("****"));
150150

151151
if (alembicFound) {
152152
console.log("Alembic found!");
@@ -217,6 +217,13 @@ async function run() {
217217
// Virtual Environment and Database Setup
218218
const consoleRequestUrl = `${baseApiUrl}/consoles/${consoleId}/send_input/`;
219219

220+
// Git Pull
221+
try{
222+
await postConsoleInput(consoleRequestUrl, api_token, `git -C ${web_app.source_directory} pull\n`, "Repository Pulled.");
223+
} catch (error: any) {
224+
throw new Error(`Error during pulling repository: ${error.message}`);
225+
}
226+
220227
if (framework_type == 'django') {
221228
try {
222229
await postConsoleInput(consoleRequestUrl, api_token, `source ${web_app.virtualenv_path}/bin/activate\n`, "Virtual Environment Activated.");
@@ -235,16 +242,15 @@ async function run() {
235242
else if (framework_type == 'flask') {
236243
try {
237244
const alembicIniPath = `${web_app.source_directory}/alembic.ini`;
238-
await postConsoleInput(consoleRequestUrl, api_token, `if [ -f ${alembicIniPath} ]; then echo "**Alembic found**"; else echo "Alembic not found"; fi\n`, "Alembic configuration check completed.");
245+
await postConsoleInput(consoleRequestUrl, api_token, `find ${web_app.source_directory} -type f -name "alembic.ini" -print\n`, "Alembic configuration check completed.");
239246
const alembicResponse = await getLatestConsoleOutput(baseApiUrl, consoleId, api_token, "Alembic.ini Checking.") as unknown as string;
240-
const isAlembicUsing = await parseAndCheckAlembic(alembicResponse);
247+
const isAlembicUsing = await parseAndCheckAlembic(alembicResponse, web_app.source_directory);
241248

242249
await postConsoleInput(consoleRequestUrl, api_token, `source ${web_app.virtualenv_path}/bin/activate\n`, "Virtual Environment Activated.");
243250
await postConsoleInput(consoleRequestUrl, api_token, `pip install -r ${web_app.source_directory}/requirements.txt\n`, "Requirements Installed.");
244251

245252
if (isAlembicUsing) {
246253
console.log("Alembic migration starting...");
247-
await postConsoleInput(consoleRequestUrl, api_token, `source ${web_app.virtualenv_path}/bin/activate\n`, "Virtual Environment Activated.");
248254
await postConsoleInput(consoleRequestUrl, api_token, `alembic upgrade head\n`, "Alembic migrations applied.");
249255
}
250256

0 commit comments

Comments
 (0)