Skip to content

Commit 53322e4

Browse files
authored
Prepend [skip ci] to commit messages by default (#89)
- Allow users to opt-out of this behavior via the new --no-skip-ci flag
1 parent 9464c8e commit 53322e4

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ echo "gruntwork-io/terragrunt gruntwork-io/terratest" | git-xargs \
412412
| `--repos` | If you want to specify many repos and manage them in files (which makes batching and testing easier) then use this flag to pass the filepath to a repos file. See [the repos file format](#option-2-flat-file-of-repository-names) for more information. | String | No |
413413
| `--repo` | Use this flag to specify a single repo, e.g., `--repo gruntwork-io/cloud-nuke`. Can be passed multiple times to target several repos. | String | No |
414414
| `--github-org` | If you want to target every repo in a Github org that your GITHUB_OAUTH_TOKEN has access to, pass the name of the Organization with this flag, to page through every repo via the Github API and target it. | String | No |
415-
| `--commit-message` | The commit message to use when creating commits. If you supply this flag, but neither the optional `--pull-request-title` or `--pull-request-description` flags, then the commit message value will be used for all three. Default: `git-xargs programmatic commit`. | String | No |
415+
| `--commit-message` | The commit message to use when creating commits. If you supply this flag, but neither the optional `--pull-request-title` or `--pull-request-description` flags, then the commit message value will be used for all three. Default: `[skip ci] git-xargs programmatic commit`. Note that, by default, git-xargs will prepend \"[skip ci]\" to commit messages unless you pass the `--no-skip-ci` flag. If you wish to use an alternative prefix other than [skip ci], you can add the literal string to your --commit-message value. | String | No |
416416
| `--skip-pull-requests` | If you don't want any pull requests opened, but would rather have your changes committed directly to your specified branch, pass this flag. Note that it won't work if your Github repo is configured with branch protections on the branch you're trying to commit directly to! Default: `false`. | Boolean | No |
417417
| `--skip-archived-repos` | If you want to exclude archived (read-only) repositories from the list of targeted repos, pass this flag. Default: `false`. | Boolean | No |
418418
| `--dry-run` | If you are in the process of testing out `git-xargs` or your initial set of targeted repos, but you don't want to make any changes via the Github API (pushing your local changes or opening pull requests) you can pass the dry-run flag. This is useful because the output report will still tell you which repos would have been affected, without actually making changes via the Github API to your remote repositories. Default: `false`. | Boolean | No |
@@ -421,6 +421,7 @@ echo "gruntwork-io/terragrunt gruntwork-io/terratest" | git-xargs \
421421
| `--seconds-between-prs` | The number of seconds to wait between opening serial pull requests. If you are being rate limited, continue to increase this value until rate limiting eases. Note, this value cannot be negative, so if you pass a value less than 1, the seconds to wait between pull requests will be set to 1 second. Default: `1` second. | Integer | No |
422422
| `--max-pr-retries` | The number of seconds to wait between opening serial pull requests. If you are being rate limited, continue to increase this value until rate limiting eases. Default: `3` seconds. | Integer | No |
423423
| `--seconds-to-wait-when-rate-limited` | The number of seconds to pause once git-xargs has detected it has been rate limited. Note that this buffer is in addition to the value of --seconds-between-prs. If you are regularly being rate limited, increase this value until rate limiting eases. Default: `60` seconds. | Integer | No |
424+
| `--no-skip-ci` | By default, git-xargs will prepend \"[skip ci]\" to its commit messages to prevent large git-xargs jobs from creating expensive CI jobs excessively. If you pass the `--no-skip-ci` flag, then git-xargs will not prepend \"[skip ci]\". Default: false, meaning that \"[skip ci]\" will be prepended to commit messages. | Bool | No |
424425

425426
## Best practices, tips and tricks
426427

cmd/git-xargs.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"bufio"
5+
"fmt"
56
"io"
67
"os"
78
"strings"
@@ -38,6 +39,12 @@ func parseGitXargsConfig(c *cli.Context) (*config.GitXargsConfig, error) {
3839
config.SecondsToSleepBetweenPRs = c.Int("seconds-between-prs")
3940
config.PullRequestRetries = c.Int("max-pr-retries")
4041
config.SecondsToSleepWhenRateLimited = c.Int("seconds-to-wait-when-rate-limited")
42+
config.NoSkipCI = c.Bool("no-skip-ci")
43+
// By default, prepend "[skip ci]" to commit messages, unless the user passed --no-skip-ci
44+
if config.NoSkipCI == false {
45+
commitMsgWithCISkip := fmt.Sprintf("%s %s", "[skip ci]", config.CommitMessage)
46+
config.CommitMessage = commitMsgWithCISkip
47+
}
4148

4249
// A non-positive ticker value won't work, so set to the default minimum if user passed a bad value
4350
tickerVal := c.Int("seconds-between-prs")

common/common.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
DefaultPullRequestDescription = "git-xargs programmatic pull request"
2323
MaxPullRequestRetriesFlagName = "max-pr-retries"
2424
SecondsToWaitWhenRateLimitedFlagName = "seconds-to-wait-when-rate-limited"
25+
NoSkipCIFlagName = "no-skip-ci"
2526
DefaultMaxConcurrentRepos = 0
2627
DefaultSecondsBetweenPRs = 1
2728
DefaultMaxPullRequestRetries = 3
@@ -100,4 +101,8 @@ var (
100101
Usage: "The number of additional seconds to sleep before attempting to open a PR again, when rate limited by GitHub. Defaults to 60.",
101102
Value: DefaultSecondsToWaitWhenRateLimited,
102103
}
104+
GenericNoSkipCIFlag = cli.BoolFlag{
105+
Name: NoSkipCIFlagName,
106+
Usage: "By default, git-xargs prepends \"[skip ci]\" to its commit messages. Pass this flag to prevent \"[skip ci]\" from being prepending to commit messages.",
107+
}
103108
)

config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type GitXargsConfig struct {
3636
SecondsToSleepBetweenPRs int
3737
PullRequestRetries int
3838
SecondsToSleepWhenRateLimited int
39+
NoSkipCI bool
3940
Ticker *time.Ticker
4041
}
4142

@@ -64,11 +65,11 @@ func NewGitXargsConfig() *GitXargsConfig {
6465
SecondsToSleepBetweenPRs: common.DefaultSecondsBetweenPRs,
6566
SecondsToSleepWhenRateLimited: common.DefaultSecondsToWaitWhenRateLimited,
6667
PullRequestRetries: common.DefaultMaxPullRequestRetries,
68+
NoSkipCI: false,
6769
}
6870
}
6971

7072
func NewGitXargsTestConfig() *GitXargsConfig {
71-
7273
config := NewGitXargsConfig()
7374

7475
uniqueID := util.RandStringBytes(9)

main.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ import (
1818
// For more info, see: http://stackoverflow.com/a/11355611/483528
1919
var VERSION string
2020

21-
var (
22-
LogLevelFlag = cli.StringFlag{
23-
Name: "loglevel",
24-
Value: logrus.InfoLevel.String(),
25-
}
26-
)
21+
var LogLevelFlag = cli.StringFlag{
22+
Name: "loglevel",
23+
Value: logrus.InfoLevel.String(),
24+
}
2725

2826
// initCli initializes the CLI app before any command is actually executed. This function will handle all the setup
2927
// code, such as setting up the logger with the appropriate log level.
@@ -77,6 +75,7 @@ func setupApp() *cli.App {
7775
common.GenericSecondsToWaitFlag,
7876
common.GenericMaxPullRequestRetriesFlag,
7977
common.GenericSecondsToWaitWhenRateLimitedFlag,
78+
common.GenericNoSkipCIFlag,
8079
}
8180

8281
app.Action = cmd.RunGitXargs

0 commit comments

Comments
 (0)