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

Store a list of current repos which use the JSON Schema topic and when they were created #4 #10

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

wcj617
Copy link

@wcj617 wcj617 commented Mar 22, 2024

Resolves #4

This PR is for 'Store a list of current repos which use the JSON Schema topic and when they were created
#4'

Requirement

Here's the work that needs to be done on this:

 No longer check the way back machine for earliest use of the json-schema github topic and no longer record the data related to the way back machine
 Get the date of the first commit for a repo and store that in the CSV as a timestamp
 Confirm the initial data script can be run fully and include the created CSV as a commit
 Catch any potential error and log into a file, without causing the script to crash, and allowing it to continue if appropriate.
Stretch objectives:

 
![2024-03-27_03-36-48](https://github.com/json-schema-org/ecosystem/assets/47830372/35f647fe-ca4c-46d7-8c09-f36c2ed5ce87)
Write tests which [mock the Github API calls](https://mswjs.io/) and [mock the file writing](https://medium.com/nerd-for-tech/testing-in-node-js-easy-way-to-mock-filesystem-883b9f822ea4), and check it has the correct content for the API data mocked.

What I have done

This commit includes several enhancements to the initial data script:

  1. The script now retrieves the date of the first commit for each repository and stores it in the CSV file as a timestamp.
  2. The script has been confirmed to run fully, and the resulting CSV file is included in this commit.
  3. Error handling has been added to the script. Any errors that occur are logged to a file, and the script is able to continue running where appropriate.

2024-03-27_03-36-48

@wcj617 wcj617 changed the title chore: Initiate GSoC qualification task, fix package.json and add CSV… chore: Initiate GSoC qualification task, fix package.json and add CSV#4 Mar 22, 2024
@Relequestual Relequestual changed the title chore: Initiate GSoC qualification task, fix package.json and add CSV#4 chore: Initiate GSoC qualification task, fix package.json and add CSV Mar 25, 2024
Copy link
Member

@Relequestual Relequestual left a comment

Choose a reason for hiding this comment

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

Welcome, and thanks for your initial work on this.
I have left a few comments and questions.

Looking at the requirements on #4.

  1. Covered.
  2. I have updated this to specify using the timestamp format.
  3. Not covered. "Fully run" means all results without limit. There are about 1.8k results. This may take some time to run.
  4. Not covered. This is important because it can take some time to run, so the script should capture errors and continue running rather than crash and exit.

When you have updated and tested, please indicate this needs to be re-reviewed. Thanks.
Feel free to reach me on our Slack under the same username if you have questions.

projects/initial-data/.gitignore Outdated Show resolved Hide resolved
projects/initial-data/package.json Show resolved Hide resolved
projects/initial-data/main.js Outdated Show resolved Hide resolved
projects/initial-data/main.js Outdated Show resolved Hide resolved
@wcj617 wcj617 changed the title chore: Initiate GSoC qualification task, fix package.json and add CSV PR for Store a list of current repos which use the JSON Schema topic and when they were created #4 Mar 26, 2024
@wcj617
Copy link
Author

wcj617 commented Mar 30, 2024

This is my second qualification task work!
second qualification task.pdf

@wcj617 wcj617 changed the title PR for Store a list of current repos which use the JSON Schema topic and when they were created #4 Store a list of current repos which use the JSON Schema topic and when they were created #4 Apr 2, 2024
@Relequestual
Copy link
Member

This looks much improved. I'm scheduling some time to test it locally before it is merged. Thanks for your work on this.

@Relequestual
Copy link
Member

I rebased and force pushed to this PR.
Rebase was required because importing a function from main.js would cause the main function to be called, and an API request to Github to be maid before the mock could be setup, which resulted in seeing a failed API request (due to invalid API key as it had expired) after all tests had run. This was confusing when all tests had passed.

Copy link
Member

@Relequestual Relequestual left a comment

Choose a reason for hiding this comment

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

Left a few suggestions, otherwise this is looking better.

I know GSoC candidates have been selected now, but it would be nice to know if you'd like to finish this PR or not. If not, that's totally fine, and I'm sure I can find someone else to finish it or do it myself. Let me know.

projects/initial-data/main.js Outdated Show resolved Hide resolved
return Date.parse(lastPageResponse.data[0].commit.author.date);
} else {
console.error('Error occured');
throw new Error('No commits found'); //TODO: check if this is the correct error message
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
throw new Error('No commits found'); //TODO: check if this is the correct error message
throw new Error(`No commits found ${owner}/${repo}`);

Copy link
Author

Choose a reason for hiding this comment

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

fixed as suggested

}
} catch (err) {
console.log(err);
throw new Error('No commits found'); //TODO: check if this is the correct error message
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
throw new Error('No commits found'); //TODO: check if this is the correct error message
throw new Error(`Could not find any commits for ${owner}/${repo}`);

Copy link
Author

Choose a reason for hiding this comment

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

fixed as suggested

if (response.data.length > 0) {
response.data[0].created_at;
} else {
throw new Error('No releases found'); //TODO: check if this is the correct error message
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
throw new Error('No releases found'); //TODO: check if this is the correct error message
throw new Error(`No releases found for ${owner}/${repo}`);

Copy link
Author

Choose a reason for hiding this comment

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

fixed as suggested

if (lastPageResponse.data.length > 0) {
return Date.parse(lastPageResponse.data[0].created_at);
} else {
throw new Error('No releases found'); //TODO: check if this is the correct error message
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
throw new Error('No releases found'); //TODO: check if this is the correct error message
throw new Error(`No releases found for ${owner}/${repo}`);

Copy link
Author

Choose a reason for hiding this comment

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

fixed as suggested

}
} catch (err) {
console.error('Error occured');
throw new Error('No releases found'); //TODO: check if this is the correct error message
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
throw new Error('No releases found'); //TODO: check if this is the correct error message
throw new Error(`Unable to get releases for ${owner}/${repo}`);

firstReleaseDate = await fetchFirstReleaseDate(octokit, owner, repo);
} catch (err) {
console.error('Error occured in fetchFirstReleaseDate');
throw new Error('No releases found');
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
throw new Error('No releases found');
throw new Error(`Unable to get releases for ${owner}/${repo}`);

try {
firstCommitDate = await fetchFirstCommitDate(octokit, owner, repo);
} catch (err) {
console.error('Error occured in fetchFirstCommitDate');
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
console.error('Error occured in fetchFirstCommitDate');
console.error(`Error occured in fetchFirstCommitDate for ${owner}/${repo}`);

firstCommitDate = await fetchFirstCommitDate(octokit, owner, repo);
} catch (err) {
console.error('Error occured in fetchFirstCommitDate');
throw new Error('No commits found');
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
throw new Error('No commits found');
throw new Error(`Error trying to find first commit for ${owner}/${repo}`);

@wcj617
Copy link
Author

wcj617 commented May 24, 2024

[previous git commit history]
image

[after fixed]

2024-05-23_22-13-15
image

[mock jest]
image

Hi Ben,

Thank you for your insightful feedback! I appreciate the guidance and the opportunity to learn from real-world problems provided by this project.

I've completed a git rebase and resolved the divergent commits as you've noticed. I've also re-requested a review of the PR to ensure everything aligns with the project's current needs.

Regarding the API key update, your clarification was very helpful. I understand now the importance of designing tests that don't make real API calls and will take this as a key learning point.

Thank you for your support and for providing a nurturing environment for newcomers like me. I look forward to continuing my contribution to the project and will keep in touch via Slack as needed.

Best regards,
David

@wcj617 wcj617 requested a review from Relequestual May 24, 2024 05:37
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.

Store a list of current repos which use the JSON Schema topic and when they were created
2 participants