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

tests: add repository maturity test #5492

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yassinebenaid
Copy link
Collaborator

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?

GITHUB_API_TOKEN="ghp_XXXXXXXXXXXXXXXXXXXXXXX" go test . -run ^TestMaturity$

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 is what worked for me, you might have a better option, correct me if I'm mistaking.


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.

@yassinebenaid yassinebenaid added new feature go Pull requests that update Go code labels Nov 27, 2024
Comment on lines +58 to +59
http.DefaultClient.Timeout = time.Minute
httpRes, err := http.DefaultClient.Do(request)

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")

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")

Choose a reason for hiding this comment

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

Suggested change
githubApiAuthorizationToken = os.Getenv("GITHUB_API_TOKEN")
githubAPIAuthorizationToken = os.Getenv("GITHUB_API_TOKEN")

Or to respect the GitHub syntax

Suggested change
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 {

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

Suggested change
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)

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

Repository owner deleted a comment from github-actions bot Nov 28, 2024
Copy link

@ccoVeille ccoVeille left a 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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants