Feature/dependency pinning and update automation (#5451)

* * handle local flag
* add managerfactory handling for local flag
* add shortName handling for local flag
* add dot git file handling for local flag
* add tests

* fix normal listing

* add ParseGitRepository function, add viper, add testing for utils

* add latest tag logic, add auto pinning and auto fetching

* makke gorepomod list works with --local

* make pinning works with local flag, enable auto update on fork and non-fork repo

* fix: refactor to pass linter

* refactor code and fix comments

* edit README

* refactor code to pass linting

* refactor code

* refactor code and enable patch branch label

* ru add license

* fbackward compatibility for unpin
This commit is contained in:
Kurnianto Trilaksono
2024-01-17 05:34:56 +08:00
committed by GitHub
parent f3fedac429
commit ab519fdc13
18 changed files with 1189 additions and 88 deletions

View File

@@ -4,8 +4,10 @@
package utils
import (
"fmt"
"log"
"os"
"regexp"
"strings"
)
@@ -45,3 +47,38 @@ func SliceContains(slice []string, target string) bool {
}
return false
}
// Receive git remote url as input and produce string containing git repository name
// e.g. kustomize, myrepo/kustomize
func ParseGitRepositoryPath(urlString string) string {
var d []string = getURLStringArray(urlString)
protocol := d[0]
var repoPath string
// TODO(antoooks): Confirm if we should handle other formats not commonly supported by Github
switch protocol {
// ssh protocol, e.g. git@github.com:path/repo.git
case "git":
repoPath = strings.Join(d[2:len(d)-1], "/") + "/" + d[3][:len(d[3])-4]
// https protocol, e.g. https://github.com/path/repo.git
case "https":
repoPath = strings.Join(d[2:], "/")
repoPath = repoPath[:len(repoPath)-4]
// unsupported format
default:
_ = fmt.Errorf("protocol format is not supported: %s", protocol)
return ""
}
return d[1] + "/" + repoPath
}
// Extract array of string from urlString
func getURLStringArray(urlString string) []string {
// Supported git regex based on URI allowed regex as defined under RFC3986
const rfc3986 = `[A-Za-z0-9][A-Za-z0-9+.-]*`
re := regexp.MustCompile(rfc3986)
var u []string = re.FindAllString(urlString, -1)
return u
}

View File

@@ -0,0 +1,36 @@
// Copyright 2023 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package utils
import (
"testing"
)
func TestParseGitRepositoryPath(t *testing.T) {
var testCases = map[string]struct {
urlString string
expected string
}{
"ssh format": {
urlString: "git@github.com:path/dummy.git",
expected: "github.com/path/dummy",
},
"https format": {
urlString: "https://github.com/path/dummy.git",
expected: "github.com/path/dummy",
},
"unknown format": {
urlString: "file:///path/to/repo.git/",
expected: "",
},
}
for n, tc := range testCases {
actual := ParseGitRepositoryPath(tc.urlString)
t.Log(actual)
if actual != tc.expected {
t.Errorf("%s: expected %s, got %s", n, tc.expected, actual)
}
}
}