You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/09/19 17:31:59 UTC
[17/23] git commit: [#6535] ticket:425 Import tracker into existing
project
[#6535] ticket:425 Import tracker into existing project
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/a2833b3b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/a2833b3b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/a2833b3b
Branch: refs/heads/master
Commit: a2833b3ba8a4eb27cd13b29ac7672cbb1822d855
Parents: aefd7c9
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Sep 16 15:37:50 2013 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Sep 19 14:46:51 2013 +0000
----------------------------------------------------------------------
.../github/templates/tracker/index.html | 36 ++++++++++++
.../forgeimporters/github/tests/test_tracker.py | 54 ++++++++++++++++++
ForgeImporters/forgeimporters/github/tracker.py | 58 +++++++++++++++++++-
3 files changed, 147 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a2833b3b/ForgeImporters/forgeimporters/github/templates/tracker/index.html
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/templates/tracker/index.html b/ForgeImporters/forgeimporters/github/templates/tracker/index.html
new file mode 100644
index 0000000..6536628
--- /dev/null
+++ b/ForgeImporters/forgeimporters/github/templates/tracker/index.html
@@ -0,0 +1,36 @@
+{#-
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-#}
+{% extends 'forgeimporters:templates/importer_base.html' %}
+
+{% block title %}
+{{c.project.name}} / Import your tickets from GitHub
+{% endblock %}
+
+{% block importer_fields %}
+<div>
+ <label for="gh_user_name">GitHub User Name</label>
+ <input name="gh_user_name" value="{{ c.form_values['gh_user_name'] }}" />
+ {{ error('gh_user_name') }}
+</div>
+<div>
+ <label for="gh_project_name">GitHub Project Name</label>
+ <input name="gh_project_name" value="{{ c.form_values['gh_project_name'] }}" />
+ {{ error('gh_project_name') }}
+</div>
+{% endblock %}
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a2833b3b/ForgeImporters/forgeimporters/github/tests/test_tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_tracker.py b/ForgeImporters/forgeimporters/github/tests/test_tracker.py
new file mode 100644
index 0000000..ed20581
--- /dev/null
+++ b/ForgeImporters/forgeimporters/github/tests/test_tracker.py
@@ -0,0 +1,54 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from unittest import TestCase
+from mock import patch
+
+from allura.tests import TestController
+from allura.tests.decorators import with_tool
+
+# important to be distinct from 'test' which ForgeTracker uses, so that the tests can run in parallel and not clobber each other
+test_project_with_tracker = 'test2'
+with_tracker = with_tool(test_project_with_tracker, 'tickets', 'spooky-issues', 'tickets')
+
+
+class TestGitHubTrackerImportController(TestController, TestCase):
+
+ url = '/p/%s/admin/ext/import/github-tracker/' % test_project_with_tracker
+
+ @with_tracker
+ def test_index(self):
+ r = self.app.get(self.url)
+ self.assertIsNotNone(r.html.find(attrs=dict(name='gh_user_name')))
+ self.assertIsNotNone(r.html.find(attrs=dict(name='gh_project_name')))
+ self.assertIsNotNone(r.html.find(attrs=dict(name='mount_label')))
+ self.assertIsNotNone(r.html.find(attrs=dict(name='mount_point')))
+
+ @with_tracker
+ @patch('forgeimporters.github.tracker.import_tool')
+ def test_create(self, import_tool):
+ params = dict(
+ gh_user_name='spooky',
+ gh_project_name='mulder',
+ mount_point='issues',
+ mount_label='Issues')
+ r = self.app.post(self.url + 'create', params, status=302)
+ self.assertEqual(r.location, 'http://localhost/p/%s/admin/' % test_project_with_tracker)
+ self.assertEqual(u'Issues', import_tool.post.call_args[1]['mount_label'])
+ self.assertEqual(u'issues', import_tool.post.call_args[1]['mount_point'])
+ self.assertEqual(u'mulder', import_tool.post.call_args[1]['project_name'])
+ self.assertEqual(u'spooky', import_tool.post.call_args[1]['user_name'])
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a2833b3b/ForgeImporters/forgeimporters/github/tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tracker.py b/ForgeImporters/forgeimporters/github/tracker.py
index ec9729f..20ba465 100644
--- a/ForgeImporters/forgeimporters/github/tracker.py
+++ b/ForgeImporters/forgeimporters/github/tracker.py
@@ -6,8 +6,22 @@ try:
except ImportError:
from StringIO import StringIO
+from formencode import validators as fev
+from tg import (
+ expose,
+ validate,
+ flash,
+ redirect
+ )
+from tg.decorators import (
+ with_trailing_slash,
+ without_trailing_slash
+ )
+
from allura import model as M
+from allura.controllers import BaseController
from allura.lib import helpers as h
+from allura.lib.decorators import require_post, task
from ming.orm import session, ThreadLocalORMSession
from pylons import tmpl_context as c
from pylons import app_globals as g
@@ -16,13 +30,55 @@ from . import GitHubProjectExtractor
from ..base import ToolImporter
from forgetracker.tracker_main import ForgeTrackerApp
from forgetracker import model as TM
+from forgeimporters.base import ToolImportForm, ImportErrorHandler
+
+
+@task(notifications_disabled=True)
+def import_tool(**kw):
+ importer = GitHubTrackerImporter()
+ with ImportErrorHandler(importer, kw.get('project_name')):
+ importer.import_tool(c.project, c.user, **kw)
+
+class GitHubTrackerImportForm(ToolImportForm):
+ gh_project_name = fev.UnicodeString(not_empty=True)
+ gh_user_name = fev.UnicodeString(not_empty=True)
+
+
+class GitHubTrackerImportController(BaseController):
+
+ def __init__(self):
+ self.importer = GitHubTrackerImporter()
+
+ @property
+ def target_app(self):
+ return self.importer.target_app
+
+ @with_trailing_slash
+ @expose('jinja:forgeimporters.github:templates/tracker/index.html')
+ def index(self, **kw):
+ return dict(importer=self.importer,
+ target_app=self.target_app)
+
+ @without_trailing_slash
+ @expose()
+ @require_post()
+ @validate(GitHubTrackerImportForm(ForgeTrackerApp), error_handler=index)
+ def create(self, gh_project_name, gh_user_name, mount_point, mount_label, **kw):
+ import_tool.post(
+ project_name=gh_project_name,
+ user_name=gh_user_name,
+ mount_point=mount_point,
+ mount_label=mount_label)
+ flash('Ticket import has begun. Your new tracker will be available '
+ 'when the import is complete.')
+ redirect(c.project.url() + 'admin/')
class GitHubTrackerImporter(ToolImporter):
source = 'GitHub'
target_app = ForgeTrackerApp
- controller = None
+ controller = GitHubTrackerImportController
tool_label = 'Issues'
max_ticket_num = 0
open_milestones = set()