-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
handle PR files pages #60
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,14 +89,15 @@ func GetFilterForMilestone(milestoneRaw string) *Filter { | |
PR: func(pr github.PullRequest) (bool, error) { | ||
milestone := pr.GetMilestone().GetTitle() | ||
|
||
// nolint:gocritic | ||
//nolint:gocritic | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cli/gh-pr-filters.go:92:4: directive
|
||
if strings.EqualFold(filterMilestone, milestone) && !negate { | ||
c.Printf(" milestone: <green>%s</> <gray>(%s)</>\n", filterMilestone, milestone) | ||
return true, nil | ||
} else if negate { | ||
c.Printf(" milestone: <green>-%s</> <gray>(%s)</>\n", filterMilestone, milestone) | ||
return true, nil | ||
} else { | ||
//revive:disable:indent-error-flow | ||
c.Printf(" milestone: <red>%s</> <gray>(%s)</>\n", filterMilestone, milestone) | ||
return false, nil | ||
} | ||
Comment on lines
99
to
103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cli/gh-pr-filters.go:99:11: indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)
|
||
|
@@ -207,7 +208,7 @@ func GetFilterForLabels(labels []string, and bool) *Filter { | |
for filterLabel, negate := range filterLabelMap { | ||
_, found := labelMap[filterLabel] | ||
|
||
// nolint:gocritic | ||
//nolint:gocritic | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cli/gh-pr-filters.go:210:5: directive
|
||
if found && !negate { | ||
orPass = true | ||
c.Printf(" <green>%s</>", filterLabel) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,10 +43,9 @@ func (f FlagData) GetPrTests(pr int) (*map[string][]string, error) { | |
} | ||
|
||
// todo break this apart - get/check PR state, get files, filter/process files, get tests, get services. | ||
func (gr githubRepo) PrTests(pri int, filterRegExStr, splitTestsAt string) (*map[string][]string, error) { | ||
func (gr GithubRepo) PrTests(pri int, filterRegExStr, splitTestsAt string) (*map[string][]string, error) { | ||
client, ctx := gr.NewClient() | ||
httpClient := chttp.NewHTTPClient("HTTP") | ||
fileRegEx := regexp.MustCompile(filterRegExStr) | ||
|
||
clog.Log.Debugf("fetching data for PR %s/%s/#%d...", gr.Owner, gr.Name, pri) | ||
pr, _, err := client.PullRequests.Get(ctx, gr.Owner, gr.Name, pri) | ||
|
@@ -60,56 +59,15 @@ func (gr githubRepo) PrTests(pri int, filterRegExStr, splitTestsAt string) (*map | |
} | ||
|
||
clog.Log.Tracef("listing files...") | ||
files, _, err := client.PullRequests.ListFiles(ctx, gr.Owner, gr.Name, pri, nil) | ||
filesFiltered, err := gr.GetAllPullRequestFiles(pri, filterRegExStr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// filter out uninteresting files and convert non test files to test files and only retain unique | ||
filesFiltered := map[string]bool{} | ||
clog.Log.Debugf(" filtering files (%s)", filterRegExStr) | ||
for _, f := range files { | ||
if f.Filename == nil { | ||
continue | ||
} | ||
|
||
name := *f.Filename | ||
clog.Log.Debugf(" %v", *f.Filename) | ||
|
||
// if in service package mode skip some files | ||
if strings.Contains(name, "/services/") { | ||
if strings.Contains(name, "/client/") || strings.Contains(name, "/parse/") || strings.Contains(name, "/validate/") { | ||
continue | ||
} | ||
|
||
if strings.HasSuffix(name, "registration.go") || strings.HasSuffix(name, "resourceids.go") { | ||
continue | ||
} | ||
} | ||
|
||
if strings.HasSuffix(name, "_test.go") { | ||
filesFiltered[name] = true | ||
continue | ||
} | ||
|
||
if !fileRegEx.MatchString(name) { | ||
continue | ||
} | ||
|
||
f := strings.Replace(name, ".go", "_test.go", 1) | ||
filesFiltered[f] = true | ||
} | ||
clog.Log.Debugf(" FOUND %d", len(filesFiltered)) | ||
|
||
if len(filesFiltered) == 0 { | ||
return nil, fmt.Errorf("found no files matching: %s", filterRegExStr) | ||
return nil, fmt.Errorf("failed to get PR files for %s/%s/pull/%d: %w", gr.Owner, gr.Name, pri, err) | ||
} | ||
// log.Println(files) TODO debug message here | ||
|
||
// for each file get content and parse out test files & services | ||
serviceTestMap := map[string]map[string]bool{} | ||
clog.Log.Debugf(" parsing content:") | ||
for f := range filesFiltered { | ||
for f := range *filesFiltered { | ||
testRegEx := regexp.MustCompile("func Test") | ||
|
||
clog.Log.Debugf(" download %s", f) | ||
|
@@ -136,7 +94,7 @@ func (gr githubRepo) PrTests(pri int, filterRegExStr, splitTestsAt string) (*map | |
} | ||
|
||
// todo thread ctx | ||
// nolint: noctx | ||
//nolint: noctx | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cli/gh-pr.go:97:3: directive
|
||
resp, err := httpClient.Get(*fileContents.DownloadURL) | ||
if err != nil { | ||
return nil, fmt.Errorf("downloading file (%s): %w", f, err) | ||
|
@@ -192,3 +150,82 @@ func (gr githubRepo) PrTests(pri int, filterRegExStr, splitTestsAt string) (*map | |
|
||
return &serviceTests, nil | ||
} | ||
|
||
func (gr GithubRepo) ListAllPullRequestFiles(pri int, cb func([]*github.CommitFile, *github.Response) error) error { | ||
client, ctx := gr.NewClient() | ||
|
||
opts := &github.ListOptions{ | ||
Page: 1, | ||
PerPage: 100, | ||
} | ||
|
||
for { | ||
clog.Log.Debugf("Listing all files for %s/%s/pull/%d (Page %d)...", gr.Owner, gr.Name, pri, opts.Page) | ||
files, resp, err := client.PullRequests.ListFiles(ctx, gr.Owner, gr.Name, pri, opts) | ||
if err != nil { | ||
return fmt.Errorf("unable to list files for %s/%s/pull/%d (Page %d): %w", gr.Owner, gr.Name, pri, opts.Page, err) | ||
} | ||
|
||
if err = cb(files, resp); err != nil { | ||
return fmt.Errorf("callback failed for %s/%s/pull/%d (Page %d): %w", gr.Owner, gr.Name, pri, opts.Page, err) | ||
} | ||
|
||
if resp.NextPage == 0 { | ||
break | ||
} | ||
opts.Page = resp.NextPage | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (gr GithubRepo) GetAllPullRequestFiles(pri int, filterRegExStr string) (*map[string]struct{}, error) { | ||
result := make(map[string]struct{}) | ||
filterRegEx := regexp.MustCompile(filterRegExStr) | ||
|
||
err := gr.ListAllPullRequestFiles(pri, func(files []*github.CommitFile, resp *github.Response) error { | ||
for _, f := range files { | ||
if f.Filename == nil { | ||
continue | ||
} | ||
|
||
name := *f.Filename | ||
clog.Log.Debugf(" %v", *f.Filename) | ||
|
||
// if in service package mode skip some files | ||
if strings.Contains(name, "/services/") { | ||
if strings.Contains(name, "/client/") || strings.Contains(name, "/parse/") || strings.Contains(name, "/validate/") { | ||
continue | ||
} | ||
|
||
if strings.HasSuffix(name, "registration.go") || strings.HasSuffix(name, "resourceids.go") { | ||
continue | ||
} | ||
} | ||
|
||
if strings.HasSuffix(name, "_test.go") { | ||
result[name] = struct{}{} | ||
continue | ||
} | ||
|
||
if !filterRegEx.MatchString(name) { | ||
continue | ||
} | ||
|
||
f := strings.Replace(name, ".go", "_test.go", 1) | ||
result[f] = struct{}{} | ||
} | ||
|
||
return nil | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get all files for %s/%s/pull/%d: %w", gr.Owner, gr.Name, pri, err) | ||
} | ||
|
||
clog.Log.Debugf(" FOUND %d", len(result)) | ||
for f := range result { | ||
clog.Log.Debugf(" %s", f) | ||
} | ||
|
||
return &result, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,11 @@ import ( | |
) | ||
|
||
// wrap the common gh lib shared with my other tools. splits common GH code from this CLI tool's specific tooling code | ||
type githubRepo struct { | ||
type GithubRepo struct { | ||
gh.Repo | ||
} | ||
|
||
func (f FlagData) NewRepo() githubRepo { | ||
func (f FlagData) NewRepo() GithubRepo { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cli/gh.go:15:29: unexported-return: exported method NewRepo returns unexported type cli.githubRepo, which can be annoying to use (revive)
|
||
ownerrepo := f.GH.Repo | ||
|
||
parts := strings.Split(ownerrepo, "/") | ||
|
@@ -24,5 +24,5 @@ func (f FlagData) NewRepo() githubRepo { | |
token := f.GH.Token | ||
clog.Log.Debugf("new gh: %s@%s/%s", token, owner, repo) | ||
|
||
return githubRepo{gh.NewRepo(owner, repo, token)} | ||
return GithubRepo{gh.NewRepo(owner, repo, token)} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,10 @@ import ( | |
) | ||
|
||
// wrap the common gh lib shared with my other tools. splits common GH code from this CLI tool's specific tooling code | ||
type tcServer struct { | ||
type TcServer struct { | ||
tc.Server | ||
} | ||
|
||
func (f FlagData) NewServer() tcServer { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cli/tc.go:12:31: unexported-return: exported method NewServer returns unexported type cli.tcServer, which can be annoying to use (revive)
|
||
return tcServer{tc.NewServer(f.TC.ServerURL, f.TC.Token, f.TC.User, f.TC.Pass)} | ||
func (f FlagData) NewServer() TcServer { | ||
return TcServer{tc.NewServer(f.TC.ServerURL, f.TC.Token, f.TC.User, f.TC.Pass)} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,12 @@ func NewHTTPClient(name string) *http.Client { | |
} | ||
} | ||
|
||
type transport struct { | ||
type Transport struct { | ||
name string | ||
transport http.RoundTripper | ||
} | ||
|
||
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) { | ||
func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) { | ||
reqData, err := httputil.DumpRequestOut(req, true) | ||
|
||
if err == nil { | ||
|
@@ -47,8 +47,8 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) { | |
return resp, nil | ||
} | ||
|
||
func NewTransport(name string, t http.RoundTripper) *transport { | ||
return &transport{name, t} | ||
func NewTransport(name string, t http.RoundTripper) *Transport { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lib/chttp/http.go:50:53: unexported-return: exported func NewTransport returns unexported type *chttp.transport, which can be annoying to use (revive)
|
||
return &Transport{name, t} | ||
} | ||
|
||
// prettyPrintJSON iterates through a []byte line-by-line, | ||
|
@@ -58,7 +58,7 @@ func prettyPrintJSON(b []byte) string { | |
for i, p := range parts { | ||
if b := []byte(p); json.Valid(b) { | ||
var out bytes.Buffer | ||
// nolint:errcheck | ||
//nolint:errcheck | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lib/chttp/http.go:61:4: directive
|
||
json.Indent(&out, b, "", " ") | ||
parts[i] = out.String() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARN [runner] The linter 'varcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused.
WARN [runner] The linter 'deadcode' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused.
WARN [runner] The linter 'ifshort' is deprecated (since v1.48.0) due to: The repository of the linter has been deprecated by the owner.
WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused.