aboutsummaryrefslogtreecommitdiff
path: root/common.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2018-05-27 01:51:46 +0700
committerShulhan <ms@kilabit.info>2018-05-27 02:34:34 +0700
commitc8ec4eef5463d072717fc1a2ce96d5a2dc873a74 (patch)
tree49bc40b23dc4a8b383aa9efdf64b08d38e41f283 /common.go
parent8899b54af622ccfd18d7d1b9ef8903801fe64005 (diff)
downloadbeku-c8ec4eef5463d072717fc1a2ce96d5a2dc873a74.tar.xz
env.SyncAll: display compare URL for manual reviewing
Diffstat (limited to 'common.go')
-rw-r--r--common.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/common.go b/common.go
index 3630699..1d5ee17 100644
--- a/common.go
+++ b/common.go
@@ -15,6 +15,56 @@ import (
)
//
+// GetCompareURL return the URL that compare two versions of package from
+// given remote URL. Remote URL can be in git format
+// ("git@github.com:<username>/<reponame>") or in HTTP format.
+//
+// On package that hosted on Github, the compare URL format is,
+//
+// https://github.com/<username>/<reponame>/compare/<old-version>...<new-version>
+//
+func GetCompareURL(remoteURL, oldVer, newVer string) (url string) {
+ if len(remoteURL) == 0 {
+ return
+ }
+
+ remoteURL = strings.TrimPrefix(remoteURL, "git@")
+ remoteURL = strings.TrimPrefix(remoteURL, "https://")
+ remoteURL = strings.TrimPrefix(remoteURL, "www.")
+ remoteURL = strings.TrimSuffix(remoteURL, ".git")
+
+ var host, user, repo string
+
+ colIdx := strings.IndexByte(remoteURL, ':')
+ if colIdx > 0 {
+ names := strings.Split(remoteURL[colIdx+1:], "/")
+
+ host = remoteURL[0:colIdx]
+ user = names[0]
+ repo = names[len(names)-1]
+ } else {
+ names := strings.Split(remoteURL, "/")
+ if len(names) < 3 {
+ return
+ }
+ host = names[0]
+ user = names[1]
+ repo = names[len(names)-1]
+ }
+
+ switch host {
+ case "github.com":
+ url = fmt.Sprintf("https://%s/%s/%s/compare/%s...%s", host,
+ user, repo, oldVer, newVer)
+ case "golang.org":
+ url = fmt.Sprintf("https://github.com/golang/%s/compare/%s...%s",
+ repo, oldVer, newVer)
+ }
+
+ return
+}
+
+//
// IsDirEmpty will return true if directory is not exist or empty; otherwise
// it will return false.
//