This is an automated email from the ASF dual-hosted git repository.
mrutkowski pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/incubator-openwhisk-wskdeploy.git
The following commit(s) were added to refs/heads/master by this push:
new 40f6455 GH-735 adjusting check for github to mainly make sure that
github app… (#738)
40f6455 is described below
commit 40f6455b61b308bde1a33f0c20eff1b4a4ed89be
Author: allen-servedio <[email protected]>
AuthorDate: Thu Feb 15 10:18:22 2018 -0500
GH-735 adjusting check for github to mainly make sure that github app…
(#738)
* GH-735 adjusting check for github to mainly make sure that github appears
in the host name. Will allow many variations of host names as well as username
and password.
* GH-735 Adding comment that private repos are not fully supported.
---
.gitignore | 4 ++++
utils/dependencies.go | 12 ++++++----
utils/dependencies_test.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 71 insertions(+), 4 deletions(-)
diff --git a/.gitignore b/.gitignore
index 73345b7..d986475 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,6 +35,10 @@ wskdeploy
# Go IDE
.idea
*.iml
+.project
+.settings
+.vscode
+Packages/
# Gradle
.gradle
diff --git a/utils/dependencies.go b/utils/dependencies.go
index 92c19d9..f892101 100644
--- a/utils/dependencies.go
+++ b/utils/dependencies.go
@@ -72,10 +72,14 @@ func LocationIsBinding(location string) bool {
return false
}
-func LocationIsGithub(location string) bool {
- if strings.HasPrefix(location, "github.com") ||
strings.HasPrefix(location, "https://github.com") ||
strings.HasPrefix(location, "http://github.com") {
- return true
+func removeProtocol(location string) string {
+ if paths := strings.SplitAfterN(location, "://", 2); len(paths) == 2 {
+ return paths[1]
}
+ return location
+}
- return false
+func LocationIsGithub(location string) bool {
+ paths := strings.SplitN(removeProtocol(location), "/", 2)
+ return strings.Contains(paths[0], "github")
}
diff --git a/utils/dependencies_test.go b/utils/dependencies_test.go
new file mode 100644
index 0000000..6041deb
--- /dev/null
+++ b/utils/dependencies_test.go
@@ -0,0 +1,59 @@
+// +build unit
+
+/*
+ * 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.
+ */
+
+package utils
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+/* NOTE: Though username and password is used here, this does not mean that
wskdeploy fully supports private repos.
+ * This is merely one of many changes required to support them.
+ */
+
+func TestLocationIsGithub(t *testing.T) {
+ assert.True(t, LocationIsGithub("github.com/my-org/my-project"), "Does
not allow github without a http/https prefix")
+ assert.True(t, LocationIsGithub("github.ibm.com/my-org/my-project"),
"Does not allow github.ibm.com without a http/https prefix")
+ assert.True(t, LocationIsGithub("http://github.com/my-org/my-project"),
"Does not allow github with a http/https prefix")
+ assert.True(t,
LocationIsGithub("http://github.ibm.com/my-org/my-project"), "Does not allow
github.ibm.com with a http/https prefix")
+}
+
+func TestLocationIsGithub_WithUsernamePassword(t *testing.T) {
+ assert.True(t,
LocationIsGithub("username:[email protected]/my-org/my-project"), "Does not
allow username/password and github without a http/https prefix")
+ assert.True(t,
LocationIsGithub("username:[email protected]/my-org/my-project"), "Does
not allow username/password and github.ibm.com without a http/https prefix")
+ assert.True(t,
LocationIsGithub("http://username:[email protected]/my-org/my-project"),
"Does not allow username/password and github with a http/https prefix")
+ assert.True(t,
LocationIsGithub("http://username:[email protected]/my-org/my-project"),
"Does not allow username/password and github.ibm.com with a http/https prefix")
+}
+
+func TestLocationIsGithub_NonGithub(t *testing.T) {
+ assert.False(t, LocationIsGithub("git.com/my-org/my-project"), "Allows
non-github without a http/https prefix")
+ assert.False(t, LocationIsGithub("git.ibm.com/my-org/my-project"),
"Allows non-github.ibm.com without a http/https prefix")
+ assert.False(t, LocationIsGithub("http://git.com/my-org/my-project"),
"Allows non-github with a http/https prefix")
+ assert.False(t,
LocationIsGithub("http://git.ibm.com/my-org/my-project"), "Allows
non-github.ibm.com with a http/https prefix")
+
+ assert.False(t, LocationIsGithub("git.com/my-org/my-github"), "Thinks
it is github because it is part of the project name")
+ assert.False(t, LocationIsGithub("git.com/my-org/github"), "Thinks it
is github because it is the project name")
+ assert.False(t, LocationIsGithub("git.com/my-github/my-project"),
"Thinks it is github because it is part of the organization name")
+ assert.False(t, LocationIsGithub("git.com/github/my-project"), "Thinks
it is github because it is the organization name")
+
+ assert.False(t, LocationIsGithub("git.com"), "Allows non-github")
+ assert.False(t, LocationIsGithub(""), "Allows empty location")
+}
--
To stop receiving notification emails like this one, please contact
[email protected].