Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ability to configure repository clone directory #366

Merged
merged 10 commits into from
May 4, 2024

Conversation

filipkrayem
Copy link
Contributor

What does this change

Adds the ability to configure repository clone directory.

What issue does it fix

Closes #294

Notes for the reviewer

Hi! I'm a newcomer to Go, so the code probably isn't really idiomatic, any comments and reviews are more than welcome!

Checklist

  • Made sure the PR follows the CONTRIBUTING.md guidelines
  • Tests if something new is added

Copy link
Owner

@lindell lindell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

I'm impressed with the code as a Go beginner 🥇 But there are some things that need to be changed.

Feel free to reach out if anything is unclear.

tests/repo_helper_test.go Outdated Show resolved Hide resolved
tests/table_test.go Outdated Show resolved Hide resolved
tests/table_test.go Outdated Show resolved Hide resolved
tests/table_test.go Outdated Show resolved Hide resolved
internal/multigitter/shared.go Outdated Show resolved Hide resolved
internal/multigitter/shared.go Outdated Show resolved Hide resolved
internal/multigitter/shared.go Outdated Show resolved Hide resolved
tests/table_test.go Show resolved Hide resolved
internal/multigitter/shared.go Outdated Show resolved Hide resolved
@filipkrayem
Copy link
Contributor Author

Thanks for the thorough review! I implemented what you asked for, however there's one more thing I am not so sure about and that is the test. Couldn't really figure out what exactly to test for apart from a folder existing in the directory. Do you have any ideas on how to improve the test?

Copy link
Owner

@lindell lindell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code look good except two minor things left behind from the code comment refactoring.

When it comes to the test, it's a bit tricky, since multi-gitter should always delete the directory where things are cloned to after the execution is complete. So we will have to, from the script that is run, leave something behind.

I can think of two approaches.

  1. Create a program/script that prints the current location, then check it in the logs
// tests/scripts/pwd/main.go
package main

import (
	"fmt"
	"os"
)

func main() {
	path, _ := os.Getwd()
	fmt.Println("Current path:", path)
}
  1. A similar approach, expect printing the current location is saved to a file (which is then pushed to the "remote" by multi-gitter). Then we can verify what was committed and ensure that a specific file contains the text of the directory we expect.

Nr. 1 is probably the easiest.

internal/multigitter/shared.go Outdated Show resolved Hide resolved
internal/multigitter/shared.go Outdated Show resolved Hide resolved
@lindell lindell force-pushed the master branch 2 times, most recently from de07efa to 2e9b182 Compare July 15, 2023 19:12
@filipkrayem
Copy link
Contributor Author

Ended up adding it to the logs since creating a script would require changing the cobra.Command.Args config and that probably wouldn't be the best solution.

Copy link
Owner

@lindell lindell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ended up adding it to the logs since creating a script would require changing the cobra.Command.Args config and that probably wouldn't be the best solution.

I don't really know what is meant by cobra.Command.Args having to be changed. But just checking the logs of where it claims the repo will be cloned into will not actually test that this feature does work.

I implemented the test as suggested (, and added an absolute path test), based on the commit of the last review, and it seems to work without any cobra changes. e5f0c90

@@ -67,7 +67,9 @@ func (r Printer) runSingleRepo(ctx context.Context, repo scm.Repository) error {
log := log.WithField("repo", repo.FullName())
log.Info("Cloning and running script")

tmpDir, err := CreateTempDir(r.CloneDir)
tmpDir, err := createTempDir(r.CloneDir)
log.Info("Cloning into directory ", NormalizePath(tmpDir))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A log message is good. But it should be max debug level.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the path normalized for the logging?

Copy link
Contributor Author

@filipkrayem filipkrayem Jul 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the path wouldn't match on windows devices when not normalized

@@ -1001,6 +1002,7 @@ Repositories with a successful run:
verify: func(t *testing.T, vcMock *vcmock.VersionController, runData runData) {
require.Len(t, vcMock.PullRequests, 1)
assert.True(t, fileExist(t, workingDir, "tmp-test"))
assert.Contains(t, runData.logOut, multigitter.NormalizePath(filepath.Join(workingDir, "tmp-test/")))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking where the logs claim the repo is cloned to will not guarantee that it will actually use that directory.

tmpDir, err := createTempDir(r.CloneDir)
log.Debug("Cloning into directory ", NormalizePath(tmpDir))
CloneAndRun(os.TempDir())

⬆️ Pseudocode that would pass the test.

}

// Create the directory
err := os.MkdirAll(directoryPath, os.ModePerm)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0777 is higher permissions than needed for this directory. Just read and write access for the current user should be enough.

@filipkrayem
Copy link
Contributor Author

The tests work locally, even when run inside the github actions with act, so the issue is, it seems, related to the github environment where the actions are run. Any ideas?

@lindell
Copy link
Owner

lindell commented Aug 9, 2023

It might be that 0600 is not enough for the directory creation. Try to add execution permission as well (0700).

@filipkrayem
Copy link
Contributor Author

Hi, sorry, this PR got kind of forgotten 😄 I added the 0700 perms and resolved the merge conflict 👍

@filipkrayem filipkrayem requested a review from lindell May 3, 2024 07:27
Copy link
Owner

@lindell lindell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution 😄

@lindell lindell merged commit 6345c6b into lindell:master May 4, 2024
9 checks passed
Copy link
Contributor

github-actions bot commented May 4, 2024

Included in release v0.52.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to configure repository clone directory (currently system temp)
2 participants