You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/08/23 18:01:48 UTC
[1/8] git commit: [#6531] ticket:413 Remove github username from
project name
Updated Branches:
refs/heads/tv/6531 [created] 2c578f5fc
[#6531] ticket:413 Remove github username from project name
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/3c58dc97
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/3c58dc97
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/3c58dc97
Branch: refs/heads/tv/6531
Commit: 3c58dc9759285f3fca9aa7781ba62439289ddf17
Parents: c98e7c6
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Thu Aug 22 15:22:55 2013 +0400
Committer: Yuriy Arhipov <yu...@yandex.ru>
Committed: Thu Aug 22 17:59:25 2013 +0400
----------------------------------------------------------------------
ForgeImporters/forgeimporters/github/project.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3c58dc97/ForgeImporters/forgeimporters/github/project.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/project.py b/ForgeImporters/forgeimporters/github/project.py
index 4af2bdf..58485a7 100644
--- a/ForgeImporters/forgeimporters/github/project.py
+++ b/ForgeImporters/forgeimporters/github/project.py
@@ -45,7 +45,8 @@ class GitHubProjectImporter(base.ProjectImporter):
def after_project_create(self, project, **kw):
project.set_tool_data('github', project_name=project.name)
- tasks.import_project_info.post(project.name)
+ project_name = '%s/%s' % (kw['user_name'], kw['project_name'])
+ tasks.import_project_info.post(project_name)
@with_trailing_slash
@expose(index_template)
@@ -56,7 +57,6 @@ class GitHubProjectImporter(base.ProjectImporter):
@expose()
@validate(process_validator)
def process(self, **kw):
- kw['project_name'] = '%s/%s' % (kw['user_name'], kw['project_name'])
kw['tools'] = ''
return super(self.__class__, self).process(**kw)
[2/8] git commit: [#6531] ticket:413 Project metadata importer for
github
Posted by tv...@apache.org.
[#6531] ticket:413 Project metadata importer for github
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/c98e7c60
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/c98e7c60
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/c98e7c60
Branch: refs/heads/tv/6531
Commit: c98e7c60d91a2aa7f070fe517e087e4a9a9811d8
Parents: 71176e6
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Tue Aug 20 13:18:20 2013 +0400
Committer: Yuriy Arhipov <yu...@yandex.ru>
Committed: Thu Aug 22 17:59:25 2013 +0400
----------------------------------------------------------------------
.../forgeimporters/github/__init__.py | 43 +++++++++++++
ForgeImporters/forgeimporters/github/project.py | 66 ++++++++++++++++++++
ForgeImporters/forgeimporters/github/tasks.py | 31 +++++++++
.../github/templates/project.html | 55 ++++++++++++++++
.../forgeimporters/tests/github/__init__.py | 17 +++++
.../tests/github/functional/__init__.py | 17 +++++
.../tests/github/functional/test_github.py | 28 +++++++++
.../tests/github/test_extractor.py | 48 ++++++++++++++
.../forgeimporters/tests/github/test_tasks.py | 31 +++++++++
ForgeImporters/setup.py | 1 +
10 files changed, 337 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c98e7c60/ForgeImporters/forgeimporters/github/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/__init__.py b/ForgeImporters/forgeimporters/github/__init__.py
new file mode 100644
index 0000000..472429e
--- /dev/null
+++ b/ForgeImporters/forgeimporters/github/__init__.py
@@ -0,0 +1,43 @@
+# 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.
+
+import re
+import urllib
+import urllib2
+import json
+try:
+ from cStringIO import StringIO
+except ImportError:
+ from StringIO import StringIO
+import logging
+
+log = logging.getLogger(__name__)
+
+class GitHubProjectExtractor(object):
+ RE_REPO_TYPE = re.compile(r'(svn|hg|git)')
+ PAGE_MAP = {
+ 'project_info': 'https://api.github.com/repos/%s',
+ }
+
+
+ def __init__(self, allura_project, gh_project_name, page):
+ self.project = allura_project
+ self.url = self.PAGE_MAP[page] % urllib.quote(gh_project_name)
+ self.page = json.loads(urllib2.urlopen(self.url).read().decode('utf8'))
+
+ def get_summmary(self):
+ self.project.summary = self.page['description']
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c98e7c60/ForgeImporters/forgeimporters/github/project.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/project.py b/ForgeImporters/forgeimporters/github/project.py
new file mode 100644
index 0000000..4af2bdf
--- /dev/null
+++ b/ForgeImporters/forgeimporters/github/project.py
@@ -0,0 +1,66 @@
+# 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.
+
+import logging
+
+from formencode import validators as fev
+
+from tg import expose, validate
+from tg.decorators import with_trailing_slash
+
+from allura.lib.decorators import require_post
+
+from .. import base
+from . import tasks
+
+
+log = logging.getLogger(__name__)
+
+class GitHubProjectForm(base.ProjectImportForm):
+ project_name = fev.Regex(r'^[a-z0-9][a-z0-9-]{,61}$',
+ not_empty=True,
+ messages={
+ 'invalid': 'Please use only letters, numbers, and dashes.',
+ })
+
+class GitHubProjectImporter(base.ProjectImporter):
+
+ source = 'GitHub'
+ index_template = 'jinja:forgeimporters.github:templates/project.html'
+ process_validator = GitHubProjectForm(source)
+
+ def after_project_create(self, project, **kw):
+ project.set_tool_data('github', project_name=project.name)
+ tasks.import_project_info.post(project.name)
+
+ @with_trailing_slash
+ @expose(index_template)
+ def index(self, **kw):
+ return super(self.__class__, self).index(**kw)
+
+ @require_post()
+ @expose()
+ @validate(process_validator)
+ def process(self, **kw):
+ kw['project_name'] = '%s/%s' % (kw['user_name'], kw['project_name'])
+ kw['tools'] = ''
+ return super(self.__class__, self).process(**kw)
+
+ @expose('json:')
+ @validate(process_validator)
+ def check_names(self, **kw):
+ return super(self.__class__, self).check_names(**kw)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c98e7c60/ForgeImporters/forgeimporters/github/tasks.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tasks.py b/ForgeImporters/forgeimporters/github/tasks.py
new file mode 100644
index 0000000..4fd928c
--- /dev/null
+++ b/ForgeImporters/forgeimporters/github/tasks.py
@@ -0,0 +1,31 @@
+# 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 pylons import tmpl_context as c
+
+from ming.orm import ThreadLocalORMSession
+
+from allura.lib.decorators import task
+
+from . import GitHubProjectExtractor
+
+
+@task
+def import_project_info(project_name):
+ extractor = GitHubProjectExtractor(c.project, project_name, 'project_info')
+ extractor.get_summmary()
+ ThreadLocalORMSession.flush_all()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c98e7c60/ForgeImporters/forgeimporters/github/templates/project.html
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/templates/project.html b/ForgeImporters/forgeimporters/github/templates/project.html
new file mode 100644
index 0000000..de42737
--- /dev/null
+++ b/ForgeImporters/forgeimporters/github/templates/project.html
@@ -0,0 +1,55 @@
+{#-
+ 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/project_base.html' %}
+
+{% block project_fields %}
+ <div class="grid-6">
+ <label>GitHub User Name</label>
+ </div>
+ <div class="grid-10">
+ <input id="user_name" name="user_name" value="{{c.form_values['user_name']}}" autofocus/>
+ <div id="user_name_error" class="error{% if not c.form_errors['user_name'] %} hidden{% endif %}">
+ {{c.form_errors['user_name']}}
+ </div>
+ </div>
+
+
+ <div class="grid-6" style="clear:left">
+ <label>GitHub Project Name</label>
+ </div>
+ <div class="grid-10">
+ <input id="project_name" name="project_name" value="{{c.form_values['project_name']}}" autofocus/>
+ <div id="project_name_error" class="error{% if not c.form_errors['project_name'] %} hidden{% endif %}">
+ {{c.form_errors['project_name']}}
+ </div>
+ </div>
+
+ <div class="grid-6" style="clear:left">
+ <label>URL Name</label>
+ </div>
+ <div class="grid-10">
+ <input id="project_shortname" name="project_shortname" value="{{c.form_values['project_shortname']}}"/>
+ <div id="project_shortname_error" class="error{% if not c.form_errors['project_shortname'] %} hidden{% endif %}">
+ {{c.form_errors['project_shortname']}}
+ </div>
+ <div id="project-url">
+ http://{{request.environ['HTTP_HOST']}}{{importer.neighborhood.url()}}<span id="url-fragment">{{c.form_values['project_shortname']}}</span>
+ </div>
+ </div>
+{% endblock %}
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c98e7c60/ForgeImporters/forgeimporters/tests/github/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/__init__.py b/ForgeImporters/forgeimporters/tests/github/__init__.py
new file mode 100644
index 0000000..77505f1
--- /dev/null
+++ b/ForgeImporters/forgeimporters/tests/github/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c98e7c60/ForgeImporters/forgeimporters/tests/github/functional/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/functional/__init__.py b/ForgeImporters/forgeimporters/tests/github/functional/__init__.py
new file mode 100644
index 0000000..77505f1
--- /dev/null
+++ b/ForgeImporters/forgeimporters/tests/github/functional/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c98e7c60/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/functional/test_github.py b/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
new file mode 100644
index 0000000..6667e7b
--- /dev/null
+++ b/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
@@ -0,0 +1,28 @@
+# 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 allura.tests import TestController
+
+class TestGitHubImportController(TestController, TestCase):
+
+ def test_index(self):
+ r = self.app.get('/p/import_project/github/')
+ assert 'GitHub Project Importer' in r
+ assert '<input id="user_name" name="user_name" value="" autofocus/>' in r
+ assert '<input id="project_name" name="project_name" value="" autofocus/>' in r
+ assert '<input id="project_shortname" name="project_shortname" value=""/>' in r
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c98e7c60/ForgeImporters/forgeimporters/tests/github/test_extractor.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/test_extractor.py b/ForgeImporters/forgeimporters/tests/github/test_extractor.py
new file mode 100644
index 0000000..a21f775
--- /dev/null
+++ b/ForgeImporters/forgeimporters/tests/github/test_extractor.py
@@ -0,0 +1,48 @@
+# 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
+
+import mock
+
+from ... import github
+
+
+class TestGitHubProjectExtractor(TestCase):
+ def setUp(self):
+ self._p_urlopen = mock.patch.object(github.urllib2, 'urlopen')
+ self._p_json = mock.patch.object(github.json, 'loads')
+ self.urlopen = self._p_urlopen.start()
+ self.json = self._p_json.start()
+ self.project = mock.Mock(name='project')
+ self.project.get_tool_data.return_value = 'testproject'
+
+ def tearDown(self):
+ self._p_urlopen.stop()
+ self._p_json.stop()
+
+
+ def test_init(self):
+ extractor = github.GitHubProjectExtractor(self.project, 'testproject', 'project_info')
+ self.urlopen.assert_called_once_with('https://api.github.com/repos/testproject')
+ self.assertEqual(extractor.project, self.project)
+
+ def test_get_summary(self):
+ extractor = github.GitHubProjectExtractor(self.project, 'testproject', 'project_info')
+ extractor.page = {'description': 'test summary'}
+ extractor.get_summmary()
+ self.assertEqual(self.project.summary, 'test summary')
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c98e7c60/ForgeImporters/forgeimporters/tests/github/test_tasks.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/test_tasks.py b/ForgeImporters/forgeimporters/tests/github/test_tasks.py
new file mode 100644
index 0000000..b478bc9
--- /dev/null
+++ b/ForgeImporters/forgeimporters/tests/github/test_tasks.py
@@ -0,0 +1,31 @@
+# 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.
+
+import mock
+
+from ...github import tasks
+
+
+@mock.patch.object(tasks, 'GitHubProjectExtractor')
+@mock.patch.object(tasks, 'ThreadLocalORMSession')
+@mock.patch.object(tasks, 'c')
+def test_import_project_info(c, session, ghpe):
+ c.project = mock.Mock(name='project')
+ tasks.import_project_info('my-project')
+ ghpe.assert_called_once_with(c.project, 'my-project', 'project_info')
+ ghpe.return_value.get_summmary.assert_called_once_with()
+ session.flush_all.assert_called_once_with()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c98e7c60/ForgeImporters/setup.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/setup.py b/ForgeImporters/setup.py
index b19fd17..cec76b4 100644
--- a/ForgeImporters/setup.py
+++ b/ForgeImporters/setup.py
@@ -36,6 +36,7 @@ setup(name='ForgeImporters',
[allura.project_importers]
google-code = forgeimporters.google.project:GoogleCodeProjectImporter
trac = forgeimporters.trac.project:TracProjectImporter
+ github = forgeimporters.github.project:GitHubProjectImporter
[allura.importers]
google-code-tracker = forgeimporters.google.tracker:GoogleCodeTrackerImporter
[3/8] git commit: [#6531] ticket:413 homepage import from allura
Posted by tv...@apache.org.
[#6531] ticket:413 homepage import from allura
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/796dcd3a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/796dcd3a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/796dcd3a
Branch: refs/heads/tv/6531
Commit: 796dcd3a45a5e019c5338d0ee4c137f5de191931
Parents: 3c58dc9
Author: Anton Kasyanov <mi...@gmail.com>
Authored: Thu Aug 22 18:05:09 2013 +0300
Committer: Anton Kasyanov <mi...@gmail.com>
Committed: Thu Aug 22 18:05:09 2013 +0300
----------------------------------------------------------------------
ForgeImporters/forgeimporters/github/__init__.py | 3 +++
ForgeImporters/forgeimporters/github/tasks.py | 1 +
2 files changed, 4 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/796dcd3a/ForgeImporters/forgeimporters/github/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/__init__.py b/ForgeImporters/forgeimporters/github/__init__.py
index 472429e..1ce4398 100644
--- a/ForgeImporters/forgeimporters/github/__init__.py
+++ b/ForgeImporters/forgeimporters/github/__init__.py
@@ -41,3 +41,6 @@ class GitHubProjectExtractor(object):
def get_summmary(self):
self.project.summary = self.page['description']
+
+ def get_homepage(self):
+ self.project.external_homepage = self.page['homepage']
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/796dcd3a/ForgeImporters/forgeimporters/github/tasks.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tasks.py b/ForgeImporters/forgeimporters/github/tasks.py
index 4fd928c..be2325d 100644
--- a/ForgeImporters/forgeimporters/github/tasks.py
+++ b/ForgeImporters/forgeimporters/github/tasks.py
@@ -28,4 +28,5 @@ from . import GitHubProjectExtractor
def import_project_info(project_name):
extractor = GitHubProjectExtractor(c.project, project_name, 'project_info')
extractor.get_summmary()
+ extractor.get_homepage()
ThreadLocalORMSession.flush_all()
[8/8] git commit: [#6531] Refactored more stuff up into
ProjectExtractor
Posted by tv...@apache.org.
[#6531] Refactored more stuff up into ProjectExtractor
Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/2c578f5f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/2c578f5f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/2c578f5f
Branch: refs/heads/tv/6531
Commit: 2c578f5fc62bced30952bbe707e3b6cece67faeb
Parents: 3b71d0f
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Fri Aug 23 16:01:29 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Fri Aug 23 16:01:29 2013 +0000
----------------------------------------------------------------------
ForgeImporters/forgeimporters/base.py | 59 ++++++++++++++++++++
.../forgeimporters/github/__init__.py | 30 ++++------
ForgeImporters/forgeimporters/github/tasks.py | 8 ++-
.../github/templates/project.html | 3 +-
.../forgeimporters/google/__init__.py | 39 -------------
.../tests/github/functional/test_github.py | 2 +-
.../tests/github/test_extractor.py | 32 ++++-------
.../forgeimporters/tests/github/test_tasks.py | 5 +-
.../tests/google/test_extractor.py | 3 +-
9 files changed, 92 insertions(+), 89 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2c578f5f/ForgeImporters/forgeimporters/base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/base.py b/ForgeImporters/forgeimporters/base.py
index 49397a5..3cf6774 100644
--- a/ForgeImporters/forgeimporters/base.py
+++ b/ForgeImporters/forgeimporters/base.py
@@ -16,10 +16,12 @@
# under the License.
import logging
+import urllib
import urllib2
from pkg_resources import iter_entry_points
+from BeautifulSoup import BeautifulSoup
from tg import expose, validate, flash, redirect, config
from tg.decorators import with_trailing_slash
from pylons import tmpl_context as c
@@ -67,12 +69,69 @@ class ProjectExtractor(object):
a custom User-Agent and automatically retries timed-out requests.
"""
+
+ PAGE_MAP = {}
+
+ def __init__(self, project_name, page_name=None, **kw):
+ self.project_name = project_name
+ self._page_cache = {}
+ self.url = None
+ self.page = None
+ if page_name:
+ self.get_page(page_name, **kw)
+
@staticmethod
def urlopen(url, retries=3, codes=(408,), **kw):
req = urllib2.Request(url, **kw)
req.add_header('User-Agent', 'Allura Data Importer (http://sf.net/p/allura)')
return h.urlopen(req, retries=retries, codes=codes)
+ def get_page(self, page_name_or_url, **kw):
+ """Return a Beautiful soup object for the given page name or url.
+
+ If a page name is provided, the associated url is looked up in
+ :attr:`PAGE_MAP`.
+
+ Results are cached so that subsequent calls for the same page name or
+ url will return the cached result rather than making another HTTP
+ request.
+
+ """
+ if page_name_or_url in self.PAGE_MAP:
+ self.url = self.get_page_url(page_name_or_url, **kw)
+ else:
+ self.url = page_name_or_url
+ if self.url in self._page_cache:
+ self.page = self._page_cache[self.url]
+ else:
+ self.page = self._page_cache[self.url] = \
+ self.parse_page(self.urlopen(self.url))
+ return self.page
+
+ def get_page_url(self, page_name, **kw):
+ """Return the url associated with ``page_name``.
+
+ Raises KeyError if ``page_name`` is not in :attr:`PAGE_MAP`.
+
+ """
+ return self.PAGE_MAP[page_name].format(
+ project_name = urllib.quote(self.project_name), **kw)
+
+ def parse_page(self, page):
+ """Transforms the result of a `urlopen` call before returning it from
+ :meth:`get_page`.
+
+ The default implementation create a :class:`BeautifulSoup` object from
+ the html.
+
+ Subclasses can override to change the behavior or handle other types
+ of content (like JSON).
+
+ :param page: A file-like object return from :meth:`urlopen`
+
+ """
+ return BeautifulSoup(page)
+
class ProjectImporter(BaseController):
"""
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2c578f5f/ForgeImporters/forgeimporters/github/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/__init__.py b/ForgeImporters/forgeimporters/github/__init__.py
index 1ce4398..f08f478 100644
--- a/ForgeImporters/forgeimporters/github/__init__.py
+++ b/ForgeImporters/forgeimporters/github/__init__.py
@@ -15,32 +15,24 @@
# specific language governing permissions and limitations
# under the License.
-import re
-import urllib
-import urllib2
-import json
-try:
- from cStringIO import StringIO
-except ImportError:
- from StringIO import StringIO
import logging
+import json
+
+from forgeimporters import base
log = logging.getLogger(__name__)
-class GitHubProjectExtractor(object):
- RE_REPO_TYPE = re.compile(r'(svn|hg|git)')
+
+class GitHubProjectExtractor(base.ProjectExtractor):
PAGE_MAP = {
- 'project_info': 'https://api.github.com/repos/%s',
+ 'project_info': 'https://api.github.com/repos/{project_name}',
}
+ def parse_page(self, page):
+ return json.loads(page.read().decode('utf8'))
- def __init__(self, allura_project, gh_project_name, page):
- self.project = allura_project
- self.url = self.PAGE_MAP[page] % urllib.quote(gh_project_name)
- self.page = json.loads(urllib2.urlopen(self.url).read().decode('utf8'))
-
- def get_summmary(self):
- self.project.summary = self.page['description']
+ def get_summary(self):
+ return self.get_page('project_info').get('description')
def get_homepage(self):
- self.project.external_homepage = self.page['homepage']
+ return self.get_page('project_info').get('homepage')
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2c578f5f/ForgeImporters/forgeimporters/github/tasks.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tasks.py b/ForgeImporters/forgeimporters/github/tasks.py
index be2325d..588c5a6 100644
--- a/ForgeImporters/forgeimporters/github/tasks.py
+++ b/ForgeImporters/forgeimporters/github/tasks.py
@@ -16,6 +16,7 @@
# under the License.
from pylons import tmpl_context as c
+from pylons import app_globals as g
from ming.orm import ThreadLocalORMSession
@@ -26,7 +27,8 @@ from . import GitHubProjectExtractor
@task
def import_project_info(project_name):
- extractor = GitHubProjectExtractor(c.project, project_name, 'project_info')
- extractor.get_summmary()
- extractor.get_homepage()
+ extractor = GitHubProjectExtractor(project_name)
+ c.project.summary = extractor.get_summary()
+ c.project.external_homepage = extractor.get_homepage()
ThreadLocalORMSession.flush_all()
+ g.post_event('project_updated')
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2c578f5f/ForgeImporters/forgeimporters/github/templates/project.html
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/templates/project.html b/ForgeImporters/forgeimporters/github/templates/project.html
index de42737..d0f59f6 100644
--- a/ForgeImporters/forgeimporters/github/templates/project.html
+++ b/ForgeImporters/forgeimporters/github/templates/project.html
@@ -29,12 +29,11 @@
</div>
</div>
-
<div class="grid-6" style="clear:left">
<label>GitHub Project Name</label>
</div>
<div class="grid-10">
- <input id="project_name" name="project_name" value="{{c.form_values['project_name']}}" autofocus/>
+ <input id="project_name" name="project_name" value="{{c.form_values['project_name']}}" />
<div id="project_name_error" class="error{% if not c.form_errors['project_name'] %} hidden{% endif %}">
{{c.form_errors['project_name']}}
</div>
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2c578f5f/ForgeImporters/forgeimporters/google/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/__init__.py b/ForgeImporters/forgeimporters/google/__init__.py
index 902683a..29e5011 100644
--- a/ForgeImporters/forgeimporters/google/__init__.py
+++ b/ForgeImporters/forgeimporters/google/__init__.py
@@ -78,45 +78,6 @@ class GoogleCodeProjectExtractor(ProjectExtractor):
DEFAULT_ICON = 'http://www.gstatic.com/codesite/ph/images/defaultlogo.png'
- def __init__(self, project_name, page_name=None, **kw):
- self.project_name = project_name
- self._page_cache = {}
- self.url = None
- self.page = None
- if page_name:
- self.get_page(page_name, **kw)
-
- def get_page(self, page_name_or_url, **kw):
- """Return a Beautiful soup object for the given page name or url.
-
- If a page name is provided, the associated url is looked up in
- :attr:`PAGE_MAP`.
-
- Results are cached so that subsequent calls for the same page name or
- url will return the cached result rather than making another HTTP
- request.
-
- """
- if page_name_or_url in self.PAGE_MAP:
- self.url = self.get_page_url(page_name_or_url, **kw)
- else:
- self.url = page_name_or_url
- if self.url in self._page_cache:
- self.page = self._page_cache[self.url]
- else:
- self.page = self._page_cache[self.url] = \
- BeautifulSoup(self.urlopen(self.url))
- return self.page
-
- def get_page_url(self, page_name, **kw):
- """Return the url associated with ``page_name``.
-
- Raises KeyError if ``page_name`` is not in :attr:`PAGE_MAP`.
-
- """
- return self.PAGE_MAP[page_name].format(
- project_name = urllib.quote(self.project_name), **kw)
-
def get_short_description(self, project):
page = self.get_page('project_info')
project.short_description = page.find(itemprop='description').string.strip()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2c578f5f/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/functional/test_github.py b/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
index 6667e7b..3c05a2d 100644
--- a/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
+++ b/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
@@ -24,5 +24,5 @@ class TestGitHubImportController(TestController, TestCase):
r = self.app.get('/p/import_project/github/')
assert 'GitHub Project Importer' in r
assert '<input id="user_name" name="user_name" value="" autofocus/>' in r
- assert '<input id="project_name" name="project_name" value="" autofocus/>' in r
+ assert '<input id="project_name" name="project_name" value="" />' in r
assert '<input id="project_shortname" name="project_shortname" value=""/>' in r
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2c578f5f/ForgeImporters/forgeimporters/tests/github/test_extractor.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/test_extractor.py b/ForgeImporters/forgeimporters/tests/github/test_extractor.py
index a21f775..cffbf81 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_extractor.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_extractor.py
@@ -17,32 +17,20 @@
from unittest import TestCase
-import mock
-
from ... import github
class TestGitHubProjectExtractor(TestCase):
def setUp(self):
- self._p_urlopen = mock.patch.object(github.urllib2, 'urlopen')
- self._p_json = mock.patch.object(github.json, 'loads')
- self.urlopen = self._p_urlopen.start()
- self.json = self._p_json.start()
- self.project = mock.Mock(name='project')
- self.project.get_tool_data.return_value = 'testproject'
-
- def tearDown(self):
- self._p_urlopen.stop()
- self._p_json.stop()
-
-
- def test_init(self):
- extractor = github.GitHubProjectExtractor(self.project, 'testproject', 'project_info')
- self.urlopen.assert_called_once_with('https://api.github.com/repos/testproject')
- self.assertEqual(extractor.project, self.project)
+ import json
+ from StringIO import StringIO
+ self.extractor = github.GitHubProjectExtractor('testproject')
+ d = dict(description='project description',
+ homepage='http://example.com')
+ self.extractor.urlopen = lambda url: StringIO(json.dumps(d))
def test_get_summary(self):
- extractor = github.GitHubProjectExtractor(self.project, 'testproject', 'project_info')
- extractor.page = {'description': 'test summary'}
- extractor.get_summmary()
- self.assertEqual(self.project.summary, 'test summary')
+ self.assertEqual(self.extractor.get_summary(), 'project description')
+
+ def test_get_homepage(self):
+ self.assertEqual(self.extractor.get_homepage(), 'http://example.com')
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2c578f5f/ForgeImporters/forgeimporters/tests/github/test_tasks.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/test_tasks.py b/ForgeImporters/forgeimporters/tests/github/test_tasks.py
index b478bc9..86b321e 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_tasks.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_tasks.py
@@ -26,6 +26,7 @@ from ...github import tasks
def test_import_project_info(c, session, ghpe):
c.project = mock.Mock(name='project')
tasks.import_project_info('my-project')
- ghpe.assert_called_once_with(c.project, 'my-project', 'project_info')
- ghpe.return_value.get_summmary.assert_called_once_with()
+ ghpe.assert_called_once_with('my-project')
+ ghpe.return_value.get_summary.assert_called_once_with()
+ ghpe.return_value.get_homepage.assert_called_once_with()
session.flush_all.assert_called_once_with()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2c578f5f/ForgeImporters/forgeimporters/tests/google/test_extractor.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/google/test_extractor.py b/ForgeImporters/forgeimporters/tests/google/test_extractor.py
index 92c5fb2..d5a9f22 100644
--- a/ForgeImporters/forgeimporters/tests/google/test_extractor.py
+++ b/ForgeImporters/forgeimporters/tests/google/test_extractor.py
@@ -28,7 +28,8 @@ from forgeimporters import base
class TestGoogleCodeProjectExtractor(TestCase):
def setUp(self):
self._p_urlopen = mock.patch.object(base.ProjectExtractor, 'urlopen')
- self._p_soup = mock.patch.object(google, 'BeautifulSoup')
+ # self._p_soup = mock.patch.object(google, 'BeautifulSoup')
+ self._p_soup = mock.patch.object(base, 'BeautifulSoup')
self.urlopen = self._p_urlopen.start()
self.soup = self._p_soup.start()
self.project = mock.Mock(name='project')
[6/8] git commit: [#6531] ticket:413 Remove github username from
project name
Posted by tv...@apache.org.
[#6531] ticket:413 Remove github username from project name
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/9bf4f01d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/9bf4f01d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/9bf4f01d
Branch: refs/heads/tv/6531
Commit: 9bf4f01dfbd67e818d50c95f31024184f23b2a94
Parents: 5d63159
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Thu Aug 22 15:22:55 2013 +0400
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Fri Aug 23 14:14:36 2013 +0000
----------------------------------------------------------------------
ForgeImporters/forgeimporters/github/project.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9bf4f01d/ForgeImporters/forgeimporters/github/project.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/project.py b/ForgeImporters/forgeimporters/github/project.py
index 4af2bdf..58485a7 100644
--- a/ForgeImporters/forgeimporters/github/project.py
+++ b/ForgeImporters/forgeimporters/github/project.py
@@ -45,7 +45,8 @@ class GitHubProjectImporter(base.ProjectImporter):
def after_project_create(self, project, **kw):
project.set_tool_data('github', project_name=project.name)
- tasks.import_project_info.post(project.name)
+ project_name = '%s/%s' % (kw['user_name'], kw['project_name'])
+ tasks.import_project_info.post(project_name)
@with_trailing_slash
@expose(index_template)
@@ -56,7 +57,6 @@ class GitHubProjectImporter(base.ProjectImporter):
@expose()
@validate(process_validator)
def process(self, **kw):
- kw['project_name'] = '%s/%s' % (kw['user_name'], kw['project_name'])
kw['tools'] = ''
return super(self.__class__, self).process(**kw)
[7/8] git commit: Merge branch '42cc_6531' of
ssh://git.code.sf.net/p/allura/git into 42cc_6531
Posted by tv...@apache.org.
Merge branch '42cc_6531' of ssh://git.code.sf.net/p/allura/git into 42cc_6531
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/3b71d0f8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/3b71d0f8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/3b71d0f8
Branch: refs/heads/tv/6531
Commit: 3b71d0f802e39b95f557eadc0ede14355ed108cb
Parents: 82597e9 796dcd3
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Fri Aug 23 14:55:37 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Fri Aug 23 14:55:37 2013 +0000
----------------------------------------------------------------------
----------------------------------------------------------------------
[5/8] git commit: [#6531] ticket:413 Project metadata importer for
github
Posted by tv...@apache.org.
[#6531] ticket:413 Project metadata importer for github
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/5d631591
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/5d631591
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/5d631591
Branch: refs/heads/tv/6531
Commit: 5d63159184fc3a7b7ea3efebf63adc29db4ab9b3
Parents: 0fb6390
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Tue Aug 20 13:18:20 2013 +0400
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Fri Aug 23 14:14:36 2013 +0000
----------------------------------------------------------------------
.../forgeimporters/github/__init__.py | 43 +++++++++++++
ForgeImporters/forgeimporters/github/project.py | 66 ++++++++++++++++++++
ForgeImporters/forgeimporters/github/tasks.py | 31 +++++++++
.../github/templates/project.html | 55 ++++++++++++++++
.../forgeimporters/tests/github/__init__.py | 17 +++++
.../tests/github/functional/__init__.py | 17 +++++
.../tests/github/functional/test_github.py | 28 +++++++++
.../tests/github/test_extractor.py | 48 ++++++++++++++
.../forgeimporters/tests/github/test_tasks.py | 31 +++++++++
ForgeImporters/setup.py | 1 +
10 files changed, 337 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5d631591/ForgeImporters/forgeimporters/github/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/__init__.py b/ForgeImporters/forgeimporters/github/__init__.py
new file mode 100644
index 0000000..472429e
--- /dev/null
+++ b/ForgeImporters/forgeimporters/github/__init__.py
@@ -0,0 +1,43 @@
+# 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.
+
+import re
+import urllib
+import urllib2
+import json
+try:
+ from cStringIO import StringIO
+except ImportError:
+ from StringIO import StringIO
+import logging
+
+log = logging.getLogger(__name__)
+
+class GitHubProjectExtractor(object):
+ RE_REPO_TYPE = re.compile(r'(svn|hg|git)')
+ PAGE_MAP = {
+ 'project_info': 'https://api.github.com/repos/%s',
+ }
+
+
+ def __init__(self, allura_project, gh_project_name, page):
+ self.project = allura_project
+ self.url = self.PAGE_MAP[page] % urllib.quote(gh_project_name)
+ self.page = json.loads(urllib2.urlopen(self.url).read().decode('utf8'))
+
+ def get_summmary(self):
+ self.project.summary = self.page['description']
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5d631591/ForgeImporters/forgeimporters/github/project.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/project.py b/ForgeImporters/forgeimporters/github/project.py
new file mode 100644
index 0000000..4af2bdf
--- /dev/null
+++ b/ForgeImporters/forgeimporters/github/project.py
@@ -0,0 +1,66 @@
+# 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.
+
+import logging
+
+from formencode import validators as fev
+
+from tg import expose, validate
+from tg.decorators import with_trailing_slash
+
+from allura.lib.decorators import require_post
+
+from .. import base
+from . import tasks
+
+
+log = logging.getLogger(__name__)
+
+class GitHubProjectForm(base.ProjectImportForm):
+ project_name = fev.Regex(r'^[a-z0-9][a-z0-9-]{,61}$',
+ not_empty=True,
+ messages={
+ 'invalid': 'Please use only letters, numbers, and dashes.',
+ })
+
+class GitHubProjectImporter(base.ProjectImporter):
+
+ source = 'GitHub'
+ index_template = 'jinja:forgeimporters.github:templates/project.html'
+ process_validator = GitHubProjectForm(source)
+
+ def after_project_create(self, project, **kw):
+ project.set_tool_data('github', project_name=project.name)
+ tasks.import_project_info.post(project.name)
+
+ @with_trailing_slash
+ @expose(index_template)
+ def index(self, **kw):
+ return super(self.__class__, self).index(**kw)
+
+ @require_post()
+ @expose()
+ @validate(process_validator)
+ def process(self, **kw):
+ kw['project_name'] = '%s/%s' % (kw['user_name'], kw['project_name'])
+ kw['tools'] = ''
+ return super(self.__class__, self).process(**kw)
+
+ @expose('json:')
+ @validate(process_validator)
+ def check_names(self, **kw):
+ return super(self.__class__, self).check_names(**kw)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5d631591/ForgeImporters/forgeimporters/github/tasks.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tasks.py b/ForgeImporters/forgeimporters/github/tasks.py
new file mode 100644
index 0000000..4fd928c
--- /dev/null
+++ b/ForgeImporters/forgeimporters/github/tasks.py
@@ -0,0 +1,31 @@
+# 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 pylons import tmpl_context as c
+
+from ming.orm import ThreadLocalORMSession
+
+from allura.lib.decorators import task
+
+from . import GitHubProjectExtractor
+
+
+@task
+def import_project_info(project_name):
+ extractor = GitHubProjectExtractor(c.project, project_name, 'project_info')
+ extractor.get_summmary()
+ ThreadLocalORMSession.flush_all()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5d631591/ForgeImporters/forgeimporters/github/templates/project.html
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/templates/project.html b/ForgeImporters/forgeimporters/github/templates/project.html
new file mode 100644
index 0000000..de42737
--- /dev/null
+++ b/ForgeImporters/forgeimporters/github/templates/project.html
@@ -0,0 +1,55 @@
+{#-
+ 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/project_base.html' %}
+
+{% block project_fields %}
+ <div class="grid-6">
+ <label>GitHub User Name</label>
+ </div>
+ <div class="grid-10">
+ <input id="user_name" name="user_name" value="{{c.form_values['user_name']}}" autofocus/>
+ <div id="user_name_error" class="error{% if not c.form_errors['user_name'] %} hidden{% endif %}">
+ {{c.form_errors['user_name']}}
+ </div>
+ </div>
+
+
+ <div class="grid-6" style="clear:left">
+ <label>GitHub Project Name</label>
+ </div>
+ <div class="grid-10">
+ <input id="project_name" name="project_name" value="{{c.form_values['project_name']}}" autofocus/>
+ <div id="project_name_error" class="error{% if not c.form_errors['project_name'] %} hidden{% endif %}">
+ {{c.form_errors['project_name']}}
+ </div>
+ </div>
+
+ <div class="grid-6" style="clear:left">
+ <label>URL Name</label>
+ </div>
+ <div class="grid-10">
+ <input id="project_shortname" name="project_shortname" value="{{c.form_values['project_shortname']}}"/>
+ <div id="project_shortname_error" class="error{% if not c.form_errors['project_shortname'] %} hidden{% endif %}">
+ {{c.form_errors['project_shortname']}}
+ </div>
+ <div id="project-url">
+ http://{{request.environ['HTTP_HOST']}}{{importer.neighborhood.url()}}<span id="url-fragment">{{c.form_values['project_shortname']}}</span>
+ </div>
+ </div>
+{% endblock %}
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5d631591/ForgeImporters/forgeimporters/tests/github/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/__init__.py b/ForgeImporters/forgeimporters/tests/github/__init__.py
new file mode 100644
index 0000000..77505f1
--- /dev/null
+++ b/ForgeImporters/forgeimporters/tests/github/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5d631591/ForgeImporters/forgeimporters/tests/github/functional/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/functional/__init__.py b/ForgeImporters/forgeimporters/tests/github/functional/__init__.py
new file mode 100644
index 0000000..77505f1
--- /dev/null
+++ b/ForgeImporters/forgeimporters/tests/github/functional/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5d631591/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/functional/test_github.py b/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
new file mode 100644
index 0000000..6667e7b
--- /dev/null
+++ b/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
@@ -0,0 +1,28 @@
+# 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 allura.tests import TestController
+
+class TestGitHubImportController(TestController, TestCase):
+
+ def test_index(self):
+ r = self.app.get('/p/import_project/github/')
+ assert 'GitHub Project Importer' in r
+ assert '<input id="user_name" name="user_name" value="" autofocus/>' in r
+ assert '<input id="project_name" name="project_name" value="" autofocus/>' in r
+ assert '<input id="project_shortname" name="project_shortname" value=""/>' in r
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5d631591/ForgeImporters/forgeimporters/tests/github/test_extractor.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/test_extractor.py b/ForgeImporters/forgeimporters/tests/github/test_extractor.py
new file mode 100644
index 0000000..a21f775
--- /dev/null
+++ b/ForgeImporters/forgeimporters/tests/github/test_extractor.py
@@ -0,0 +1,48 @@
+# 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
+
+import mock
+
+from ... import github
+
+
+class TestGitHubProjectExtractor(TestCase):
+ def setUp(self):
+ self._p_urlopen = mock.patch.object(github.urllib2, 'urlopen')
+ self._p_json = mock.patch.object(github.json, 'loads')
+ self.urlopen = self._p_urlopen.start()
+ self.json = self._p_json.start()
+ self.project = mock.Mock(name='project')
+ self.project.get_tool_data.return_value = 'testproject'
+
+ def tearDown(self):
+ self._p_urlopen.stop()
+ self._p_json.stop()
+
+
+ def test_init(self):
+ extractor = github.GitHubProjectExtractor(self.project, 'testproject', 'project_info')
+ self.urlopen.assert_called_once_with('https://api.github.com/repos/testproject')
+ self.assertEqual(extractor.project, self.project)
+
+ def test_get_summary(self):
+ extractor = github.GitHubProjectExtractor(self.project, 'testproject', 'project_info')
+ extractor.page = {'description': 'test summary'}
+ extractor.get_summmary()
+ self.assertEqual(self.project.summary, 'test summary')
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5d631591/ForgeImporters/forgeimporters/tests/github/test_tasks.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/test_tasks.py b/ForgeImporters/forgeimporters/tests/github/test_tasks.py
new file mode 100644
index 0000000..b478bc9
--- /dev/null
+++ b/ForgeImporters/forgeimporters/tests/github/test_tasks.py
@@ -0,0 +1,31 @@
+# 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.
+
+import mock
+
+from ...github import tasks
+
+
+@mock.patch.object(tasks, 'GitHubProjectExtractor')
+@mock.patch.object(tasks, 'ThreadLocalORMSession')
+@mock.patch.object(tasks, 'c')
+def test_import_project_info(c, session, ghpe):
+ c.project = mock.Mock(name='project')
+ tasks.import_project_info('my-project')
+ ghpe.assert_called_once_with(c.project, 'my-project', 'project_info')
+ ghpe.return_value.get_summmary.assert_called_once_with()
+ session.flush_all.assert_called_once_with()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5d631591/ForgeImporters/setup.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/setup.py b/ForgeImporters/setup.py
index b19fd17..cec76b4 100644
--- a/ForgeImporters/setup.py
+++ b/ForgeImporters/setup.py
@@ -36,6 +36,7 @@ setup(name='ForgeImporters',
[allura.project_importers]
google-code = forgeimporters.google.project:GoogleCodeProjectImporter
trac = forgeimporters.trac.project:TracProjectImporter
+ github = forgeimporters.github.project:GitHubProjectImporter
[allura.importers]
google-code-tracker = forgeimporters.google.tracker:GoogleCodeTrackerImporter
[4/8] git commit: [#6531] ticket:413 homepage import from allura
Posted by tv...@apache.org.
[#6531] ticket:413 homepage import from allura
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/82597e9a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/82597e9a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/82597e9a
Branch: refs/heads/tv/6531
Commit: 82597e9a6721d7658b4fc37e467d6281d2407928
Parents: 9bf4f01
Author: Anton Kasyanov <mi...@gmail.com>
Authored: Thu Aug 22 18:05:09 2013 +0300
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Fri Aug 23 14:14:36 2013 +0000
----------------------------------------------------------------------
ForgeImporters/forgeimporters/github/__init__.py | 3 +++
ForgeImporters/forgeimporters/github/tasks.py | 1 +
2 files changed, 4 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/82597e9a/ForgeImporters/forgeimporters/github/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/__init__.py b/ForgeImporters/forgeimporters/github/__init__.py
index 472429e..1ce4398 100644
--- a/ForgeImporters/forgeimporters/github/__init__.py
+++ b/ForgeImporters/forgeimporters/github/__init__.py
@@ -41,3 +41,6 @@ class GitHubProjectExtractor(object):
def get_summmary(self):
self.project.summary = self.page['description']
+
+ def get_homepage(self):
+ self.project.external_homepage = self.page['homepage']
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/82597e9a/ForgeImporters/forgeimporters/github/tasks.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tasks.py b/ForgeImporters/forgeimporters/github/tasks.py
index 4fd928c..be2325d 100644
--- a/ForgeImporters/forgeimporters/github/tasks.py
+++ b/ForgeImporters/forgeimporters/github/tasks.py
@@ -28,4 +28,5 @@ from . import GitHubProjectExtractor
def import_project_info(project_name):
extractor = GitHubProjectExtractor(c.project, project_name, 'project_info')
extractor.get_summmary()
+ extractor.get_homepage()
ThreadLocalORMSession.flush_all()