diff --git a/daemon.py b/daemon.py index e2d583afd..0bb365580 100644 --- a/daemon.py +++ b/daemon.py @@ -450,6 +450,7 @@ from maps import map_format_from_tagmaps_path from relationships import get_moved_feed from relationships import get_inactive_feed from relationships import update_moved_actors +from git import get_repo_url # maximum number of posts to list in outbox feed MAX_POSTS_IN_FEED = 12 @@ -9010,6 +9011,7 @@ class PubServer(BaseHTTPRequestHandler): locked_account = False also_known_as = None moved_to = '' + repo_url = None actor_json = \ get_person_from_cache(base_dir, options_actor, @@ -9040,6 +9042,7 @@ class PubServer(BaseHTTPRequestHandler): pgp_fingerprint = get_pgp_fingerprint(actor_json) if actor_json.get('alsoKnownAs'): also_known_as = remove_html(actor_json['alsoKnownAs']) + repo_url = get_repo_url(actor_json) access_keys = self.server.access_keys nickname = 'instance' @@ -9096,7 +9099,8 @@ class PubServer(BaseHTTPRequestHandler): authorized, access_keys, is_group, self.server.theme_name, - self.server.blocked_cache) + self.server.blocked_cache, + repo_url) if msg: msg = msg.encode('utf-8') msglen = len(msg) diff --git a/git.py b/git.py index 714d6ec98..cc26fde57 100644 --- a/git.py +++ b/git.py @@ -12,6 +12,8 @@ import html from utils import acct_dir from utils import has_object_string_type from utils import text_in_file +from utils import get_attachment_property_value +from utils import remove_html def _git_format_content(content: str) -> str: @@ -220,3 +222,40 @@ def receive_git_patch(base_dir: str, nickname: str, domain: str, except OSError as ex: print('EX: receive_git_patch ' + patch_filename + ' ' + str(ex)) return False + + +def get_repo_url(actor_json: {}) -> str: + """Returns a link used for code repo + """ + if not actor_json.get('attachment'): + return '' + repo_type = ('github', 'gitlab', 'codeberg', 'launchpad', + 'sourceforge', 'bitbucket', 'gitea') + for property_value in actor_json['attachment']: + name_value = None + if property_value.get('name'): + name_value = property_value['name'] + elif property_value.get('schema:name'): + name_value = property_value['schema:name'] + if not name_value: + continue + if name_value.lower() not in repo_type: + continue + if not property_value.get('type'): + continue + prop_value_name, prop_value = \ + get_attachment_property_value(property_value) + if not prop_value: + continue + if not property_value['type'].endswith('PropertyValue'): + continue + if ' str: + blocked_cache: [], + repo_url: str) -> str: """Show options for a person: view/follow/block/report """ options_link_str = '' @@ -364,6 +365,13 @@ def html_person_options(default_timeline: str, options_str += \ '

🌐 ' + \ web_address + '

\n' + if repo_url: + repo_str = remove_html(repo_url) + if '://' not in repo_str: + repo_str = 'https://' + repo_str + options_str += \ + '

💻 ' + \ + repo_url + '

\n' if gemini_link: gemini_str = remove_html(gemini_link) if '://' not in gemini_str: