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

feat: add protobuf #717

Merged
merged 1 commit into from
Oct 18, 2024
Merged

feat: add protobuf #717

merged 1 commit into from
Oct 18, 2024

Conversation

akitaSummer
Copy link
Contributor

@akitaSummer akitaSummer commented Oct 18, 2024

Summary by CodeRabbit

  • New Features

    • Added support for Protocol Buffers with a new binary entry in the configuration.
  • Tests

    • Introduced a new test case to verify the fetching of release data for the Protocol Buffers repository from GitHub.

Copy link
Contributor

coderabbitai bot commented Oct 18, 2024

Walkthrough

The changes in this pull request introduce a new entry for the protobuf binary in the config/binaries.ts file, detailing its properties such as category, description, type, repository, and distribution URL. Additionally, a new test case is added to the GithubBinary.test.ts file, which verifies the functionality of fetching release data for the protobuf repository from GitHub. This includes checking for specific files and ensuring the fetch() method operates correctly for this new binary.

Changes

File Path Change Summary
config/binaries.ts Added a new entry for protobuf with properties: category, description, type, repo, and distUrl.
test/common/adapter/binary/GithubBinary.test.ts Introduced a new test case in the fetch() method to validate fetching data for the protobuf repository.

Poem

In the meadow where binaries play,
A new friend joins the fray today.
Protobuf hops with data so bright,
Fetching releases, what a delight!
With tests that ensure all's well and good,
Our code now dances, as it should! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b06e255 and af52c66.

📒 Files selected for processing (2)
  • config/binaries.ts (1 hunks)
  • test/common/adapter/binary/GithubBinary.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • config/binaries.ts
  • test/common/adapter/binary/GithubBinary.test.ts

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

非常欢迎你参与贡献,请确保你的新功能或者缺陷修复都包含相对于的单元测试用例,方便我们快速理解你的意图。更多贡献者说明请参考 https://github.com/cnpm/cnpmcore/blob/main/DEVELOPER.md

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
test/common/adapter/binary/GithubBinary.test.ts (1)

118-118: Consider removing the console.log statement.

The console.log statement on this line is likely used for debugging purposes. It's generally a good practice to remove such statements from test code before committing, as they can clutter the test output.

- console.log(JSON.stringify(result.items, null, 2));
config/binaries.ts (1)

141-141: Consider removing quotes from the 'protobuf' property name.

The static analysis tool has flagged an issue with unnecessarily quoted property 'protobuf'. In JavaScript and TypeScript, it's generally recommended to avoid quoting property names unless they contain special characters or are invalid identifiers.

Consider applying this change:

-  'protobuf': {
+  protobuf: {

This change will make the code more consistent with modern JavaScript/TypeScript style guidelines and remove the unnecessary quotes.

🧰 Tools
🪛 GitHub Check: test-mysql57-fs-nfs (22, ubuntu-latest)

[failure] 141-141:
Unnecessarily quoted property 'protobuf' found

🪛 GitHub Check: test-mysql57-fs-nfs (20, ubuntu-latest)

[failure] 141-141:
Unnecessarily quoted property 'protobuf' found

🪛 GitHub Check: test-mysql57-fs-nfs (18, ubuntu-latest)

[failure] 141-141:
Unnecessarily quoted property 'protobuf' found

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between efac8a9 and 1e09aa6.

📒 Files selected for processing (2)
  • config/binaries.ts (1 hunks)
  • test/common/adapter/binary/GithubBinary.test.ts (1 hunks)
🧰 Additional context used
🪛 GitHub Check: test-mysql57-fs-nfs (22, ubuntu-latest)
config/binaries.ts

[failure] 141-141:
Unnecessarily quoted property 'protobuf' found

🪛 GitHub Check: test-mysql57-fs-nfs (20, ubuntu-latest)
config/binaries.ts

[failure] 141-141:
Unnecessarily quoted property 'protobuf' found

🪛 GitHub Check: test-mysql57-fs-nfs (18, ubuntu-latest)
config/binaries.ts

[failure] 141-141:
Unnecessarily quoted property 'protobuf' found

🔇 Additional comments (1)
config/binaries.ts (1)

141-147: LGTM! New 'protobuf' entry looks good.

The new entry for 'protobuf' is well-structured and consistent with other entries in the binaries object. It includes all the necessary properties:

  • category: Correctly set to 'protobuf'
  • description: Provides a clear and concise description of Protocol Buffers
  • type: Correctly set to BinaryType.GitHub
  • repo: Points to the correct GitHub repository 'protocolbuffers/protobuf'
  • distUrl: Correctly set to the releases page of the repository

The addition of this entry will enable the system to handle Protocol Buffers binary distributions.

🧰 Tools
🪛 GitHub Check: test-mysql57-fs-nfs (22, ubuntu-latest)

[failure] 141-141:
Unnecessarily quoted property 'protobuf' found

🪛 GitHub Check: test-mysql57-fs-nfs (20, ubuntu-latest)

[failure] 141-141:
Unnecessarily quoted property 'protobuf' found

🪛 GitHub Check: test-mysql57-fs-nfs (18, ubuntu-latest)

[failure] 141-141:
Unnecessarily quoted property 'protobuf' found

Comment on lines +119 to +129
let matchFile1 = false;
for (const item of result.items) {
assert(item.isDir === false);
if (item.name === 'protoc-28.2-linux-aarch_64.zip') {
assert(item.date === '2024-09-18T21:02:40Z');
assert(item.size === 3218760);
assert.equal(item.url, 'https://github.com/protocolbuffers/protobuf/releases/download/v28.2/protoc-28.2-linux-aarch_64.zip');
matchFile1 = true;
}
}
assert(matchFile1);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance test coverage by checking multiple files.

The current test only verifies the presence and properties of a single file (protoc-28.2-linux-aarch_64.zip). To improve test coverage and ensure the fetch method works correctly for various file types, consider adding checks for additional files with different architectures or operating systems.

Here's an example of how you could expand the test:

const expectedFiles = [
  {
    name: 'protoc-28.2-linux-aarch_64.zip',
    date: '2024-09-18T21:02:40Z',
    size: 3218760,
    url: 'https://github.com/protocolbuffers/protobuf/releases/download/v28.2/protoc-28.2-linux-aarch_64.zip'
  },
  {
    name: 'protoc-28.2-linux-x86_64.zip',
    date: '2024-09-18T21:02:40Z',
    size: 3456789,
    url: 'https://github.com/protocolbuffers/protobuf/releases/download/v28.2/protoc-28.2-linux-x86_64.zip'
  },
  // Add more expected files here
];

for (const expectedFile of expectedFiles) {
  let fileFound = false;
  for (const item of result.items) {
    if (item.name === expectedFile.name) {
      assert(item.date === expectedFile.date);
      assert(item.size === expectedFile.size);
      assert.equal(item.url, expectedFile.url);
      fileFound = true;
      break;
    }
  }
  assert(fileFound, `File ${expectedFile.name} not found in the result`);
}

This approach allows you to easily add more files to check without duplicating assertion code.

Copy link

codecov bot commented Oct 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.46%. Comparing base (99a8660) to head (af52c66).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #717   +/-   ##
=======================================
  Coverage   96.46%   96.46%           
=======================================
  Files         188      188           
  Lines       18796    18803    +7     
  Branches     2463     2463           
=======================================
+ Hits        18132    18139    +7     
  Misses        664      664           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1e09aa6 and b06e255.

📒 Files selected for processing (2)
  • config/binaries.ts (1 hunks)
  • test/common/adapter/binary/GithubBinary.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • config/binaries.ts
🧰 Additional context used

Comment on lines +94 to +130
it('should fetch protobuf', async () => {
const response = await TestUtil.readJSONFile(TestUtil.getFixtures('protobuf-releases.json'));
app.mockHttpclient(/https:\/\/api\.github\.com\/repos\/protocolbuffers\/protobuf\/releases/, 'GET', {
data: response,
status: 200,
});
let result = await binary.fetch('/', 'protobuf');
assert(result);
assert(result.items.length > 0);
let matchDir = false;
for (const item of result.items) {
assert(item.isDir === true);
if (item.name === 'v28.2/') {
matchDir = true;
}
}
assert(matchDir);

result = await binary.fetch('/v28.2/', 'protobuf');
assert(result?.items.every(item => !/{.*}/.test(item.url)));

result = await binary.fetch('/v28.2/', 'protobuf');
assert(result);
assert(result.items.length > 0);
console.log(JSON.stringify(result.items, null, 2));
let matchFile1 = false;
for (const item of result.items) {
assert(item.isDir === false);
if (item.name === 'protoc-28.2-linux-aarch_64.zip') {
assert(item.date === '2024-09-18T21:02:40Z');
assert(item.size === 3218760);
assert.equal(item.url, 'https://github.com/protocolbuffers/protobuf/releases/download/v28.2/protoc-28.2-linux-aarch_64.zip');
matchFile1 = true;
}
}
assert(matchFile1);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider refactoring and enhancing the test case.

While the new test case for fetching protobuf is functional, there are several areas for improvement:

  1. Code duplication: The structure is very similar to the existing "should fetch skia-canvas" test. Consider refactoring common logic into a helper function to reduce duplication and improve maintainability.

  2. Test coverage: The test only checks for a single file. Enhance coverage by verifying multiple files with different architectures or operating systems.

  3. Debug logging: Remove the console.log statement on line 118 before finalizing the code.

  4. Error handling: Add test cases for potential error scenarios, such as API failures or unexpected response formats.

Here's a suggested refactoring to address these points:

function testGithubBinaryFetch(repoName: string, fixtureName: string, expectedDir: string, expectedFiles: Array<{name: string, date: string, size: number, url: string}>) {
  it(`should fetch ${repoName}`, async () => {
    const response = await TestUtil.readJSONFile(TestUtil.getFixtures(fixtureName));
    app.mockHttpclient(new RegExp(`https://api.github.com/repos/.+/${repoName}/releases`), 'GET', {
      data: response,
      status: 200,
    });

    let result = await binary.fetch('/', repoName);
    assert(result && result.items.length > 0);
    assert(result.items.some(item => item.name === expectedDir && item.isDir));

    result = await binary.fetch(`/${expectedDir}`, repoName);
    assert(result?.items.every(item => !/{.*}/.test(item.url)));

    result = await binary.fetch(`/${expectedDir}`, repoName);
    assert(result && result.items.length > 0);
    
    for (const expectedFile of expectedFiles) {
      const matchingFile = result.items.find(item => item.name === expectedFile.name);
      assert(matchingFile, `File ${expectedFile.name} not found`);
      assert(matchingFile.date === expectedFile.date);
      assert(matchingFile.size === expectedFile.size);
      assert.equal(matchingFile.url, expectedFile.url);
    }
  });
}

// Usage
testGithubBinaryFetch(
  'protobuf',
  'protobuf-releases.json',
  'v28.2/',
  [
    {
      name: 'protoc-28.2-linux-aarch_64.zip',
      date: '2024-09-18T21:02:40Z',
      size: 3218760,
      url: 'https://github.com/protocolbuffers/protobuf/releases/download/v28.2/protoc-28.2-linux-aarch_64.zip'
    },
    // Add more expected files here
  ]
);

// Add error case test
it('should handle API failure', async () => {
  app.mockHttpclient(/https:\/\/api\.github\.com\/repos\/protocolbuffers\/protobuf\/releases/, 'GET', {
    status: 500,
  });
  await assert.rejects(async () => {
    await binary.fetch('/', 'protobuf');
  }, /API request failed/);
});

This refactoring addresses the code duplication, allows for easier addition of more test cases, and includes an example of error case testing.

@fengmk2 fengmk2 added the enhancement New feature or request label Oct 18, 2024
@fengmk2 fengmk2 merged commit d6f0e1d into master Oct 18, 2024
12 of 13 checks passed
@fengmk2 fengmk2 deleted the feat/protobuf branch October 18, 2024 15:33
fengmk2 pushed a commit that referenced this pull request Oct 18, 2024
[skip ci]

## [3.64.0](v3.63.1...v3.64.0) (2024-10-18)

### Features

* mirror protobuf binary ([#717](#717)) ([d6f0e1d](d6f0e1d))
@fengmk2
Copy link
Member

fengmk2 commented Oct 18, 2024

@fengmk2
Copy link
Member

fengmk2 commented Oct 19, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants