You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by gc...@apache.org on 2021/12/08 01:48:11 UTC

[allura] branch gc/8403 created (now 7b0ff43)

This is an automated email from the ASF dual-hosted git repository.

gcruz pushed a change to branch gc/8403
in repository https://gitbox.apache.org/repos/asf/allura.git.


      at 7b0ff43  8403 added new project_url field with validator and tooltips

This branch includes the following new commits:

     new 7b0ff43  8403 added new project_url field with validator and tooltips

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[allura] 01/01: 8403 added new project_url field with validator and tooltips

Posted by gc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gcruz pushed a commit to branch gc/8403
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 7b0ff43bf14bd8f2daf2d00d4e90490bd8314bb9
Author: Guillermo Cruz <gu...@slashdotmedia.com>
AuthorDate: Tue Dec 7 18:47:52 2021 -0700

    8403 added new project_url field with validator and tooltips
---
 ForgeImporters/forgeimporters/github/__init__.py   | 13 +++-
 ForgeImporters/forgeimporters/github/project.py    |  2 +
 .../forgeimporters/github/templates/project.html   | 78 +++++++++++++++++++++-
 .../forgeimporters/templates/project_base.html     |  1 +
 4 files changed, 90 insertions(+), 4 deletions(-)

diff --git a/ForgeImporters/forgeimporters/github/__init__.py b/ForgeImporters/forgeimporters/github/__init__.py
index 32098fa..ebbbef9 100644
--- a/ForgeImporters/forgeimporters/github/__init__.py
+++ b/ForgeImporters/forgeimporters/github/__init__.py
@@ -21,6 +21,7 @@ import re
 import logging
 import json
 import time
+import requests
 import six.moves.urllib.parse
 import six.moves.urllib.request
 import six.moves.urllib.error
@@ -30,14 +31,24 @@ from tg import config, session, redirect, request, expose
 from tg.decorators import without_trailing_slash
 from tg import tmpl_context as c
 from requests_oauthlib import OAuth2Session
-import requests
 from formencode import validators as fev
 
 from forgeimporters import base
+from urllib.parse import urlparse
 
 log = logging.getLogger(__name__)
 
 
+class GitHubURLValidator(fev.FancyValidator):
+    regex = r'https?:\/\/github\.com'
+    def _to_python(self, value, state):
+        valid_url = urlparse(value.strip())
+        if not bool(valid_url.scheme):
+            raise fev.Invalid('Invalid URL', value, state)
+        if not re.match(self.regex, value):
+            raise fev.Invalid('Invalid Github URL', value, state)
+        return value
+
 class GitHubProjectNameValidator(fev.FancyValidator):
     not_empty = True
     messages = {
diff --git a/ForgeImporters/forgeimporters/github/project.py b/ForgeImporters/forgeimporters/github/project.py
index 914ccf8..8d16838 100644
--- a/ForgeImporters/forgeimporters/github/project.py
+++ b/ForgeImporters/forgeimporters/github/project.py
@@ -29,6 +29,7 @@ from forgeimporters.github import (
     tasks,
     GitHubOAuthMixin,
     GitHubProjectNameValidator,
+    GitHubURLValidator,
 )
 
 
@@ -37,6 +38,7 @@ log = logging.getLogger(__name__)
 
 class GitHubProjectForm(base.ProjectImportForm):
     project_name = GitHubProjectNameValidator()
+    project_url = GitHubURLValidator()
 
 
 class GitHubProjectImporter(base.ProjectImporter, GitHubOAuthMixin):
diff --git a/ForgeImporters/forgeimporters/github/templates/project.html b/ForgeImporters/forgeimporters/github/templates/project.html
index 6f4a067..fb09601 100644
--- a/ForgeImporters/forgeimporters/github/templates/project.html
+++ b/ForgeImporters/forgeimporters/github/templates/project.html
@@ -16,11 +16,29 @@
        specific language governing permissions and limitations
        under the License.
 -#}
+{%- import '/var/local/sftheme/allura/sftheme/templates/sftheme/shared_svgs_macro.html' as shared_svgs_macro -%}
 {% extends 'forgeimporters:templates/project_base.html' %}
 
+
 {% block project_fields %}
-    <div class="grid-6">
-        <label>GitHub User Name</label>
+
+     <div class="grid-6" style="clear:left">
+        <label>GitHub Project URL
+            <span class="tooltip" title="Paste a Github project url to automatically set the user name and project name">{{ shared_svgs_macro.global_svgs('info-circle', class='svgico info-circle') }}</span>
+        </label>
+    </div>
+     <div class="grid-10">
+        <input id="project_url" name="project_url" value="{{c.form_values['project_url']}}" />
+        <div id="project_url_error" class="error{% if not c.form_errors['project_url'] %} hidden{% endif %}">
+            {{c.form_errors['project_url']}}
+        </div>
+    </div>
+
+    <div class="grid-6" style="clear:left">
+        <label>
+            GitHub User Name
+            <span class="tooltip" title="Your Github user name can be found in the dropdown menu when you click on your avatar">{{ shared_svgs_macro.global_svgs('info-circle', class='svgico info-circle') }}</span>
+        </label>
     </div>
      <div class="grid-10">
         <input id="user_name" name="user_name" value="{{c.form_values['user_name']}}" autofocus/>
@@ -29,8 +47,15 @@
         </div>
     </div>
 
+
+
+
     <div class="grid-6" style="clear:left">
-        <label>GitHub Project Name</label>
+        <label>
+            GitHub Project Name
+            <span class="tooltip" title="You can select any name from your repositories section">{{ shared_svgs_macro.global_svgs('info-circle', class='svgico info-circle') }}</span>
+        </label>
+
     </div>
      <div class="grid-10">
         <input id="project_name" name="project_name" value="{{c.form_values['project_name']}}" />
@@ -51,4 +76,51 @@
             http://{{request.environ['HTTP_HOST']}}{{importer.neighborhood.url()}}<span id="url-fragment">{{c.form_values['project_shortname']}}</span>
         </div>
     </div>
+    <script>
+    $(window).load(function() {
+
+        function name(str) {
+            return str ? str.replace(/^\W+|\.git$/g, '') : null;
+        }
+
+        function owner(str) {
+            if (!str) return null;
+            var idx = str.indexOf(':');
+            if (idx > -1) {
+                return str.slice(idx + 1);
+            }
+            return str;
+        }
+
+        $('#project_url').on('keyup', function (evt) {
+            $('#project_url_error').toggleClass('hidden', true)
+            if (!$(this).val()) {
+                $('#project_name').val('');
+                $('#user_name').val('');
+                return;
+            }
+            console.log($(this).val())
+            try {
+                var url = new window.URL($(this).val());
+            }catch(e){
+                $('#project_url_error').empty().append('<p>Not a valid URL</p>')
+                $('#project_url_error').toggleClass('hidden', false)
+                return
+            }
+
+
+
+            var pieces = url.pathname.split('/').filter(Boolean);
+            console.log("pieces", pieces)
+            let _owner = owner(pieces[0]);
+            let _name = name(pieces[1]);
+            $('#project_name').val(_name);
+            $('#user_name').val(_owner);
+            $('#project_name').trigger('change')
+        })
+
+
+
+    })
+    </script>
 {% endblock %}
diff --git a/ForgeImporters/forgeimporters/templates/project_base.html b/ForgeImporters/forgeimporters/templates/project_base.html
index 65b33b8..0eea95d 100644
--- a/ForgeImporters/forgeimporters/templates/project_base.html
+++ b/ForgeImporters/forgeimporters/templates/project_base.html
@@ -67,6 +67,7 @@
         $(function() {
             $('#project_name').bind('change keyup', suggest_name);
             $('#project_shortname').bind('change keyup', function(event) {
+                console.log("EVEN FIRED!!!")
                 if (event.type == 'keyup') {
                     manual = true;
                 }