Skip to content

Commit

Permalink
Add some extra logging
Browse files Browse the repository at this point in the history
  • Loading branch information
lindell committed Jun 25, 2020
1 parent 18f29ce commit 768a449
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var RootCmd = &cobra.Command{
func init() {
RootCmd.PersistentFlags().StringP("gh-base-url", "g", "", "Base URL of the (v3) GitHub API, needs to be changed if GitHub enterprise is used.")
RootCmd.PersistentFlags().StringP("token", "T", "", "The GitHub personal access token. Can also be set using the GITHUB_TOKEN environment variable.")
RootCmd.PersistentFlags().StringP("log-level", "L", "info", "The level of logging that should be made. Available values: debug, info, error")
RootCmd.PersistentFlags().StringP("log-level", "L", "info", "The level of logging that should be made. Available values: trace, debug, info, error")

RootCmd.AddCommand(RunCmd)
RootCmd.AddCommand(StatusCmd)
Expand Down
4 changes: 2 additions & 2 deletions internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Git struct {
Token string
}

// Clone clones a repository
// Clone a repository
func (g Git) Clone() error {
u, err := url.Parse(g.Repo)
if err != nil {
Expand Down Expand Up @@ -52,7 +52,7 @@ func (g Git) Clone() error {
return err
}

// Commit commits and pushes changes
// Commit and push if any changes has been made to the directory
func (g Git) Commit(commitMessage string) error {
r, err := git.PlainOpen(g.Directory)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion internal/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/google/go-github/v32/github"
log "github.com/sirupsen/logrus"
"golang.org/x/oauth2"

"github.com/lindell/multi-gitter/internal/domain"
Expand Down Expand Up @@ -89,7 +90,6 @@ func (g Github) getRepositories(ctx context.Context, orgName string, page int) (

// CreatePullRequest creates a pull request
func (g Github) CreatePullRequest(ctx context.Context, repository domain.Repository, newPR domain.NewPullRequest) error {

pr, err := g.createPullRequest(ctx, repository, newPR)
if err != nil {
return err
Expand Down Expand Up @@ -152,6 +152,8 @@ func (g Github) GetPullRequestStatuses(ctx context.Context, orgName, branchName

prStatuses := []domain.PullRequest{}
for _, r := range repos {
log := log.WithField("repo", fmt.Sprintf("%s/%s", r.GetOwner().GetLogin(), r.GetName()))
log.Debug("Fetching latest pull request")
prs, _, err := g.ghClient.PullRequests.List(ctx, orgName, r.GetName(), &github.PullRequestListOptions{
Head: fmt.Sprintf("%s:%s", orgName, branchName),
State: "all",
Expand All @@ -175,6 +177,7 @@ func (g Github) GetPullRequestStatuses(ctx context.Context, orgName, branchName
} else if pr.ClosedAt != nil {
status = domain.PullRequestStatusClosed
} else {
log.Debug("Fetching the combined status of the pull request")
combinedStatus, _, err := g.ghClient.Repositories.GetCombinedStatus(ctx, orgName, r.GetName(), pr.GetHead().GetSHA(), nil)
if err != nil {
return nil, err
Expand Down

0 comments on commit 768a449

Please sign in to comment.