-
-
Notifications
You must be signed in to change notification settings - Fork 12k
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
tests: add repository maturity test #5492
base: main
Are you sure you want to change the base?
Conversation
http.DefaultClient.Timeout = time.Minute | ||
httpRes, err := http.DefaultClient.Do(request) |
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.
I would have created a dedicated client, and not playing with the default one
|
||
request.Header.Set("Accept", "application/vnd.github+json") | ||
request.Header.Set("X-GitHub-Api-Version", "2022-11-28") | ||
request.Header.Set("User-Agent", "avelino") |
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.
The user agent could be a env variable too. And you should have a default one, one that respect the UserAgent format
) | ||
|
||
var ( | ||
githubApiAuthorizationToken = os.Getenv("GITHUB_API_TOKEN") |
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.
githubApiAuthorizationToken = os.Getenv("GITHUB_API_TOKEN") | |
githubAPIAuthorizationToken = os.Getenv("GITHUB_API_TOKEN") |
Or to respect the GitHub syntax
githubApiAuthorizationToken = os.Getenv("GITHUB_API_TOKEN") | |
apiTokenGitHub = os.Getenv("GITHUB_API_TOKEN") |
t.Fatalf("failed to extract repo and user from: %s, got [%v]", href, strings.Join(matches, ", ")) | ||
} | ||
|
||
if err := checkRepositoryMaturity(matches[1], matches[2]); err != nil { |
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.
Ypu could use meaningful variable
if err := checkRepositoryMaturity(matches[1], matches[2]); err != nil { | |
user, repo := matches[1], matches[2] | |
if err := checkRepositoryMaturity(user, repo); err != nil { |
http.DefaultClient.Timeout = time.Minute | ||
httpRes, err := http.DefaultClient.Do(request) | ||
if err != nil { | ||
return fmt.Errorf("failed to fetch commits for [%s/%s], %v", user, repo, err) |
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.
When something is repeated like %s/%s + user, repo in almost every error you return, plus the fact the user and repository are the argument of the function, I tend to do not add them in the error message. The caller should do it
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.
As you liked my feedbacks by dropping emoji on it, I will assume you will work on it when you have time. But for now, I prefer to mark as "request changes"
What was changed ?
Added a new test to check repository maturity
Why do we need it?
We need to check that projects listed here are seriously maintained. As we discussed at: #5473
How it works
When you run the test, it reads all links from the entire README file, and for each link, uses the github api to fetch the first commit made 5 months before the current date. If no commits were found, the test fails.
Only links to github repositories are checked.
How to run test?
Why do we need an API key?
Rate Limit
: authenticated requests can send more requests per hour, considering that this list holds +1000 links. Not using and API key isn't an option.This PR only adds the code needed to run the test, when and how we should run them still needs a discussion, as stated above, we run tests against the entire link set. I don't think we must run this test on new PR because it may fail just because of rate limiting.
I wonder if there is a way to run them only against links added in the PR.