Skip to content
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

fixes issues 26 & 46. Added support for pagination #83

Closed
wants to merge 3 commits into from

Conversation

m-bal
Copy link
Contributor

@m-bal m-bal commented Jan 4, 2021

FetchTags only returns the first 30 tags so

fetch --repo https://github.com/gruntwork-io/terratest --tag="<0.2.0" ./LocalDir

fails with ... Tag does not exist because terratest has 200+ tags and 0.2.0 isn't in the first 30 tags.

I increased the per_page result to 100 and added a loop to get the next link from the link header.

I believe this fixes both issue #26 and #46.

Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

github.go Outdated Show resolved Hide resolved
github.go Outdated Show resolved Hide resolved
m-bal and others added 2 commits January 9, 2021 19:47
Co-authored-by: Yevgeniy Brikman <[email protected]>
Used Regex to parse Link headers instead of splits and index arthemtic.
getNextPath now returns `string` and `*FetchError`.
@m-bal m-bal requested a review from brikis98 January 20, 2021 08:21
Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates!

return "", nil
}

nextLinkRegex, regexErr := regexp.Compile(`<(.+?)>;\s+rel="next"`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the regex here, it's rel="next" (in double quotes), but in the comment on line 217, it's rel=next (no double quotes). Which is correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Also, this regex can be defined outside of this function once (e.g., at the top of github.go), with MustCompile, rather than each time this function is called.

if regexErr != nil {
return "", wrapError(regexErr)
}
pathRegex, regexErr := regexp.Compile(`([^\/]+$)`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: same with compiling this one outside the function.

}

for _, tc := range cases {
nextPath, err := getNextPath(tc.links)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: wrap the body of the for-loop in:

t.Run("<UNIQUE TEST NAME>", func(t *testing.T) {
  // The body
})

That way, each test is run as a separate sub-test, and it's clearer what failed.

Comment on lines +76 to +78
if err != nil {
t.Fatalf("error getting next path: %s", err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err != nil {
t.Fatalf("error getting next path: %s", err)
}
require.NoError(t, err)

Comment on lines +80 to +82
if nextPath != tc.expectedNextPath {
t.Fatalf("Expected next path %s, but got %s", tc.expectedNextPath, nextPath)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if nextPath != tc.expectedNextPath {
t.Fatalf("Expected next path %s, but got %s", tc.expectedNextPath, nextPath)
}
require.Equal(t, tc.expectedNextPath, nextPath)

@brikis98
Copy link
Member

Alright, I may have to wrap this PR up myself... I'm going to create a new PR with your commits, and fix the final few issues on top of that.

@brikis98
Copy link
Member

OK, I've opened #85 to wrap this up. Thanks!

@brikis98 brikis98 closed this Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants