Ejemplo n.º 1
0
    def import_tool(self, project, user, project_name=None, mount_point=None,
                    mount_label=None, user_name=None, **kw):
        """ Import a GitHub repo into a new Git Allura tool.

        """
        project_name = "%s/%s" % (user_name, project_name)
        extractor = GitHubProjectExtractor(project_name, user=user)
        repo_url = extractor.get_repo_url()
        app = project.install_app(
            "Git",
            mount_point=mount_point or 'code',
            mount_label=mount_label or 'Code',
            init_from_url=repo_url,
            import_id={
                'source': self.source,
                'project_name': project_name,
            }
        )
        M.AuditLog.log(
            'import tool %s from %s on %s' % (
                app.config.options.mount_point,
                project_name, self.source,
            ), project=project, user=user, url=app.url)
        g.post_event('project_updated')
        return app
Ejemplo n.º 2
0
    def import_tool(self,
                    project,
                    user,
                    project_name=None,
                    mount_point=None,
                    mount_label=None,
                    user_name=None,
                    **kw):
        """ Import a GitHub repo into a new Git Allura tool.

        """
        project_name = "%s/%s" % (user_name, project_name)
        extractor = GitHubProjectExtractor(project_name, user=user)
        repo_url = extractor.get_repo_url()
        app = project.install_app("Git",
                                  mount_point=mount_point or 'code',
                                  mount_label=mount_label or 'Code',
                                  init_from_url=repo_url,
                                  import_id={
                                      'source': self.source,
                                      'project_name': project_name,
                                  })
        M.AuditLog.log('import tool %s from %s on %s' % (
            app.config.options.mount_point,
            project_name,
            self.source,
        ),
                       project=project,
                       user=user,
                       url=app.url)
        g.post_event('project_updated')
        return app
Ejemplo n.º 3
0
    def import_tool(
            self, project, user, project_name=None, mount_point=None,
            mount_label=None, user_name=None, tool_option=None, **kw):
        """ Import a GitHub wiki into a new Wiki Allura tool.

        """
        project_name = "%s/%s" % (user_name, project_name)
        extractor = GitHubProjectExtractor(project_name, user=user)
        wiki_avail = extractor.has_wiki()
        if not wiki_avail:
            return

        self.github_wiki_url = extractor.get_page_url(
            'wiki_url').replace('.wiki', '/wiki')
        self.app = project.install_app(
            "Wiki",
            mount_point=mount_point or 'wiki',
            mount_label=mount_label or 'Wiki',
            import_id={
                'source': self.source,
                'project_name': project_name,
            }
        )
        with_history = tool_option == 'import_history'
        ThreadLocalORMSession.flush_all()
        self.github_markdown_converter = GitHubMarkdownConverter(
            user_name, project_name)
        try:
            M.session.artifact_orm_session._get().skip_mod_date = True
            with h.push_config(c, app=self.app):
                try:
                    wiki_url = extractor.get_page_url('wiki_url')
                    self.import_pages(wiki_url, history=with_history)
                except git.GitCommandError:
                    log.error(
                        'Unable to clone GitHub wiki: '
                        'wiki_url=%s; '
                        'wiki_avail=%s; '
                        'avail_url=%s',
                        wiki_url, wiki_avail,
                        extractor.get_page_url('project_info'),
                        exc_info=True)
                    raise
            ThreadLocalORMSession.flush_all()
            M.AuditLog.log(
                'import tool %s from %s on %s' % (
                    self.app.config.options.mount_point,
                    project_name,
                    self.source),
                project=project,
                user=user,
                url=self.app.url)
            g.post_event('project_updated')
            return self.app
        except Exception:
            h.make_app_admin_only(self.app)
            raise
        finally:
            M.session.artifact_orm_session._get().skip_mod_date = False
Ejemplo n.º 4
0
def import_project_info(project_name):
    from forgeimporters.github.project import GitHubProjectImporter
    importer = GitHubProjectImporter(None)
    with ImportErrorHandler(importer, project_name, c.project) as handler:
        extractor = GitHubProjectExtractor(project_name, user=c.user)
        c.project.summary = extractor.get_summary()
        c.project.external_homepage = extractor.get_homepage()
        ThreadLocalORMSession.flush_all()
        g.post_event('project_updated')
Ejemplo n.º 5
0
 def import_tool(self,
                 project,
                 user,
                 project_name,
                 mount_point=None,
                 mount_label=None,
                 **kw):
     import_id_converter = ImportIdConverter.get()
     project_name = '%s/%s' % (kw['user_name'], project_name)
     extractor = GitHubProjectExtractor(project_name, user=user)
     if not extractor.has_tracker():
         return
     app = project.install_app('tickets',
                               mount_point,
                               mount_label,
                               EnableVoting=False,
                               open_status_names='open',
                               closed_status_names='closed',
                               import_id={
                                   'source': self.source,
                                   'project_name': project_name,
                               })
     self.github_markdown_converter = GitHubMarkdownConverter(
         kw['user_name'], project_name)
     ThreadLocalORMSession.flush_all()
     try:
         M.session.artifact_orm_session._get().skip_mod_date = True
         with h.push_config(c, user=M.User.anonymous(), app=app):
             for ticket_num, issue in extractor.iter_issues():
                 self.max_ticket_num = max(ticket_num, self.max_ticket_num)
                 ticket = TM.Ticket(app_config_id=app.config._id,
                                    custom_fields=dict(),
                                    ticket_num=ticket_num,
                                    import_id=import_id_converter.expand(
                                        ticket_num, app))
                 self.process_fields(extractor, ticket, issue)
                 self.process_comments(extractor, ticket, issue)
                 self.process_events(extractor, ticket, issue)
                 self.process_milestones(ticket, issue)
                 session(ticket).flush(ticket)
                 session(ticket).expunge(ticket)
             app.globals.custom_fields = self.postprocess_milestones()
             app.globals.last_ticket_num = self.max_ticket_num
             ThreadLocalORMSession.flush_all()
         M.AuditLog.log(
             'import tool %s from %s on %s' %
             (app.config.options.mount_point, project_name, self.source),
             project=project,
             user=user,
             url=app.url)
         g.post_event('project_updated')
         app.globals.invalidate_bin_counts()
         return app
     finally:
         M.session.artifact_orm_session._get().skip_mod_date = False
Ejemplo n.º 6
0
 def import_tool(self, project, user, project_name, mount_point=None,
                 mount_label=None, **kw):
     import_id_converter = ImportIdConverter.get()
     project_name = '%s/%s' % (kw['user_name'], project_name)
     extractor = GitHubProjectExtractor(project_name, user=user)
     if not extractor.has_tracker():
         return
     app = project.install_app('tickets', mount_point, mount_label,
                               EnableVoting=False,
                               open_status_names='open',
                               closed_status_names='closed',
                               import_id={
                                   'source': self.source,
                                   'project_name': project_name,
                               }
                               )
     self.github_markdown_converter = GitHubMarkdownConverter(
         kw['user_name'], project_name)
     ThreadLocalORMSession.flush_all()
     try:
         M.session.artifact_orm_session._get().skip_mod_date = True
         with h.push_config(c, user=M.User.anonymous(), app=app):
             for ticket_num, issue in extractor.iter_issues():
                 self.max_ticket_num = max(ticket_num, self.max_ticket_num)
                 ticket = TM.Ticket(
                     app_config_id=app.config._id,
                     custom_fields=dict(),
                     ticket_num=ticket_num,
                     import_id=import_id_converter.expand(ticket_num, app)
                 )
                 self.process_fields(extractor, ticket, issue)
                 self.process_comments(extractor, ticket, issue)
                 self.process_events(extractor, ticket, issue)
                 self.process_milestones(ticket, issue)
                 session(ticket).flush(ticket)
                 session(ticket).expunge(ticket)
             app.globals.custom_fields = self.postprocess_milestones()
             app.globals.last_ticket_num = self.max_ticket_num
             ThreadLocalORMSession.flush_all()
         M.AuditLog.log(
             'import tool %s from %s on %s' % (
                 app.config.options.mount_point,
                 project_name, self.source),
             project=project, user=user, url=app.url)
         g.post_event('project_updated')
         app.globals.invalidate_bin_counts()
         return app
     finally:
         M.session.artifact_orm_session._get().skip_mod_date = False
Ejemplo n.º 7
0
    def import_tool(self,
                    project,
                    user,
                    project_name=None,
                    mount_point=None,
                    mount_label=None,
                    user_name=None,
                    tool_option=None,
                    **kw):
        """ Import a GitHub wiki into a new Wiki Allura tool.

        """
        project_name = "%s/%s" % (user_name, project_name)
        extractor = GitHubProjectExtractor(project_name)
        if not extractor.has_wiki():
            return

        self.github_wiki_url = extractor.get_page_url('wiki_url').replace(
            '.wiki', '/wiki')
        self.app = project.install_app("Wiki",
                                       mount_point=mount_point or 'wiki',
                                       mount_label=mount_label or 'Wiki',
                                       import_id={
                                           'source': self.source,
                                           'project_name': project_name,
                                       })
        with_history = tool_option == 'import_history'
        ThreadLocalORMSession.flush_all()
        try:
            M.session.artifact_orm_session._get().skip_mod_date = True
            with h.push_config(c, app=self.app):
                self.import_pages(extractor.get_page_url('wiki_url'),
                                  history=with_history)
            ThreadLocalORMSession.flush_all()
            M.AuditLog.log('import tool %s from %s on %s' %
                           (self.app.config.options.mount_point, project_name,
                            self.source),
                           project=project,
                           user=user,
                           url=self.app.url)
            g.post_event('project_updated')
            return self.app
        except Exception as e:
            h.make_app_admin_only(self.app)
            raise
        finally:
            M.session.artifact_orm_session._get().skip_mod_date = False
Ejemplo n.º 8
0
    def import_tool(
        self,
        project,
        user,
        project_name=None,
        mount_point=None,
        mount_label=None,
        user_name=None,
        tool_option=None,
        **kw
    ):
        """ Import a GitHub wiki into a new Wiki Allura tool.

        """
        project_name = "%s/%s" % (user_name, project_name)
        extractor = GitHubProjectExtractor(project_name, user=user)
        if not extractor.has_wiki():
            return

        self.github_wiki_url = extractor.get_page_url("wiki_url").replace(".wiki", "/wiki")
        self.app = project.install_app(
            "Wiki",
            mount_point=mount_point or "wiki",
            mount_label=mount_label or "Wiki",
            import_id={"source": self.source, "project_name": project_name},
        )
        with_history = tool_option == "import_history"
        ThreadLocalORMSession.flush_all()
        self.github_markdown_converter = GitHubMarkdownConverter(user_name, project_name)
        try:
            M.session.artifact_orm_session._get().skip_mod_date = True
            with h.push_config(c, app=self.app):
                self.import_pages(extractor.get_page_url("wiki_url"), history=with_history)
            ThreadLocalORMSession.flush_all()
            M.AuditLog.log(
                "import tool %s from %s on %s" % (self.app.config.options.mount_point, project_name, self.source),
                project=project,
                user=user,
                url=self.app.url,
            )
            g.post_event("project_updated")
            return self.app
        except Exception as e:
            h.make_app_admin_only(self.app)
            raise
        finally:
            M.session.artifact_orm_session._get().skip_mod_date = False
Ejemplo n.º 9
0
    def import_tool(self, project, user, project_name=None, mount_point=None, mount_label=None, user_name=None,
                    tool_option=None, **kw):
        """ Import a GitHub wiki into a new Wiki Allura tool.

        """
        project_name = "%s/%s" % (user_name, project_name)
        extractor = GitHubProjectExtractor(project_name)
        if not extractor.has_wiki():
            return

        self.github_wiki_url = extractor.get_page_url('wiki_url').replace('.wiki', '/wiki')
        self.app = project.install_app(
            "Wiki",
            mount_point=mount_point or 'wiki',
            mount_label=mount_label or 'Wiki',
            import_id={
                'source': self.source,
                'project_name': project_name,
            }
        )
        with_history = tool_option == 'import_history'
        ThreadLocalORMSession.flush_all()
        try:
            M.session.artifact_orm_session._get().skip_mod_date = True
            with h.push_config(c, app=self.app):
                self.import_pages(extractor.get_page_url('wiki_url'), history=with_history)
            ThreadLocalORMSession.flush_all()
            M.AuditLog.log(
                'import tool %s from %s on %s' % (
                    self.app.config.options.mount_point,
                    project_name,
                    self.source),
                project=project,
                user=user,
                url=self.app.url)
            g.post_event('project_updated')
            return self.app
        except Exception as e:
            h.make_app_admin_only(self.app)
            raise
        finally:
            M.session.artifact_orm_session._get().skip_mod_date = False
Ejemplo n.º 10
0
    def import_tool(self,
                    project,
                    user,
                    project_name=None,
                    mount_point=None,
                    mount_label=None,
                    user_name=None,
                    tool_option=None,
                    **kw):
        """ Import a GitHub wiki into a new Wiki Allura tool.

        """
        project_name = "%s/%s" % (user_name, project_name)
        extractor = GitHubProjectExtractor(project_name, user=user)
        wiki_avail = extractor.has_wiki()
        # has_wiki only indicates that wiki is enabled, but it does not mean
        # that it has any pages, so we should check if wiki repo actually
        # exists
        wiki_url = extractor.get_page_url('wiki_url')
        if not wiki_avail or not self.has_wiki_repo(wiki_url):
            return

        self.github_wiki_url = extractor.get_page_url('wiki_url').replace(
            '.wiki', '/wiki')
        self.app = project.install_app("Wiki",
                                       mount_point=mount_point or 'wiki',
                                       mount_label=mount_label or 'Wiki',
                                       import_id={
                                           'source': self.source,
                                           'project_name': project_name,
                                       })
        with_history = tool_option == 'import_history'
        ThreadLocalORMSession.flush_all()
        self.github_markdown_converter = GitHubMarkdownConverter(
            user_name, project_name)
        try:
            M.session.artifact_orm_session._get().skip_mod_date = True
            with h.push_config(c, app=self.app):
                try:
                    self.import_pages(wiki_url, history=with_history)
                except git.GitCommandError:
                    log.error(
                        'Unable to clone GitHub wiki: '
                        'wiki_url=%s; '
                        'wiki_avail=%s; '
                        'avail_url=%s',
                        wiki_url,
                        wiki_avail,
                        extractor.get_page_url('project_info'),
                        exc_info=True)
                    raise
            ThreadLocalORMSession.flush_all()
            M.AuditLog.log('import tool %s from %s on %s' %
                           (self.app.config.options.mount_point, project_name,
                            self.source),
                           project=project,
                           user=user,
                           url=self.app.url)
            g.post_event('project_updated')
            return self.app
        except Exception:
            h.make_app_admin_only(self.app)
            raise
        finally:
            M.session.artifact_orm_session._get().skip_mod_date = False
Ejemplo n.º 11
0
    def import_tool(
        self,
        project,
        user,
        project_name=None,
        mount_point=None,
        mount_label=None,
        user_name=None,
        tool_option=None,
        **kw
    ):
        """ Import a GitHub wiki into a new Wiki Allura tool.

        """
        project_name = "%s/%s" % (user_name, project_name)
        extractor = GitHubProjectExtractor(project_name, user=user)
        wiki_avail = extractor.has_wiki()
        # has_wiki only indicates that wiki is enabled, but it does not mean
        # that it has any pages, so we should check if wiki repo actually
        # exists
        wiki_url = extractor.get_page_url("wiki_url")
        if not wiki_avail or not self.has_wiki_repo(wiki_url):
            return

        self.github_wiki_url = extractor.get_page_url("wiki_url").replace(".wiki", "/wiki")
        self.app = project.install_app(
            "Wiki",
            mount_point=mount_point or "wiki",
            mount_label=mount_label or "Wiki",
            import_id={"source": self.source, "project_name": project_name},
        )
        with_history = tool_option == "import_history"
        ThreadLocalORMSession.flush_all()
        self.github_markdown_converter = GitHubMarkdownConverter(user_name, project_name)
        try:
            M.session.artifact_orm_session._get().skip_mod_date = True
            with h.push_config(c, app=self.app):
                try:
                    self.import_pages(wiki_url, history=with_history)
                except git.GitCommandError:
                    log.error(
                        "Unable to clone GitHub wiki: " "wiki_url=%s; " "wiki_avail=%s; " "avail_url=%s",
                        wiki_url,
                        wiki_avail,
                        extractor.get_page_url("project_info"),
                        exc_info=True,
                    )
                    raise
            ThreadLocalORMSession.flush_all()
            M.AuditLog.log(
                "import tool %s from %s on %s" % (self.app.config.options.mount_point, project_name, self.source),
                project=project,
                user=user,
                url=self.app.url,
            )
            g.post_event("project_updated")
            return self.app
        except Exception:
            h.make_app_admin_only(self.app)
            raise
        finally:
            M.session.artifact_orm_session._get().skip_mod_date = False