-
Notifications
You must be signed in to change notification settings - Fork 66
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
Conversation
There was a problem hiding this 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.
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? |
There was a problem hiding this 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.
- 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)
}
- 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.
de07efa
to
2e9b182
Compare
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. |
There was a problem hiding this 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
internal/multigitter/print.go
Outdated
@@ -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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
tests/table_test.go
Outdated
@@ -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/"))) |
There was a problem hiding this comment.
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.
internal/multigitter/shared.go
Outdated
} | ||
|
||
// Create the directory | ||
err := os.MkdirAll(directoryPath, os.ModePerm) |
There was a problem hiding this comment.
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.
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? |
It might be that 0600 is not enough for the directory creation. Try to add execution permission as well (0700). |
Hi, sorry, this PR got kind of forgotten 😄 I added the 0700 perms and resolved the merge conflict 👍 |
There was a problem hiding this 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 😄
Included in release v0.52.0 🎉 |
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