Giter VIP home page Giter VIP logo

Comments (2)

andyfeller avatar andyfeller commented on June 21, 2024 1

I would like to expand upon @carusooo's idea (hello, fellow Andy 👋) by also exposing --dry-run flag as environment variable, too. This is essential in order to build safe processes beyond changing content to know whether to affect change or not.

Looking at the code in repo-operations.go, this should be fairly straight forward to include after setting cmd.Dir:

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
logger.WithFields(logrus.Fields{
"Repo": repo.GetName(),
"Directory": repositoryDir,
"Command": config.Args,
}).Debug("Executing command against local clone of repo...")
stdoutStdErr, err := cmd.CombinedOutput()

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()
git-xargs --help usage statement

$ git-xargs.exe --help
Usage: git-xargs.exe [--loglevel] [--github-org] [--draft] [--dry-run] [--skip-pull-requests] [--skip-archived-repos]
[--repo] [--repos] [--branch-name] [--base-branch-name] [--commit-message] [--pull-request-title]
[--pull-request-description] [--reviewers] [--team-reviewers] [--seconds-between-prs] [--max-pr-retries]
[--seconds-to-wait-when-rate-limited] [--no-skip-ci] [--keep-cloned-repositories] [--help] command [options] [args]

git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.

Commands:

   help, h  Shows a list of commands or help for one command

@zackproser : any particular concerns with this approach ☝️? should there be a prefix / namespace for the env vars to avoid clashing with other concerns?

from git-xargs.

andyfeller avatar andyfeller commented on June 21, 2024

@carusooo : check out #127 :fishsticks:

from git-xargs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.