feat: add option to specify git remote name (#1104)
fixes https://github.com/nektos/act/issues/1099 fixes https://github.com/nektos/act/issues/983 Signed-off-by: Ryan <me@hackerc.at> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
@@ -142,8 +142,12 @@ func findGitPrettyRef(head, root, sub string) (string, error) {
|
||||
}
|
||||
|
||||
// FindGithubRepo get the repo
|
||||
func FindGithubRepo(file string, githubInstance string) (string, error) {
|
||||
url, err := findGitRemoteURL(file)
|
||||
func FindGithubRepo(file, githubInstance, remoteName string) (string, error) {
|
||||
if remoteName == "" {
|
||||
remoteName = "origin"
|
||||
}
|
||||
|
||||
url, err := findGitRemoteURL(file, remoteName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -151,7 +155,7 @@ func FindGithubRepo(file string, githubInstance string) (string, error) {
|
||||
return slug, err
|
||||
}
|
||||
|
||||
func findGitRemoteURL(file string) (string, error) {
|
||||
func findGitRemoteURL(file, remoteName string) (string, error) {
|
||||
gitDir, err := findGitDirectory(file)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -162,7 +166,7 @@ func findGitRemoteURL(file string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
remote, err := gitconfig.GetSection("remote \"origin\"")
|
||||
remote, err := gitconfig.GetSection(fmt.Sprintf(`remote "%s"`, remoteName))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ func TestFindGitSlug(t *testing.T) {
|
||||
func testDir(t *testing.T) string {
|
||||
basedir, err := ioutil.TempDir("", "act-test")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { os.RemoveAll(basedir) })
|
||||
t.Cleanup(func() { _ = os.RemoveAll(basedir) })
|
||||
return basedir
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ func TestFindGitRemoteURL(t *testing.T) {
|
||||
err = gitCmd("config", "-f", fmt.Sprintf("%s/.git/config", basedir), "--add", "remote.origin.url", remoteURL)
|
||||
assert.NoError(err)
|
||||
|
||||
u, err := findGitRemoteURL(basedir)
|
||||
u, err := findGitRemoteURL(basedir, "origin")
|
||||
assert.NoError(err)
|
||||
assert.Equal(remoteURL, u)
|
||||
}
|
||||
|
@@ -510,7 +510,7 @@ func (rc *RunContext) getGithubContext() *model.GithubContext {
|
||||
}
|
||||
|
||||
repoPath := rc.Config.Workdir
|
||||
repo, err := common.FindGithubRepo(repoPath, rc.Config.GitHubInstance)
|
||||
repo, err := common.FindGithubRepo(repoPath, rc.Config.GitHubInstance, rc.Config.RemoteName)
|
||||
if err != nil {
|
||||
log.Warningf("unable to get git repo: %v", err)
|
||||
} else {
|
||||
|
@@ -51,6 +51,7 @@ type Config struct {
|
||||
ArtifactServerPort string // the port the artifact server binds to
|
||||
CompositeRestrictions *model.CompositeRestrictions // describes which features are available in composite actions
|
||||
NoSkipCheckout bool // do not skip actions/checkout
|
||||
RemoteName string // remote name in local git repo config
|
||||
}
|
||||
|
||||
// Resolves the equivalent host path inside the container
|
||||
|
Reference in New Issue
Block a user