Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing bugs with not showing the full error in comments #18

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ jobs:
files: posts/**
json: "true"

- name: Create processed_files if not exist
arash77 marked this conversation as resolved.
Show resolved Hide resolved
if: steps.get_changed_files.outputs.any_changed == 'true'
run: |
if ! git show-ref --verify --quiet refs/heads/processed_files; then
git checkout --orphan processed_files
echo "{}" > processed_files.json
git add processed_files.json
git commit -m "Create processed_files"
git push origin processed_files
fi

- name: get published files cache
if: steps.get_changed_files.outputs.any_changed == 'true'
run: |
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/publish_content.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ jobs:
with:
files: posts/**
json: "true"

- name: Create processed_files if not exist
if: steps.get_changed_files.outputs.any_changed == 'true'
run: |
if ! git show-ref --verify --quiet refs/heads/processed_files; then
git checkout --orphan processed_files
echo "{}" > processed_files.json
git add processed_files.json
git commit -m "Create processed_files"
git push origin processed_files
fi

- name: get published files cache
if: steps.get_changed_files.outputs.any_changed == 'true'
Expand Down
16 changes: 14 additions & 2 deletions github_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,20 @@ def get_files(self):
args = parser.parse_args()

gs = galaxy_social(args.preview, args.json_out)

lint_errors = []
for file_path in files_to_process:
result, status = gs.lint_markdown_file(file_path)
if not status:
lint_errors.append(file_path)
print(result)
if lint_errors:
github.comment(f"Please check your files: {', '.join(lint_errors)}")
sys.exit(1)

try:
message = gs.process_files(files_to_process)
github.comment(message)
except Exception as e:
message = e
github.comment(message)
github.comment("Something went wrong, an Admin will take a look.")
raise e
12 changes: 10 additions & 2 deletions lib/galaxy_social.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self, preview: bool, json_out: str):
f"Invalid config for {module_name}.{class_name}.\nChange configs in plugins.yml.\n{e}"
)

def parse_markdown_file(self, file_path):
def lint_markdown_file(self, file_path):
with open(file_path, "r") as file:
content = file.read()
try:
Expand All @@ -71,8 +71,16 @@ def parse_markdown_file(self, file_path):
with open(schema_path, "r") as f:
schema = yaml(f)
validate(instance=metadata, schema=schema)
return [metadata, text], True
except Exception as e:
raise Exception(f"Invalid metadata in {file_path}.\n{e}")
return e, False

def parse_markdown_file(self, file_path):
result, status = self.lint_markdown_file(file_path)
if not status:
raise Exception(f"Failed to parse {file_path}.\n{result}")

metadata, text = result

metadata["media"] = [media.lower() for media in metadata["media"]]

Expand Down
18 changes: 13 additions & 5 deletions lib/plugins/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ def __init__(self, **kwargs):

def create_post(self, content, mentions, hashtags, images, **kwargs):
try:
_images = "\n".join(
[f'![{image.get("alt_text", "")}]({image["url"]})' for image in images]
_images = (
"\n"
+ "\n".join(
[
f'![{image.get("alt_text", "")}]({image["url"]})'
for image in images
]
)
if images
else ""
)
mentions = " ".join([f"@{v}" for v in mentions])
hashtags = " ".join([f"#{v}" for v in hashtags])
text = f"{content}\n{mentions}\n{hashtags}\n{_images}"
mentions = "\n" + " ".join([f"@{v}" for v in mentions]) if mentions else ""
hashtags = "\n" + " ".join([f"#{v}" for v in hashtags]) if hashtags else ""
text = f"{content}{mentions}{hashtags}{_images}"
if self.save_path:
os.makedirs(self.save_path, exist_ok=True)
prefix = (
Expand Down
Loading