Repository: seachicken/gh-poi
Pull request #114 (2023-10-28 11:32:49)

bump actions/checkout v4


Patch:
diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml
index 77ba203..7d3a505 100644
--- a/.github/workflows/ci-windows.yml
+++ b/.github/workflows/ci-windows.yml
@@ -14,7 +14,7 @@ jobs:
     - name: Prepare git
       run: git config --global core.autocrlf false
 
-    - uses: actions/checkout@v3
+    - uses: actions/checkout@v4
 
     - name: Set up Go
       uses: actions/setup-go@v3
@@ -25,7 +25,7 @@ jobs:
       run: go build -v ./...
 
     - name: Checkout dummy repo
-      uses: actions/checkout@v3
+      uses: actions/checkout@v4
       with:
         repository: seachicken/can
         path: ci-test
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index aba6278..bd16f38 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -15,7 +15,7 @@ jobs:
     runs-on: ${{ matrix.os }}
 
     steps:
-    - uses: actions/checkout@v3
+    - uses: actions/checkout@v4
 
     - name: Set up Go
       uses: actions/setup-go@v3
@@ -26,7 +26,7 @@ jobs:
       run: go build -v ./...
 
     - name: Checkout dummy repo
-      uses: actions/checkout@v3
+      uses: actions/checkout@v4
       with:
         repository: seachicken/can
         path: ci-test
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index efdb30c..53068a9 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -38,7 +38,7 @@ jobs:
 
     steps:
     - name: Checkout repository
-      uses: actions/checkout@v3
+      uses: actions/checkout@v4
 
     # Initializes the CodeQL tools for scanning.
     - name: Initialize CodeQL
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index ae8f43e..ea933c4 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -11,7 +11,7 @@ jobs:
     runs-on: ubuntu-latest
 
     steps:
-    - uses: actions/checkout@v3
+    - uses: actions/checkout@v4
       with:
         fetch-depth: 0
 
diff --git a/shared/remote.go b/shared/remote.go
index 3579da8..dd2b76f 100644
--- a/shared/remote.go
+++ b/shared/remote.go
@@ -1,6 +1,8 @@
 package shared
 
 import (
+	"fmt"
+	"net/url"
 	"regexp"
 	"strings"
 )
@@ -13,16 +15,54 @@ type (
 	}
 )
 
-// https://datatracker.ietf.org/doc/html/rfc3986#section-2.3
-var regex = regexp.MustCompile(`^(?:(?:[a-zA-Z0-9-._~]+)(?:://|@))?([a-zA-Z0-9-._~]+)[:/](.+?/.+?)(?:\.git|)$`)
+var (
+	hasSchemePattern  = regexp.MustCompile("^[^:]+://")
+	scpLikeURLPattern = regexp.MustCompile("^([^@]+@)?([^:]+):(/?.+)$")
+)
 
+// NewRemote parses the result of `git remote -v` and returns a Remote struct.
+//
+// acceptable url formats:
+//
+//	ssh://[user@]host.xz[:port]/path/to/repo.git/
+//	git://host.xz[:port]/path/to/repo.git/
+//	http[s]://host.xz[:port]/path/to/repo.git/
+//	ftp[s]://host.xz[:port]/path/to/repo.git/
+//
+// An alternative scp-like syntax may also be used with the ssh protocol:
+//
+//	[user@]host.xz:path/to/repo.git/
+//
+// ref. http://git-scm.com/docs/git-fetch#_git_urls
+// the code is heavily inspired by https://github.com/x-motemen/ghq/blob/7163e61e2309a039241ad40b4a25bea35671ea6f/url.go
 func NewRemote(remoteConfig string) Remote {
 	splitConfig := strings.Fields(remoteConfig)
-	if len(splitConfig) == 3 {
-		found := regex.FindStringSubmatch(splitConfig[1])
-		if len(found) == 3 {
-			return Remote{splitConfig[0], found[1], found[2]}
+	if len(splitConfig) != 3 {
+		return Remote{}
+	}
+
+	ref := splitConfig[1]
+	if !hasSchemePattern.MatchString(ref) {
+		if scpLikeURLPattern.MatchString(ref) {
+			matched := scpLikeURLPattern.FindStringSubmatch(ref)
+			user := matched[1]
+			host := matched[2]
+			path := matched[3]
+			ref = fmt.Sprintf("ssh://%s%s/%s", user, host, strings.TrimPrefix(path, "/"))
 		}
 	}
-	return Remote{}
+	u, err := url.Parse(ref)
+	if err != nil {
+		return Remote{}
+	}
+
+	repo := u.Path
+	repo = strings.TrimPrefix(repo, "/")
+	repo = strings.TrimSuffix(repo, ".git")
+
+	return Remote{
+		Name:     splitConfig[0],
+		Hostname: u.Host,
+		RepoName: repo,
+	}
 }


Test patch:
diff --git a/.github/workflows/contract-test.yml b/.github/workflows/contract-test.yml
index fa08ab6..c734f1b 100644
--- a/.github/workflows/contract-test.yml
+++ b/.github/workflows/contract-test.yml
@@ -12,7 +12,7 @@ jobs:
     runs-on: ubuntu-latest
 
     steps:
-    - uses: actions/checkout@v3
+    - uses: actions/checkout@v4
 
     - run: sudo add-apt-repository ppa:git-core/ppa
     - run: sudo apt-get update
diff --git a/shared/remote_test.go b/shared/remote_test.go
index 4de0c40..a8fcdf6 100644
--- a/shared/remote_test.go
+++ b/shared/remote_test.go
@@ -28,6 +28,17 @@ func Test_CreateRemoteWithScpLikeUrlAndCustomUserinfo(t *testing.T) {
 	)
 }
 
+func Test_CreateRemoteWithSshUrl(t *testing.T) {
+	assert.Equal(t,
+		Remote{
+			Name:     "origin",
+			Hostname: "github.com",
+			RepoName: "org/repo",
+		},
+		NewRemote("origin	ssh://git@github.com/org/repo.git (fetch)"),
+	)
+}
+
 func Test_CreateRemoteWithScpLikeUrlWithoutUserinfo(t *testing.T) {
 	assert.Equal(t,
 		Remote{