Skip to content

Commit 98fd7d2

Browse files
authored
Fix docs and comments (#51)
- Typo fixes - Formatting fixes - Various small inaccuracies - Code comments fixes
1 parent 19e1e86 commit 98fd7d2

23 files changed

+120
-118
lines changed

README.md

+35-32
Large diffs are not rendered by default.

auth/auth.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ type githubRepositoriesService interface {
2525

2626
// GithubClient is the data structure that is common between production code and test code. In production code,
2727
// go-github satisfies the PullRequests and Repositories service interfaces, whereas in test the concrete
28-
// implementations for these same services are mocks that return a static slice of pointers to github repositories,
29-
// or a single pointer to a github repository, as appropriate. This allows us to test the workflow of git-xargs
30-
// without actually making API calls to Github when running tests
28+
// implementations for these same services are mocks that return a static slice of pointers to GitHub repositories,
29+
// or a single pointer to a GitHub repository, as appropriate. This allows us to test the workflow of git-xargs
30+
// without actually making API calls to GitHub when running tests
3131
type GithubClient struct {
3232
PullRequests githubPullRequestService
3333
Repositories githubRepositoriesService
@@ -40,7 +40,7 @@ func NewClient(client *github.Client) GithubClient {
4040
}
4141
}
4242

43-
// configureGithubClient creates a Github API client using the user-supplied GITHUB_OAUTH_TOKEN and return the configured Github client
43+
// ConfigureGithubClient creates a GitHub API client using the user-supplied GITHUB_OAUTH_TOKEN and returns the configured GitHub client
4444
func ConfigureGithubClient() GithubClient {
4545
// Ensure user provided a GITHUB_OAUTH_TOKEN
4646
GithubOauthToken := os.Getenv("GITHUB_OAUTH_TOKEN")
@@ -57,7 +57,7 @@ func ConfigureGithubClient() GithubClient {
5757
return client
5858
}
5959

60-
// ensureGithubOauthTokenSet is a sanity check that a value is exported for GITHUB_OAUTH_TOKEN
60+
// EnsureGithubOauthTokenSet is a sanity check that a value is exported for GITHUB_OAUTH_TOKEN
6161
func EnsureGithubOauthTokenSet() error {
6262
if os.Getenv("GITHUB_OAUTH_TOKEN") == "" {
6363
return errors.WithStackTrace(types.NoGithubOauthTokenProvidedErr{})

auth/auth_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/stretchr/testify/assert"
88
)
99

10-
// TestConfigureGithubClient performs a sanity check that you can configure a production Github API client
10+
// TestConfigureGithubClient performs a sanity check that you can configure a production GitHub API client
1111
func TestConfigureGithubClient(t *testing.T) {
1212
t.Parallel()
1313

@@ -16,7 +16,7 @@ func TestConfigureGithubClient(t *testing.T) {
1616
}
1717

1818
// TestNoGithubOauthTokenPassed temporarily drops the existing GITHUB_OAUTH_TOKEN env var to ensure that the validation
19-
// code throws an error when it is mising. It then replaces it. This is therefore the one test that cannot be run in
19+
// code throws an error when it is missing. It then replaces it. This is therefore the one test that cannot be run in
2020
// parallel.
2121
func TestNoGithubOAuthTokenPassed(t *testing.T) {
2222
token := os.Getenv("GITHUB_OAUTH_TOKEN")

cmd/git-xargs.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func parseSliceFromReader(reader io.Reader) ([]string, error) {
8888
// handleRepoProcessing encapsulates the main processing logic for the supplied repos and printing the run report that
8989
// is built up throughout the processing
9090
func handleRepoProcessing(config *config.GitXargsConfig) error {
91-
// Track whether or not pull requests were skipped
91+
// Track whether pull requests were skipped
9292
config.Stats.SetSkipPullRequests(config.SkipPullRequests)
9393

9494
// Update raw command supplied
@@ -124,7 +124,7 @@ func sanityCheckInputs(config *config.GitXargsConfig) error {
124124
return nil
125125
}
126126

127-
// runGitXargs is the urfave cli app's Action that is called when the user executes the binary
127+
// RunGitXargs is the urfave cli app's Action that is called when the user executes the binary
128128
func RunGitXargs(c *cli.Context) error {
129129
// If someone calls us with no args at all, show the help text and exit
130130
if !c.Args().Present() {

config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type GitXargsConfig struct {
3030
Stats *stats.RunStats
3131
}
3232

33-
// NewGitXargsConfig sets reasonable defaults for a GitXargsConfig and returns a pointer to a the config
33+
// NewGitXargsConfig sets reasonable defaults for a GitXargsConfig and returns a pointer to the config
3434
func NewGitXargsConfig() *GitXargsConfig {
3535
return &GitXargsConfig{
3636
DryRun: false,

io/io.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
"github.com/sirupsen/logrus"
1212
)
1313

14-
// This utility function accepts a path to the flatfile in which the user has defined their explicitly allowed repos
15-
// It expects repos to be defined one per line in the following format: `gruntwork-io/cloud-nuke` with optional commas
16-
// Stray single and double quotes are also handled and stripped out if they are encountered, and spacing is irrelevant
14+
// ProcessAllowedRepos accepts a path to the flat file in which the user has defined their explicitly allowed repos.
15+
// It expects repos to be defined one per line in the following format: `gruntwork-io/cloud-nuke` with optional commas.
16+
// Stray single and double quotes are also handled and stripped out if they are encountered, and spacing is irrelevant.
1717
func ProcessAllowedRepos(filepath string) ([]*types.AllowedRepo, error) {
1818
logger := logging.GetLogger("git-xargs")
1919

io/io_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestProcessAllowedReposCorrectlyParsesValidReposFile(t *testing.T) {
2525
assert.NoError(t, err)
2626
assert.Equal(t, len(allowedRepos), 3)
2727

28-
// Test that repo names are correctly parsed from the flat file by initiallly setting a map of each repo name
28+
// Test that repo names are correctly parsed from the flat file by initially setting a map of each repo name
2929
// to false, and then updating each entry to true as we find them in the flat file. At the end, all map entries should be true / seen
3030
mapOfExpectedRepoNames := make(map[string]bool)
3131
mapOfExpectedRepoNames["fetch"] = false
@@ -56,7 +56,7 @@ func TestProcessAllowedReposCorrectlyFiltersMalformedInput(t *testing.T) {
5656
// be returned by the function as valid repos to operate on
5757
assert.Equal(t, len(allowedRepos), 3)
5858

59-
// Test that repo names are correctly parsed from the flat file by initiallly setting a map of each repo name
59+
// Test that repo names are correctly parsed from the flat file by initially setting a map of each repo name
6060
// to false, and then updating each entry to true as we find them in the flat file. At the end, all map entries should be true / seen
6161
mapOfExpectedRepoNames := make(map[string]bool)
6262
mapOfExpectedRepoNames["fetch"] = false

io/validate-input.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/gruntwork-io/go-commons/errors"
77
)
88

9-
// Sanity check that user has provided one valid method for selecting repos to operate on
9+
// EnsureValidOptionsPassed checks that user has provided one valid method for selecting repos to operate on
1010
func EnsureValidOptionsPassed(config *config.GitXargsConfig) error {
1111
if len(config.RepoSlice) < 1 && config.ReposFile == "" && config.GithubOrg == "" && len(config.RepoFromStdIn) == 0 {
1212
return errors.WithStackTrace(types.NoRepoSelectionsMadeErr{})

local/local_test.go

-1
This file was deleted.

main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/urfave/cli"
1111
)
1212

13-
// This variable is set at build time using -ldflags parameters. For example, we typically set this flag in circle.yml
13+
// VERSION is set at build time using -ldflags parameters. For example, we typically set this flag in circle.yml
1414
// to the latest Git tag when building our Go apps:
1515
//
1616
// build-go-binaries --app-name my-app --dest-path bin --ld-flags "-X main.VERSION=$CIRCLE_TAG"
@@ -42,7 +42,7 @@ func setupApp() *cli.App {
4242
app := entrypoint.NewApp()
4343
entrypoint.HelpTextLineWidth = 120
4444

45-
// Override the CLI FlagEnvHinter so it only returns the Usage text of the Flag and doesn't apend the envVar text. Original func https://github.com/urfave/cli/blob/master/flag.go#L652
45+
// Override the CLI FlagEnvHinter, so it only returns the Usage text of the Flag and doesn't append the envVar text. Original func https://github.com/urfave/cli/blob/master/flag.go#L652
4646
cli.FlagEnvHinter = func(envVar, str string) string {
4747
return str
4848
}

mocks/mocks.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var MockGithubRepositories = []*github.Repository{
5555
},
5656
}
5757

58-
// This mocks the PullRequest service in go-github that is used in production to call the associated Github endpoint
58+
// This mocks the PullRequest service in go-github that is used in production to call the associated GitHub endpoint
5959
type mockGithubPullRequestService struct {
6060
PullRequest *github.PullRequest
6161
Response *github.Response
@@ -69,7 +69,7 @@ func (m mockGithubPullRequestService) List(ctx context.Context, owner string, re
6969
return []*github.PullRequest{m.PullRequest}, m.Response, nil
7070
}
7171

72-
// This mocks the Repositories service in go-github that is used in production to call the associated Github endpoint
72+
// This mocks the Repositories service in go-github that is used in production to call the associated GitHub endpoint
7373
type mockGithubRepositoriesService struct {
7474
Repository *github.Repository
7575
Repositories []*github.Repository
@@ -84,12 +84,12 @@ func (m mockGithubRepositoriesService) ListByOrg(ctx context.Context, org string
8484
return m.Repositories, m.Response, nil
8585
}
8686

87-
// A convenience method to return a valid GithubClient configured for testing purposes, complete with the mocked services
87+
// ConfigureMockGithubClient returns a valid GithubClient configured for testing purposes, complete with the mocked services
8888
func ConfigureMockGithubClient() auth.GithubClient {
89-
// Call the same NewClient method that is used by the actual CLI to obtain a Github client that calls the
90-
// Github API. In testing, however, we just implement the mock services above to satisfy the interfaces required
89+
// Call the same NewClient method that is used by the actual CLI to obtain a GitHub client that calls the
90+
// GitHub API. In testing, however, we just implement the mock services above to satisfy the interfaces required
9191
// by the GithubClient. GithubClient is used uniformly between production and test code, with the only difference
92-
// being that in test we do not actually execute API calls to Github
92+
// being that in test we do not actually execute API calls to GitHub
9393
client := auth.NewClient(github.NewClient(nil))
9494

9595
testHTMLUrl := "https://github.com/gruntwork-io/test/pull/1"

printer/printer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func PrintRepoReport(allEvents []types.AnnotatedEvent, runReport *types.RunRepor
4040
fmt.Println(runReport.Command)
4141
fmt.Println()
4242

43-
// If the user selected repos via flatfile, print a table showing which repos they were
43+
// If the user selected repos via a flat file, print a table showing which repos they were
4444
if len(runReport.FileProvidedRepos) > 0 {
4545
fmt.Println(" REPOS SUPPLIED VIA --repos FILE FLAG")
4646
fileProvidedReposPrinter.Print(runReport.FileProvidedRepos)

repository/fetch-repos.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/sirupsen/logrus"
1616
)
1717

18-
// getFileDefinedRepos converts user-supplied repositories to Github API response objects that can be further processed
18+
// getFileDefinedRepos converts user-supplied repositories to GitHub API response objects that can be further processed
1919
func getFileDefinedRepos(GithubClient auth.GithubClient, allowedRepos []*types.AllowedRepo, tracker *stats.RunStats) ([]*github.Repository, error) {
2020
logger := logging.GetLogger("git-xargs")
2121

@@ -41,7 +41,7 @@ func getFileDefinedRepos(GithubClient auth.GithubClient, allowedRepos []*types.A
4141
if resp.StatusCode == 404 {
4242
// This repo does not exist / could not be fetched as named, so we won't include it in the list of repos to process
4343

44-
// create an empty github repo object to satisfy the stats tracking interface
44+
// create an empty GitHub repo object to satisfy the stats tracking interface
4545
missingRepo := &github.Repository{
4646
Owner: &github.User{Login: github.String(allowedRepo.Organization)},
4747
Name: github.String(allowedRepo.Name),
@@ -65,7 +65,7 @@ func getFileDefinedRepos(GithubClient auth.GithubClient, allowedRepos []*types.A
6565
return allRepos, nil
6666
}
6767

68-
// getReposByOrg takes the string name of a Github organization and pages through the API to fetch all of its repositories
68+
// getReposByOrg takes the string name of a GitHub organization and pages through the API to fetch all of its repositories
6969
func getReposByOrg(config *config.GitXargsConfig) ([]*github.Repository, error) {
7070

7171
logger := logging.GetLogger("git-xargs")

repository/fetch-repos_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestGetFileDefinedRepos(t *testing.T) {
3838
assert.NoError(t, reposLookupErr)
3939
}
4040

41-
// TestGetReposByOrg ensures that you can pass a configuration specifying repo look up by Github Org to getReposByOrg
41+
// TestGetReposByOrg ensures that you can pass a configuration specifying repo look up by GitHub Org to getReposByOrg
4242
func TestGetReposByOrg(t *testing.T) {
4343
t.Parallel()
4444

repository/process.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ import (
88
"github.com/sirupsen/logrus"
99
)
1010

11-
// Loop through every repo we've selected and use a WaitGroup so that the processing can happen in parallel
11+
// ProcessRepos loops through every repo we've selected and use a WaitGroup so that the processing can happen in parallel
1212
func ProcessRepos(gitxargsConfig *config.GitXargsConfig, repos []*github.Repository) error {
1313
logger := logging.GetLogger("git-xargs")
1414

1515
// Limit the number of concurrent goroutines using the MaxConcurrentRepos config value
16-
// MaxConcurrentRepos == 0 will fallback to unlimited (previous default behavior)
16+
// MaxConcurrentRepos == 0 will fall back to unlimited (previous default behavior)
1717
wg := sizedwaitgroup.New(gitxargsConfig.MaxConcurrentRepos)
1818

1919
for _, repo := range repos {
2020
wg.Add()
2121
go func(gitxargsConfig *config.GitXargsConfig, repo *github.Repository) error {
2222
defer wg.Done()
2323
// For each repo, run the supplied command against it and, if it succeeds without error,
24-
// commit the changes, push the local branch to remote and use the Github API to open a pr
24+
// commit the changes, push the local branch to remote and use the GitHub API to open a pr
2525
processErr := processRepo(gitxargsConfig, repo)
2626
if processErr != nil {
2727
logger.WithFields(logrus.Fields{
@@ -43,7 +43,7 @@ func ProcessRepos(gitxargsConfig *config.GitXargsConfig, repos []*github.Reposit
4343
// 4. Look up any worktree changes (deleted files, modified files, new and untracked files) and ADD THEM ALL to the git stage
4444
// 5. Commit these changes with the optionally configurable git commit message, or fall back to the default if it was not provided by the user
4545
// 6. Push the branch containing the new commit to the remote origin
46-
// 7. Via the Github API, open a pull request of the newly pushed branch against the main branch of the repo
46+
// 7. Via the GitHub API, open a pull request of the newly pushed branch against the main branch of the repo
4747
// 8. Track all successfully opened pull requests via the stats tracker so that we can print them out as part of our final
4848
// run report that is displayed in table format to the operator following each run
4949
func processRepo(config *config.GitXargsConfig, repo *github.Repository) error {
@@ -63,7 +63,7 @@ func processRepo(config *config.GitXargsConfig, repo *github.Repository) error {
6363
return headRefErr
6464
}
6565

66-
// Get the worktree for the given local repository so we can examine any changes made by script operations
66+
// Get the worktree for the given local repository, so we can examine any changes made by script operations
6767
worktree, worktreeErr := getLocalWorkTree(repositoryDir, localRepository, repo)
6868

6969
if worktreeErr != nil {

repository/process_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ func cleanupLocalTestRepoChanges(t *testing.T, config *config.GitXargsConfig) {
4949
if err != nil {
5050
t.Logf("cleanupLocalTestRepoChanges error deleting test branches: %+v\n", err)
5151
} else {
52-
t.Log("cleanupLocalTestRepoChanges succesfully deleted branches in local test repo")
52+
t.Log("cleanupLocalTestRepoChanges successfully deleted branches in local test repo")
5353
}
5454
}

repository/repo-operations.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/gruntwork-io/go-commons/logging"
2424
)
2525

26-
// cloneLocalRepository clones a remote Github repo via SSH to a local temporary directory so that the supplied command
26+
// cloneLocalRepository clones a remote GitHub repo via SSH to a local temporary directory so that the supplied command
2727
// can be run against the repo locally and any git changes handled thereafter. The local directory has
2828
// git-xargs-<repo-name> appended to it to make it easier to find when you are looking for it while debugging
2929
func cloneLocalRepository(config *config.GitXargsConfig, repo *github.Repository) (string, *git.Repository, error) {
@@ -204,7 +204,7 @@ func checkoutLocalBranch(config *config.GitXargsConfig, ref *plumbing.Reference,
204204
if pullErr != nil {
205205

206206
if pullErr == plumbing.ErrReferenceNotFound {
207-
// The suppled branch just doesn't exist yet on the remote - this is not a fatal error and will
207+
// The supplied branch just doesn't exist yet on the remote - this is not a fatal error and will
208208
// allow the new branch to be pushed in pushLocalBranch
209209
config.Stats.TrackSingle(stats.BranchRemoteDidntExistYet, remoteRepository)
210210
return branchName, nil
@@ -263,7 +263,7 @@ func updateRepo(config *config.GitXargsConfig, repositoryDir string, worktree *g
263263
return pushBranchErr
264264
}
265265

266-
// Open a pull request on Github, of the recently pushed branch against the repository default branch
266+
// Open a pull request on GitHub, of the recently pushed branch against the repository default branch
267267
openPullRequestErr := openPullRequest(config, remoteRepository, branchName)
268268
if openPullRequestErr != nil {
269269
return openPullRequestErr
@@ -333,8 +333,8 @@ func commitLocalChanges(status git.Status, config *config.GitXargsConfig, reposi
333333
return nil
334334
}
335335

336-
// pushLocalBranch pushes the branch in the local clone of the /tmp/ directory repository to the Github remote origin
337-
// so that a pull request can be opened against it via the Github API
336+
// pushLocalBranch pushes the branch in the local clone of the /tmp/ directory repository to the GitHub remote origin
337+
// so that a pull request can be opened against it via the GitHub API
338338
func pushLocalBranch(config *config.GitXargsConfig, remoteRepository *github.Repository, localRepository *git.Repository) error {
339339
logger := logging.GetLogger("git-xargs")
340340

@@ -379,7 +379,7 @@ func pushLocalBranch(config *config.GitXargsConfig, remoteRepository *github.Rep
379379
return nil
380380
}
381381

382-
// Attempt to open a pull request via the Github API, of the supplied branch specific to this tool, against the main
382+
// Attempt to open a pull request via the GitHub API, of the supplied branch specific to this tool, against the main
383383
// branch for the remote origin
384384
func openPullRequest(config *config.GitXargsConfig, repo *github.Repository, branch string) error {
385385
logger := logging.GetLogger("git-xargs")
@@ -435,7 +435,7 @@ func openPullRequest(config *config.GitXargsConfig, repo *github.Repository, bra
435435
}
436436
}
437437

438-
// Configure pull request options that the Github client accepts when making calls to open new pull requests
438+
// Configure pull request options that the GitHub client accepts when making calls to open new pull requests
439439
newPR := &github.NewPullRequest{
440440
Title: github.String(titleToUse),
441441
Head: github.String(branch),
@@ -444,7 +444,7 @@ func openPullRequest(config *config.GitXargsConfig, repo *github.Repository, bra
444444
MaintainerCanModify: github.Bool(true),
445445
}
446446

447-
// Make a pull request via the Github API
447+
// Make a pull request via the GitHub API
448448
pr, _, err := config.GithubClient.PullRequests.Create(context.Background(), *repo.GetOwner().Login, repo.GetName(), newPR)
449449

450450
if err != nil {

0 commit comments

Comments
 (0)