Skip to content

Commit 513808c

Browse files
authored
Merge pull request #34 from github/logrus
Use Logrus for logging.
2 parents cb31118 + a4598c2 commit 513808c

File tree

7 files changed

+64
-24
lines changed

7 files changed

+64
-24
lines changed

.licenses/go/github.com/sirupsen/logrus.dep.yml

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/markbates/pkger v0.17.0
1010
github.com/mitchellh/ioprogress v0.0.0-20180201004757-6a23b12fa88e
1111
github.com/pkg/errors v0.8.1
12+
github.com/sirupsen/logrus v1.2.0
1213
github.com/spf13/cobra v1.0.0
1314
github.com/spf13/pflag v1.0.5 // indirect
1415
github.com/stretchr/testify v1.6.1

go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/pull/pull.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66
"fmt"
77
"io"
88
"io/ioutil"
9-
"log"
109
"net/http"
1110
"os"
1211
"regexp"
1312

13+
log "github.com/sirupsen/logrus"
14+
1415
"github.com/github/codeql-action-sync/internal/actionconfiguration"
1516
"github.com/mitchellh/ioprogress"
1617
"golang.org/x/oauth2"
@@ -44,9 +45,9 @@ type pullService struct {
4445

4546
func (pullService *pullService) pullGit(fresh bool) error {
4647
if fresh {
47-
log.Print("Pulling Git contents fresh...")
48+
log.Debug("Pulling Git contents fresh...")
4849
} else {
49-
log.Print("Updating Git contents...")
50+
log.Debug("Updating Git contents...")
5051
}
5152
gitPath := pullService.cacheDirectory.GitPath()
5253

@@ -107,7 +108,7 @@ func (pullService *pullService) pullGit(fresh bool) error {
107108
}
108109

109110
func (pullService *pullService) findRelevantReleases() ([]string, error) {
110-
log.Print("Finding release references...")
111+
log.Debug("Finding release references...")
111112
localRepository, err := git.PlainOpen(pullService.cacheDirectory.GitPath())
112113
if err != nil {
113114
return []string{}, errors.Wrap(err, "Error opening Git repository cache.")
@@ -121,15 +122,15 @@ func (pullService *pullService) findRelevantReleases() ([]string, error) {
121122
releases := []string{}
122123
err = references.ForEach(func(reference *plumbing.Reference) error {
123124
if relevantReferences.MatchString(reference.Name().String()) {
124-
log.Printf("Found %s.", reference.Name().String())
125+
log.Debugf("Found %s.", reference.Name().String())
125126
commit, err := localRepository.CommitObject(reference.Hash())
126127
if err != nil {
127128
return errors.Wrap(err, fmt.Sprintf("Error loading commit %s for reference %s.", reference.Hash(), reference.Name().String()))
128129
}
129130
file, err := commit.File(defaultConfigurationPath)
130131
if err != nil {
131132
if err == object.ErrFileNotFound {
132-
log.Printf("Ignoring reference %s as it does not have a default configuration.", reference.Name().String())
133+
log.Debugf("Ignoring reference %s as it does not have a default configuration.", reference.Name().String())
133134
return nil
134135
}
135136
return errors.Wrap(err, fmt.Sprintf("Error loading default configuration file from commit %s for reference %s.", reference.Hash(), reference.Name().String()))
@@ -156,14 +157,14 @@ func (pullService *pullService) findRelevantReleases() ([]string, error) {
156157
}
157158

158159
func (pullService *pullService) pullReleases() error {
159-
log.Print("Pulling CodeQL bundles...")
160+
log.Debug("Pulling CodeQL bundles...")
160161
relevantReleases, err := pullService.findRelevantReleases()
161162
if err != nil {
162163
return err
163164
}
164165

165166
for index, releaseTag := range relevantReleases {
166-
log.Printf("Pulling CodeQL bundle %s (%d/%d)...", releaseTag, index+1, len(relevantReleases))
167+
log.Debugf("Pulling CodeQL bundle %s (%d/%d)...", releaseTag, index+1, len(relevantReleases))
167168
release, _, err := pullService.githubDotComClient.Repositories.GetReleaseByTag(pullService.ctx, sourceOwner, sourceRepository, releaseTag)
168169
if err != nil {
169170
return errors.Wrap(err, "Error loading CodeQL release information.")
@@ -187,11 +188,11 @@ func (pullService *pullService) pullReleases() error {
187188
return errors.Wrap(err, "Error creating assets directory.")
188189
}
189190
for _, asset := range release.Assets {
190-
log.Printf("Downloading asset %s...", asset.GetName())
191+
log.Debugf("Downloading asset %s...", asset.GetName())
191192
downloadPath := pullService.cacheDirectory.AssetPath(releaseTag, asset.GetName())
192193
downloadPathStat, err := os.Stat(downloadPath)
193194
if err == nil && downloadPathStat.Size() == int64(asset.GetSize()) {
194-
log.Println("Asset is already in cache.")
195+
log.Debug("Asset is already in cache.")
195196
continue
196197
}
197198
err = os.RemoveAll(downloadPath)
@@ -275,6 +276,6 @@ func Pull(ctx context.Context, cacheDirectory cachedirectory.CacheDirectory, sou
275276
if err != nil {
276277
return err
277278
}
278-
log.Print("Finished pulling the CodeQL Action repository and bundles!")
279+
log.Info("Finished pulling the CodeQL Action repository and bundles!")
279280
return nil
280281
}

internal/push/push.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import (
66
"fmt"
77
"io"
88
"io/ioutil"
9-
"log"
109
"mime"
1110
"net/http"
1211
"net/url"
1312
"os"
1413
"path/filepath"
1514
"strings"
1615

16+
log "github.com/sirupsen/logrus"
17+
1718
"github.com/github/codeql-action-sync/internal/cachedirectory"
1819
"github.com/github/codeql-action-sync/internal/version"
1920
"github.com/go-git/go-git/v5"
@@ -41,7 +42,7 @@ type pushService struct {
4142
}
4243

4344
func (pushService *pushService) createRepository() (*github.Repository, error) {
44-
log.Printf("Ensuring repository exists...")
45+
log.Debug("Ensuring repository exists...")
4546
user, _, err := pushService.githubEnterpriseClient.Users.Get(pushService.ctx, "")
4647
if err != nil {
4748
return nil, errors.Wrap(err, "Error getting current user.")
@@ -59,7 +60,7 @@ func (pushService *pushService) createRepository() (*github.Repository, error) {
5960
return nil, errors.Wrap(err, "Error checking if destination organization exists.")
6061
}
6162
if response.StatusCode == http.StatusNotFound {
62-
log.Printf("The organization %s does not exist. Creating it...", pushService.destinationRepositoryOwner)
63+
log.Debugf("The organization %s does not exist. Creating it...", pushService.destinationRepositoryOwner)
6364
_, _, err := pushService.githubEnterpriseClient.Admin.CreateOrg(pushService.ctx, &github.Organization{
6465
Login: github.String(pushService.destinationRepositoryOwner),
6566
Name: github.String(pushService.destinationRepositoryOwner),
@@ -106,9 +107,9 @@ func (pushService *pushService) createRepository() (*github.Repository, error) {
106107
func (pushService *pushService) pushGit(repository *github.Repository, initialPush bool) error {
107108
remoteURL := repository.GetCloneURL()
108109
if initialPush {
109-
log.Printf("Pushing Git releases to %s...", remoteURL)
110+
log.Debugf("Pushing Git releases to %s...", remoteURL)
110111
} else {
111-
log.Printf("Pushing Git references to %s...", remoteURL)
112+
log.Debugf("Pushing Git references to %s...", remoteURL)
112113
}
113114
gitRepository, err := git.PlainOpen(pushService.cacheDirectory.GitPath())
114115
if err != nil {
@@ -190,7 +191,7 @@ func (pushService *pushService) createOrUpdateRelease(releaseName string) (*gith
190191
return nil, errors.Wrap(err, "Error checking for existing CodeQL release.")
191192
}
192193
if release == nil {
193-
log.Printf("Creating release %s...", releaseMetadata.GetTagName())
194+
log.Debugf("Creating release %s...", releaseMetadata.GetTagName())
194195
release, _, err := pushService.githubEnterpriseClient.Repositories.CreateRelease(pushService.ctx, pushService.destinationRepositoryOwner, pushService.destinationRepositoryName, &releaseMetadata)
195196
if err != nil {
196197
return nil, errors.Wrap(err, "Error creating release.")
@@ -199,7 +200,7 @@ func (pushService *pushService) createOrUpdateRelease(releaseName string) (*gith
199200
}
200201
release, _, err = pushService.githubEnterpriseClient.Repositories.EditRelease(pushService.ctx, pushService.destinationRepositoryOwner, pushService.destinationRepositoryName, release.GetID(), &releaseMetadata)
201202
if err != nil {
202-
log.Printf("Updating release %s...", releaseMetadata.GetTagName())
203+
log.Debugf("Updating release %s...", releaseMetadata.GetTagName())
203204
return nil, errors.Wrap(err, "Error updating release.")
204205
}
205206
return release, nil
@@ -231,7 +232,7 @@ func (pushService *pushService) createOrUpdateReleaseAsset(release *github.Repos
231232
}
232233
}
233234
}
234-
log.Printf("Uploading release asset %s...", assetPathStat.Name())
235+
log.Debugf("Uploading release asset %s...", assetPathStat.Name())
235236
assetFile, err := os.Open(pushService.cacheDirectory.AssetPath(release.GetTagName(), assetPathStat.Name()))
236237
defer assetFile.Close()
237238
progressReader := &ioprogress.Reader{
@@ -250,7 +251,7 @@ func (pushService *pushService) createOrUpdateReleaseAsset(release *github.Repos
250251
}
251252

252253
func (pushService *pushService) pushReleases() error {
253-
log.Print("Pushing CodeQL bundles...")
254+
log.Debugf("Pushing CodeQL bundles...")
254255
releasesPath := pushService.cacheDirectory.ReleasesPath()
255256

256257
releasePathStats, err := ioutil.ReadDir(releasesPath)
@@ -348,6 +349,6 @@ func Push(ctx context.Context, cacheDirectory cachedirectory.CacheDirectory, des
348349
if err != nil {
349350
return err
350351
}
351-
log.Printf("Finished pushing CodeQL Action to %s!", destinationRepository)
352+
log.Infof("Finished pushing CodeQL Action to %s!", destinationRepository)
352353
return nil
353354
}

internal/version/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package version
22

3-
import "log"
3+
import log "github.com/sirupsen/logrus"
44

55
var version = "development"
66
var commit = "0000000000000000000000000000000000000000"
@@ -14,5 +14,5 @@ func Commit() string {
1414
}
1515

1616
func LogVersion() {
17-
log.Printf("Starting CodeQL Action sync tool version %s...", Version())
17+
log.Infof("Starting CodeQL Action sync tool version %s...", Version())
1818
}

main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ package main
22

33
import (
44
"context"
5-
"log"
65
"os"
76

7+
log "github.com/sirupsen/logrus"
8+
89
"github.com/github/codeql-action-sync/cmd"
910
)
1011

1112
func main() {
13+
log.SetLevel(log.DebugLevel)
1214
ctx := context.Background()
1315
if err := cmd.Execute(ctx); err != nil {
1416
if err == cmd.SilentErr {

0 commit comments

Comments
 (0)