mrutkows closed pull request #738: GH-735 adjusting check for github to mainly
make sure that github app?
URL: https://github.com/apache/incubator-openwhisk-wskdeploy/pull/738
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/.gitignore b/.gitignore
index 73345b7b..d9864756 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 92c19d94..f8921012 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 00000000..6041deb7
--- /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")
+}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services