Skip to content

Commit

Permalink
Merge branch 'main' into matrix-post-attempt-2
Browse files Browse the repository at this point in the history
  • Loading branch information
wm75 committed May 14, 2024
2 parents ad5156c + 5c155bb commit 162022c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish_content.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }}
BLUESKY_USERNAME: ${{ secrets.BLUESKY_USERNAME }}
BLUESKY_PASSWORD: ${{ secrets.BLUESKY_PASSWORD }}
MASTODON_EU_FR_TOKEN: ${{ secrets.MASTODON_EU_FR_TOKEN }}
MATRIX_ACCESS_TOKEN: ${{ secrets.MATRIX_ACCESS_TOKEN }}
SLACK_ACCESS_TOKEN: ${{ secrets.SLACK_ACCESS_TOKEN }}
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID }}
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
14 changes: 11 additions & 3 deletions plugins.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
plugins:
- name: mastodon
class: mastodon.mastodon_client
enabled: true
enabled: false
config:
base_url: "https://mstdn.science"
access_token: $MASTODON_ACCESS_TOKEN
max_content_length: 500

- name: bluesky
class: bluesky.bluesky_client
enabled: true
enabled: false
config:
base_url: "https://bsky.social"
username: $BLUESKY_USERNAME
password: $BLUESKY_PASSWORD
max_content_length: 300

- name: mastodon-eu-freiburg
class: mastodon.mastodon_client
enabled: true
config:
base_url: "https://xn--baw-joa.social"
access_token: $MASTODON_EU_FR_TOKEN
max_content_length: 500

- name: matrix-eu-announce
class: matrix.matrix_client
enabled: true
Expand All @@ -26,7 +34,7 @@ plugins:

- name: slack
class: slack.slack_client
enabled: true
enabled: false
config:
access_token: $SLACK_ACCESS_TOKEN
channel_id: $SLACK_CHANNEL_ID
Expand Down

0 comments on commit 162022c

Please sign in to comment.