-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Set current repo as Env var #115
Comments
I would like to expand upon @carusooo's idea (hello, fellow Andy 👋) by also exposing Looking at the code in git-xargs/repository/repo-operations.go Lines 104 to 120 in c630589
Maybe this looks something like: func executeCommandWithLogger(config *config.GitXargsConfig, repositoryDir string, repo *github.Repository, logger *logrus.Logger) error {
if len(config.Args) < 1 {
return errors.WithStackTrace(types.NoCommandSuppliedErr{})
}
cmdArgs := config.Args
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
cmd.Dir = repositoryDir
cmd.Env = os.Environ()
cmd.Env = append(cmd.Environ(), fmt.Sprintf("XARGS_REPO_NAME=%s", repo.GetName()))
cmd.Env = append(cmd.Environ(), fmt.Sprintf("XARGS_DRY_RUN=%s", config.DryRun))
logger.WithFields(logrus.Fields{
"Repo": repo.GetName(),
"Directory": repositoryDir,
"Command": config.Args,
}).Debug("Executing command against local clone of repo...")
stdoutStdErr, err := cmd.CombinedOutput()
|
Closes gruntwork-io#115 These changes add support for git-xargs registered environment variables based on arguments and flags intended for use by the commands and scripts called by git-xargs. These environment variables start with `XARGS_` to avoid collision with other use cases and include: - `XARGS_REPO_NAME`: the name of the repository targeted - `XARGS_DRY_RUN`: whether `--dry-run` flag was provided Additionally, these changes contain a basic test to ensure this feature works as expected going forward.
…rguments and flags (#127) * Register env vars based on arguments and flags Closes #115 These changes add support for git-xargs registered environment variables based on arguments and flags intended for use by the commands and scripts called by git-xargs. These environment variables start with `XARGS_` to avoid collision with other use cases and include: - `XARGS_REPO_NAME`: the name of the repository targeted - `XARGS_DRY_RUN`: whether `--dry-run` flag was provided Additionally, these changes contain a basic test to ensure this feature works as expected going forward. * README documentation, repository owner env var While updating documentation, I realized that the original intent of issue 115 might require the repository owner information as well as the repository name. This expands the initial changes and performs some minor refactoring.
Describe the solution you'd like
Set the current repo as an environment variable that can be accessed while processing. From the logs it looks like this is available at invocation time
Describe alternatives you've considered
I could parse this out of the
cwd
, but that seems brittle since there's a lot of nonces to prevent collisionsI could also invoke a git command and poke at the output, that involves too much shell cruft and line noise.
Additional context
It's possible this is already implemented or could be solved simpler than I envision.
The text was updated successfully, but these errors were encountered: