mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	integrations: Render bots' docs alongside integration docs.
This commit implements support for rendering static files in under static/generated/bots/ in the same manner as we render our webhooks/integration documentation. Said static files are generated by tools/setup/generate_zulip_bots_static_files.py during provisioning.
This commit is contained in:
		@@ -47,6 +47,7 @@ CATEGORIES = {
 | 
			
		||||
    'project-management': _('Project management'),
 | 
			
		||||
    'productivity': _('Productivity'),
 | 
			
		||||
    'version-control': _('Version control'),
 | 
			
		||||
    'bots': _('Interactive bots'),
 | 
			
		||||
}  # type: Dict[str, str]
 | 
			
		||||
 | 
			
		||||
class Integration(object):
 | 
			
		||||
@@ -94,6 +95,42 @@ class Integration(object):
 | 
			
		||||
        # type: (Dict[Any, Any]) -> None
 | 
			
		||||
        self.doc_context = context
 | 
			
		||||
 | 
			
		||||
class BotIntegration(Integration):
 | 
			
		||||
    DEFAULT_LOGO_STATIC_PATH_PNG = 'static/generated/bots/{name}/logo.png'
 | 
			
		||||
    DEFAULT_LOGO_STATIC_PATH_SVG = 'static/generated/bots/{name}/logo.svg'
 | 
			
		||||
    ZULIP_LOGO_STATIC_PATH_PNG = 'static/images/logo/zulip-icon-128x128.png'
 | 
			
		||||
    DEFAULT_DOC_PATH = '{name}/doc.md'
 | 
			
		||||
 | 
			
		||||
    def __init__(self, name, categories, logo=None, secondary_line_text=None,
 | 
			
		||||
                 display_name=None, doc=None):
 | 
			
		||||
        # type: (str, List[str], Optional[str], Optional[str], Optional[str], Optional[str]) -> None
 | 
			
		||||
        super(BotIntegration, self).__init__(
 | 
			
		||||
            name,
 | 
			
		||||
            client_name=name,
 | 
			
		||||
            categories=categories,
 | 
			
		||||
            secondary_line_text=secondary_line_text,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        if logo is None:
 | 
			
		||||
            if os.path.isfile(self.DEFAULT_LOGO_STATIC_PATH_PNG.format(name=name)):
 | 
			
		||||
                logo = self.DEFAULT_LOGO_STATIC_PATH_PNG.format(name=name)
 | 
			
		||||
            elif os.path.isfile(self.DEFAULT_LOGO_STATIC_PATH_SVG.format(name=name)):
 | 
			
		||||
                logo = self.DEFAULT_LOGO_STATIC_PATH_SVG.format(name=name)
 | 
			
		||||
            else:
 | 
			
		||||
                # TODO: Add a test for this by initializing one in a test.
 | 
			
		||||
                logo = self.ZULIP_LOGO_STATIC_PATH_PNG  # nocoverage
 | 
			
		||||
        self.logo = logo
 | 
			
		||||
 | 
			
		||||
        if display_name is None:
 | 
			
		||||
            display_name = "{} Bot".format(name.title())  # nocoverage
 | 
			
		||||
        else:
 | 
			
		||||
            display_name = "{} Bot".format(display_name)
 | 
			
		||||
        self.display_name = display_name
 | 
			
		||||
 | 
			
		||||
        if doc is None:
 | 
			
		||||
            doc = self.DEFAULT_DOC_PATH.format(name=name)
 | 
			
		||||
        self.doc = doc
 | 
			
		||||
 | 
			
		||||
class EmailIntegration(Integration):
 | 
			
		||||
    def is_enabled(self):
 | 
			
		||||
        # type: () -> bool
 | 
			
		||||
@@ -387,6 +424,12 @@ INTEGRATIONS = {
 | 
			
		||||
                           doc='zerver/integrations/twitter.md'),
 | 
			
		||||
}  # type: Dict[str, Integration]
 | 
			
		||||
 | 
			
		||||
BOT_INTEGRATIONS = [
 | 
			
		||||
    BotIntegration('github_detail', ['version-control', 'bots'],
 | 
			
		||||
                   display_name='GitHub Detail'),
 | 
			
		||||
    BotIntegration('googlesearch', ['bots'], display_name='Google Search'),
 | 
			
		||||
]  # type: List[BotIntegration]
 | 
			
		||||
 | 
			
		||||
HUBOT_LOZENGES = {
 | 
			
		||||
    'assembla': HubotLozenge('assembla', ['project-management', 'version-control']),
 | 
			
		||||
    'bonusly': HubotLozenge('bonusly', ['hr']),
 | 
			
		||||
@@ -403,3 +446,6 @@ HUBOT_LOZENGES = {
 | 
			
		||||
 | 
			
		||||
for integration in WEBHOOK_INTEGRATIONS:
 | 
			
		||||
    INTEGRATIONS[integration.name] = integration
 | 
			
		||||
 | 
			
		||||
for bot_integration in BOT_INTEGRATIONS:
 | 
			
		||||
    INTEGRATIONS[bot_integration.name] = bot_integration
 | 
			
		||||
 
 | 
			
		||||
@@ -85,7 +85,7 @@ def render_markdown_path(markdown_file_path, context=None):
 | 
			
		||||
    if context.get('integrations_dict') is not None:
 | 
			
		||||
        integration_dir = None
 | 
			
		||||
        if markdown_file_path.endswith('doc.md'):
 | 
			
		||||
            integration_dir = markdown_file_path.split('/')[0]
 | 
			
		||||
            integration_dir = os.path.basename(os.path.dirname(markdown_file_path))
 | 
			
		||||
        elif 'integrations' in markdown_file_path.split('/'):
 | 
			
		||||
            integration_dir = os.path.splitext(os.path.basename(markdown_file_path))[0]
 | 
			
		||||
 | 
			
		||||
@@ -93,7 +93,8 @@ def render_markdown_path(markdown_file_path, context=None):
 | 
			
		||||
 | 
			
		||||
        context['integration_name'] = integration.name
 | 
			
		||||
        context['integration_display_name'] = integration.display_name
 | 
			
		||||
        context['recommended_stream_name'] = integration.stream_name
 | 
			
		||||
        if hasattr(integration, 'stream_name'):
 | 
			
		||||
            context['recommended_stream_name'] = integration.stream_name
 | 
			
		||||
        if hasattr(integration, 'url'):
 | 
			
		||||
            context['integration_url'] = integration.url[3:]
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -71,6 +71,7 @@ class DocPageTest(ZulipTestCase):
 | 
			
		||||
                       'IFTTT'
 | 
			
		||||
                   ])
 | 
			
		||||
        self._test('/integrations/doc-html/travis', 'Your Travis CI notifications may look like:')
 | 
			
		||||
        self._test('/integrations/doc-html/googlesearch', 'This bot allows users to do Google search queries')
 | 
			
		||||
        self._test('/devlogin/', 'Normal users', landing_page=False)
 | 
			
		||||
        self._test('/devtools/', 'Useful development URLs')
 | 
			
		||||
        self._test('/errors/404/', 'Page not found')
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user