Skip to content

Commit 9133f92

Browse files
committed
script fix
1 parent c49ddff commit 9133f92

File tree

3 files changed

+69
-49
lines changed

3 files changed

+69
-49
lines changed

.github/workflows/scripts/detect_ts_ignore.py

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66
import sys
77
import logging
8+
import os
89

910
# Configure logging
1011
logging.basicConfig(
@@ -14,6 +15,18 @@
1415

1516
TS_IGNORE_PATTERN = r"(?://|/\*)\s*@ts-ignore(?:\s+|$)"
1617

18+
IGNORED_EXTENSIONS = {".avif", ".jpeg", ".png", ".webp", ".mp4", ".webm"}
19+
20+
def is_binary_file(filepath: str) -> bool:
21+
"""Check if a file is binary based on its extension.
22+
23+
Args:
24+
filepath (str): The file path.
25+
26+
Returns:
27+
bool: True if the file should be ignored, False otherwise.
28+
"""
29+
return os.path.splitext(filepath)[1].lower() in IGNORED_EXTENSIONS
1730

1831
def check_ts_ignore(files: list[str]) -> int:
1932
"""Check for occurrences of '@ts-ignore' in the given files.
@@ -27,33 +40,34 @@ def check_ts_ignore(files: list[str]) -> int:
2740
ts_ignore_found = False
2841

2942
for file in files:
30-
try:
31-
logging.info("Checking file: %s", file)
32-
with open(file, encoding="utf-8") as f:
33-
for line_num, line in enumerate(f, start=1):
34-
# Handle more variations of @ts-ignore
35-
if re.search(
36-
TS_IGNORE_PATTERN,
37-
line.strip(),
38-
):
39-
print(
40-
"❌ Error: '@ts-ignore' found in %s at line %d",
41-
file,
42-
line_num,
43-
)
44-
logging.debug(
45-
"Found @ts-ignore in line: %s",
43+
if is_binary_file(file):
44+
try:
45+
logging.info("Checking file: %s", file)
46+
with open(file, encoding="utf-8") as f:
47+
for line_num, line in enumerate(f, start=1):
48+
# Handle more variations of @ts-ignore
49+
if re.search(
50+
TS_IGNORE_PATTERN,
4651
line.strip(),
47-
)
48-
ts_ignore_found = True
49-
except FileNotFoundError:
50-
logging.warning("File not found: %s", file)
51-
except OSError:
52-
logging.exception("Could not read %s", file)
53-
if not ts_ignore_found:
54-
print("✅ No '@ts-ignore' comments found in the files.")
55-
56-
return 1 if ts_ignore_found else 0
52+
):
53+
print(
54+
"❌ Error: '@ts-ignore' found in %s at line %d",
55+
file,
56+
line_num,
57+
)
58+
logging.debug(
59+
"Found @ts-ignore in line: %s",
60+
line.strip(),
61+
)
62+
ts_ignore_found = True
63+
except FileNotFoundError:
64+
logging.warning("File not found: %s", file)
65+
except OSError:
66+
logging.exception("Could not read %s", file)
67+
if not ts_ignore_found:
68+
print("✅ No '@ts-ignore' comments found in the files.")
69+
70+
return 1 if ts_ignore_found else 0
5771

5872

5973
def main() -> None:

src/utilities/loadSampleData.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -221,32 +221,38 @@ async function insertCollections(
221221
await db.insert(schema.postVotesTable).values(post_votes);
222222
break;
223223
}
224-
case "post_attachements": {
225-
const post_attachements = JSON.parse(data).map(
224+
case "post_attachments": {
225+
const post_attachments = JSON.parse(data).map(
226226
(post_attachement: { createdAt: string | number | Date }) => ({
227227
...post_attachement,
228228
createdAt: parseDate(post_attachement.createdAt),
229229
}),
230230
) as (typeof schema.postAttachmentsTable.$inferInsert)[];
231-
await db
232-
.insert(schema.postAttachmentsTable)
233-
.values(post_attachements);
234-
post_attachements.map(async (attachment) => {
235-
const fileExtension = attachment.mimeType.split("/").pop();
236-
const filePath = path.resolve(
237-
dirname,
238-
`../../sample_data/images/${attachment.name}.${fileExtension}`,
239-
);
240-
const readStream = await fs.readFile(filePath);
241-
await minioClient.putObject(
242-
"talawa",
243-
attachment.name,
244-
readStream,
245-
undefined,
246-
{
247-
"content-type": attachment.mimeType,
248-
},
249-
);
231+
await db.insert(schema.postAttachmentsTable).values(post_attachments);
232+
post_attachments.map(async (attachment) => {
233+
try {
234+
const fileExtension = attachment.mimeType.split("/").pop();
235+
const filePath = path.resolve(
236+
dirname,
237+
`../../sample_data/images/${attachment.name}.${fileExtension}`,
238+
);
239+
const readStream = await fs.readFile(filePath);
240+
await minioClient.putObject(
241+
"talawa",
242+
attachment.name,
243+
readStream,
244+
undefined,
245+
{
246+
"content-type": attachment.mimeType,
247+
},
248+
);
249+
} catch (error) {
250+
console.error(
251+
`Failed to upload attachment ${attachment.name}:`,
252+
error,
253+
);
254+
throw error;
255+
}
250256
});
251257
break;
252258
}
@@ -315,7 +321,7 @@ async function checkCountAfterImport(): Promise<boolean> {
315321
},
316322
{ name: "posts", table: schema.postsTable },
317323
{ name: "post_votes", table: schema.postVotesTable },
318-
{ name: "post_attachements", table: schema.postAttachmentsTable },
324+
{ name: "post_attachments", table: schema.postAttachmentsTable },
319325
{ name: "comments", table: schema.commentsTable },
320326
{ name: "comment_votes", table: schema.commentVotesTable },
321327
];
@@ -356,7 +362,7 @@ const collections = [
356362
"organization_memberships",
357363
"posts",
358364
"post_votes",
359-
"post_attachements",
365+
"post_attachments",
360366
"comments",
361367
"comment_votes",
362368
]; // Add organization memberships to collections

0 commit comments

Comments
 (0)