Skip to content

Commit d4272bd

Browse files
Ryanmergify[bot]
Ryan
andauthored
feat: add option to specify git remote name (#1104)
fixes nektos/act#1099 fixes nektos/act#983 Signed-off-by: Ryan <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 9dc17f9 commit d4272bd

File tree

6 files changed

+15
-7
lines changed

6 files changed

+15
-7
lines changed

cmd/input.go

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Input struct {
4040
artifactServerPort string
4141
jsonLogger bool
4242
noSkipCheckout bool
43+
remoteName string
4344
}
4445

4546
func (i *Input) resolve(path string) string {

cmd/root.go

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func Execute(ctx context.Context, version string) {
4343
rootCmd.Flags().StringP("job", "j", "", "run job")
4444
rootCmd.Flags().BoolP("bug-report", "", false, "Display system information for bug report")
4545

46+
rootCmd.Flags().StringVar(&input.remoteName, "remote-name", "origin", "git remote name that will be used to retrieve url of git repo")
4647
rootCmd.Flags().StringArrayVarP(&input.secrets, "secret", "s", []string{}, "secret to make available to actions with optional value (e.g. -s mysecret=foo or -s mysecret)")
4748
rootCmd.Flags().StringArrayVarP(&input.envs, "env", "", []string{}, "env to make available to actions with optional value (e.g. --env myenv=foo or --env myenv)")
4849
rootCmd.Flags().StringArrayVarP(&input.platforms, "platform", "P", []string{}, "custom image to use per platform (e.g. -P ubuntu-18.04=nektos/act-environments-ubuntu:18.04)")
@@ -379,6 +380,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
379380
ArtifactServerPath: input.artifactServerPath,
380381
ArtifactServerPort: input.artifactServerPort,
381382
NoSkipCheckout: input.noSkipCheckout,
383+
RemoteName: input.remoteName,
382384
}
383385
r, err := runner.New(config)
384386
if err != nil {

pkg/common/git.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,20 @@ func findGitPrettyRef(head, root, sub string) (string, error) {
142142
}
143143

144144
// FindGithubRepo get the repo
145-
func FindGithubRepo(file string, githubInstance string) (string, error) {
146-
url, err := findGitRemoteURL(file)
145+
func FindGithubRepo(file, githubInstance, remoteName string) (string, error) {
146+
if remoteName == "" {
147+
remoteName = "origin"
148+
}
149+
150+
url, err := findGitRemoteURL(file, remoteName)
147151
if err != nil {
148152
return "", err
149153
}
150154
_, slug, err := findGitSlug(url, githubInstance)
151155
return slug, err
152156
}
153157

154-
func findGitRemoteURL(file string) (string, error) {
158+
func findGitRemoteURL(file, remoteName string) (string, error) {
155159
gitDir, err := findGitDirectory(file)
156160
if err != nil {
157161
return "", err
@@ -162,7 +166,7 @@ func findGitRemoteURL(file string) (string, error) {
162166
if err != nil {
163167
return "", err
164168
}
165-
remote, err := gitconfig.GetSection("remote \"origin\"")
169+
remote, err := gitconfig.GetSection(fmt.Sprintf(`remote "%s"`, remoteName))
166170
if err != nil {
167171
return "", err
168172
}

pkg/common/git_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestFindGitSlug(t *testing.T) {
4747
func testDir(t *testing.T) string {
4848
basedir, err := ioutil.TempDir("", "act-test")
4949
require.NoError(t, err)
50-
t.Cleanup(func() { os.RemoveAll(basedir) })
50+
t.Cleanup(func() { _ = os.RemoveAll(basedir) })
5151
return basedir
5252
}
5353

@@ -86,7 +86,7 @@ func TestFindGitRemoteURL(t *testing.T) {
8686
err = gitCmd("config", "-f", fmt.Sprintf("%s/.git/config", basedir), "--add", "remote.origin.url", remoteURL)
8787
assert.NoError(err)
8888

89-
u, err := findGitRemoteURL(basedir)
89+
u, err := findGitRemoteURL(basedir, "origin")
9090
assert.NoError(err)
9191
assert.Equal(remoteURL, u)
9292
}

pkg/runner/run_context.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ func (rc *RunContext) getGithubContext() *model.GithubContext {
510510
}
511511

512512
repoPath := rc.Config.Workdir
513-
repo, err := common.FindGithubRepo(repoPath, rc.Config.GitHubInstance)
513+
repo, err := common.FindGithubRepo(repoPath, rc.Config.GitHubInstance, rc.Config.RemoteName)
514514
if err != nil {
515515
log.Warningf("unable to get git repo: %v", err)
516516
} else {

pkg/runner/runner.go

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type Config struct {
5151
ArtifactServerPort string // the port the artifact server binds to
5252
CompositeRestrictions *model.CompositeRestrictions // describes which features are available in composite actions
5353
NoSkipCheckout bool // do not skip actions/checkout
54+
RemoteName string // remote name in local git repo config
5455
}
5556

5657
// Resolves the equivalent host path inside the container

0 commit comments

Comments
 (0)