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

fix: fixed dashboard scripts #3304

Merged
merged 10 commits into from
Oct 23, 2024

Conversation

akshatnema
Copy link
Member

@akshatnema akshatnema commented Oct 20, 2024

Description

Fixed dashboard script to remove secondary rate limits in the flow of script.

Related issue(s)
Fixes #2894 #3132

Testing of workflow

Test runs in forked repo - https://github.com/akshatnema/website/actions/runs/11426503184/job/31789495554

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a batching mechanism for processing discussions, improving API call control.
    • Added a pause function to manage delays between batches.
  • Bug Fixes

    • Corrected formatting and indentation issues in workflow and script files.
  • Refactor

    • Enhanced readability by using template literals and cleaning up code structure.
    • Removed the Twitter timeline embed from the Newsroom component to streamline content.
  • Chores

    • Updated workflow trigger to run daily at midnight and refined environment variable handling.

Copy link

coderabbitai bot commented Oct 20, 2024

Walkthrough

The pull request introduces modifications to the GitHub Actions workflow file and the build-dashboard.js script. The workflow now includes a daily cron trigger and updates to environment variable references. The build-dashboard.js script has been restructured to process discussions in batches, enhancing API call management and introducing a pause function. Various code improvements were made for readability and consistency, while the module exports remain unchanged.

Changes

File Change Summary
.github/workflows/regenerate-meetings-and-videos.yml Updated cron schedule to run daily at midnight, modified environment variable references, adjusted step for package-lock version, corrected branch naming convention, and ensured consistent formatting in Slack reporting step.
scripts/dashboard/build-dashboard.js Restructured getHotDiscussions to process discussions in batches with a pause function, altered error handling, updated variable declarations, and improved code readability and formatting.
components/newsroom/Newsroom.tsx Removed TwitterTimelineEmbed component and adjusted layout for the component, modifying class names for height adjustments while streamlining content presentation.

Assessment against linked issues

Objective Addressed Explanation
Fix intermittent 403 RequestError in build-dashboard.js script (#2894)

Possibly related PRs

  • fix: run tests on branch pushes #3296: The changes in this PR involve modifications to workflow files, similar to the main PR, which also updates a workflow file. Both PRs focus on enhancing workflow configurations, although they address different aspects of workflow execution.

Suggested labels

ready-to-merge

Suggested reviewers

  • derberg
  • magicmatatjahu
  • devilkiller-ag
  • sambhavgupta0705
  • asyncapi-bot-eve
  • Mayaleeeee

🐇 In the moonlight's gentle glow,
The workflow dances, swift and slow.
Batching discussions, oh what a feat,
With pauses in place, it can't be beat!
A token's secret, now in its place,
Together we build, with style and grace! 🌙✨


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

netlify bot commented Oct 20, 2024

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 79611d1
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/67187bb6cfda6f00082747c6
😎 Deploy Preview https://deploy-preview-3304--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Oct 20, 2024

Codecov Report

Attention: Patch coverage is 0% with 37 lines in your changes missing coverage. Please review.

Project coverage is 52.30%. Comparing base (7b70861) to head (79611d1).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
scripts/dashboard/build-dashboard.js 0.00% 37 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3304      +/-   ##
==========================================
- Coverage   53.17%   52.30%   -0.88%     
==========================================
  Files          21       21              
  Lines         598      608      +10     
==========================================
  Hits          318      318              
- Misses        280      290      +10     

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

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Oct 20, 2024

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 45
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-3304--asyncapi-website.netlify.app/

Copy link

@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)
.github/workflows/regenerate-meetings-and-videos.yml (1)

48-48: Consider a more descriptive branch naming convention

The change to use github.sha in the branch name provides a unique identifier for each run, which is good for tracking. However, it might make it less obvious what the branch is for at a glance.

Consider using a combination of a descriptive prefix and the SHA for better clarity, e.g.:

branch: update-meetings-${{ github.sha }}

This way, you maintain uniqueness while also conveying the purpose of the branch.

scripts/dashboard/build-dashboard.js (1)

66-110: Ensure Batching Logic Effectively Manages Rate Limits

The introduction of batching in getHotDiscussions enhances control over API call rates, which is beneficial. Ensure that the chosen batch size (5) and pause durations (1000ms between batches) align with GitHub's API rate limiting policies to prevent the script from exceeding rate limits.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 66-67: scripts/dashboard/build-dashboard.js#L66-L67
Added lines #L66 - L67 were not covered by tests


[warning] 69-69: scripts/dashboard/build-dashboard.js#L69
Added line #L69 was not covered by tests


[warning] 71-71: scripts/dashboard/build-dashboard.js#L71
Added line #L71 was not covered by tests


[warning] 73-76: scripts/dashboard/build-dashboard.js#L73-L76
Added lines #L73 - L76 were not covered by tests


[warning] 80-80: scripts/dashboard/build-dashboard.js#L80
Added line #L80 was not covered by tests


[warning] 82-82: scripts/dashboard/build-dashboard.js#L82
Added line #L82 was not covered by tests


[warning] 84-84: scripts/dashboard/build-dashboard.js#L84
Added line #L84 was not covered by tests


[warning] 87-87: scripts/dashboard/build-dashboard.js#L87
Added line #L87 was not covered by tests


[warning] 89-89: scripts/dashboard/build-dashboard.js#L89
Added line #L89 was not covered by tests


[warning] 101-102: scripts/dashboard/build-dashboard.js#L101-L102
Added lines #L101 - L102 were not covered by tests


[warning] 108-108: scripts/dashboard/build-dashboard.js#L108
Added line #L108 was not covered by tests


[warning] 110-110: scripts/dashboard/build-dashboard.js#L110
Added line #L110 was not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9a1c3a6 and fca64ae.

📒 Files selected for processing (2)
  • .github/workflows/regenerate-meetings-and-videos.yml (4 hunks)
  • scripts/dashboard/build-dashboard.js (2 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
scripts/dashboard/build-dashboard.js

[warning] 7-8: scripts/dashboard/build-dashboard.js#L7-L8
Added lines #L7 - L8 were not covered by tests


[warning] 14-14: scripts/dashboard/build-dashboard.js#L14
Added line #L14 was not covered by tests


[warning] 32-32: scripts/dashboard/build-dashboard.js#L32
Added line #L32 was not covered by tests


[warning] 34-34: scripts/dashboard/build-dashboard.js#L34
Added line #L34 was not covered by tests


[warning] 39-39: scripts/dashboard/build-dashboard.js#L39
Added line #L39 was not covered by tests


[warning] 43-43: scripts/dashboard/build-dashboard.js#L43
Added line #L43 was not covered by tests


[warning] 48-48: scripts/dashboard/build-dashboard.js#L48
Added line #L48 was not covered by tests


[warning] 59-59: scripts/dashboard/build-dashboard.js#L59
Added line #L59 was not covered by tests


[warning] 64-64: scripts/dashboard/build-dashboard.js#L64
Added line #L64 was not covered by tests


[warning] 66-67: scripts/dashboard/build-dashboard.js#L66-L67
Added lines #L66 - L67 were not covered by tests


[warning] 69-69: scripts/dashboard/build-dashboard.js#L69
Added line #L69 was not covered by tests


[warning] 71-71: scripts/dashboard/build-dashboard.js#L71
Added line #L71 was not covered by tests


[warning] 73-76: scripts/dashboard/build-dashboard.js#L73-L76
Added lines #L73 - L76 were not covered by tests


[warning] 80-80: scripts/dashboard/build-dashboard.js#L80
Added line #L80 was not covered by tests


[warning] 82-82: scripts/dashboard/build-dashboard.js#L82
Added line #L82 was not covered by tests


[warning] 84-84: scripts/dashboard/build-dashboard.js#L84
Added line #L84 was not covered by tests


[warning] 87-87: scripts/dashboard/build-dashboard.js#L87
Added line #L87 was not covered by tests


[warning] 89-89: scripts/dashboard/build-dashboard.js#L89
Added line #L89 was not covered by tests


[warning] 101-102: scripts/dashboard/build-dashboard.js#L101-L102
Added lines #L101 - L102 were not covered by tests


[warning] 108-108: scripts/dashboard/build-dashboard.js#L108
Added line #L108 was not covered by tests


[warning] 110-110: scripts/dashboard/build-dashboard.js#L110
Added line #L110 was not covered by tests


[warning] 112-114: scripts/dashboard/build-dashboard.js#L112-L114
Added lines #L112 - L114 were not covered by tests


[warning] 117-117: scripts/dashboard/build-dashboard.js#L117
Added line #L117 was not covered by tests


[warning] 120-120: scripts/dashboard/build-dashboard.js#L120
Added line #L120 was not covered by tests


[warning] 129-129: scripts/dashboard/build-dashboard.js#L129
Added line #L129 was not covered by tests


[warning] 135-136: scripts/dashboard/build-dashboard.js#L135-L136
Added lines #L135 - L136 were not covered by tests


[warning] 140-140: scripts/dashboard/build-dashboard.js#L140
Added line #L140 was not covered by tests


[warning] 142-143: scripts/dashboard/build-dashboard.js#L142-L143
Added lines #L142 - L143 were not covered by tests


[warning] 160-160: scripts/dashboard/build-dashboard.js#L160
Added line #L160 was not covered by tests


[warning] 166-166: scripts/dashboard/build-dashboard.js#L166
Added line #L166 was not covered by tests

🪛 Biome
scripts/dashboard/build-dashboard.js

[error] 136-136: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (6)
.github/workflows/regenerate-meetings-and-videos.yml (5)

Line range hint 3-7: LGTM: Cron schedule added for daily execution

The addition of a daily cron schedule at 00:10 UTC aligns well with the PR objective of addressing the nightly execution of the dashboard script. This change ensures regular and automated execution of the workflow.


Line range hint 26-30: LGTM: Improved Node.js version management

The update to use the Node.js version from the package-lock.json file is a good practice. It ensures consistency between the development and CI environments, reducing potential issues caused by version mismatches.


57-57: LGTM: Improved YAML formatting

The correction of the indentation for the SLACK_WEBHOOK_URL environment variable improves readability and ensures proper YAML syntax. While this doesn't affect functionality, it contributes to better overall code quality.


Line range hint 1-57: Overall assessment: Changes align well with PR objectives

The modifications to this workflow file effectively address the PR objectives:

  1. The addition of a daily cron schedule ensures regular execution of the dashboard script.
  2. The use of GH_TOKEN instead of GITHUB_TOKEN may help with API rate limit issues.
  3. Improved Node.js version management ensures consistency across environments.

These changes, along with the modifications in other files not shown here, should help resolve the intermittent 403 RequestError issue mentioned in the linked bug report.

To further improve the PR:

  1. Verify the permissions of the GH_TOKEN as suggested earlier.
  2. Consider the suggestion for a more descriptive branch naming convention.

Once these points are addressed, the PR looks good to merge.


Line range hint 15-15: Verify permissions for GH_TOKEN

The change from GITHUB_TOKEN to secrets.GH_TOKEN is noted. This modification could potentially address the API rate limit issues mentioned in the PR objectives.

Please confirm that the GH_TOKEN has the necessary permissions for the workflow tasks, particularly for API calls that might have been hitting rate limits previously. Run the following script to check the permissions of the token:

scripts/dashboard/build-dashboard.js (1)

6-9: Implementation of 'pause' Function is Correct

The pause function is properly implemented to introduce delays using Promises and setTimeout. This helps in managing API call rates effectively.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 7-8: scripts/dashboard/build-dashboard.js#L7-L8
Added lines #L7 - L8 were not covered by tests

} catch (e) {
console.error(e);

return Promise.reject(e);
Copy link

@coderabbitai coderabbitai bot Oct 20, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplify Error Handling by Throwing Errors Directly

In async functions, instead of returning Promise.reject(e);, it's cleaner to throw the error directly using throw e;. This makes the code more idiomatic and easier to read.

Apply this diff:

// In the getDiscussions function
-    return Promise.reject(e);
+    throw e;

// In the getDiscussionByID function
-    return Promise.reject(e);
+    throw e;

Also applies to: 59-59

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 43-43: scripts/dashboard/build-dashboard.js#L43
Added line #L43 was not covered by tests

Copy link
Member Author

Choose a reason for hiding this comment

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

Will improve this readiness of the code in another PR.

Copy link

Choose a reason for hiding this comment

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

@akshatnema, understood. Would you like me to open a new GitHub issue to track this improvement?

🐰😔

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure 👍 . Please do it.

Copy link

Choose a reason for hiding this comment

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

@akshatnema, I've opened a new GitHub issue to track this improvement: Issue #3305.

🐰😊

🔗 Analysis chain
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash

# Create a new GitHub issue to track the requested improvement.
gh issue create \
  --title "Simplify error handling in build-dashboard.js" \
  --body "As discussed in [PR #3304](https://github.com/asyncapi/website/pull/3304) ([comment](https://github.com/asyncapi/website/pull/3304#discussion_r1807819750)), @akshatnema agreed to improve the error handling by throwing errors directly instead of using \`Promise.reject(e);\` in the \`build-dashboard.js\` script.

We should update the error handling code to throw errors directly, making the asynchronous functions more idiomatic and easier to read." \
  --assignee akshatnema

Length of output: 597

Comment on lines 135 to 136
const result = issue.labels.nodes.find((label) => label.name.startsWith(filter));
return result && result.name.split('/')[1];
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplify Property Access Using Optional Chaining

To handle cases where result might be undefined, you can simplify the return statement using optional chaining for better readability.

Apply this diff:

-  return result && result.name.split('/')[1];
+  return result?.name.split('/')[1];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const result = issue.labels.nodes.find((label) => label.name.startsWith(filter));
return result && result.name.split('/')[1];
const result = issue.labels.nodes.find((label) => label.name.startsWith(filter));
return result?.name.split('/')[1];
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 135-136: scripts/dashboard/build-dashboard.js#L135-L136
Added lines #L135 - L136 were not covered by tests

🪛 Biome

[error] 136-136: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Copy link

@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: 0

🧹 Outside diff range and nitpick comments (3)
scripts/dashboard/build-dashboard.js (3)

6-9: LGTM! Consider adding JSDoc for clarity.

The pause function is a good addition for managing API rate limits. To improve maintainability, consider adding a JSDoc comment explaining its purpose and usage.

Add a JSDoc comment above the function:

/**
 * Introduces a delay in the execution flow.
 * @param {number} ms - The number of milliseconds to pause.
 * @returns {Promise<void>} A promise that resolves after the specified delay.
 */
async function pause(ms) {
  // ... existing implementation
}
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 7-8: scripts/dashboard/build-dashboard.js#L7-L8
Added lines #L7 - L8 were not covered by tests


63-114: Excellent restructuring for API rate limit management.

The changes in the getHotDiscussions function significantly improve API call management:

  1. Processing discussions in batches of 5 helps prevent hitting secondary rate limits.
  2. Adding pauses between batches further mitigates API limit issues.

These changes directly address the PR objectives and should resolve the intermittent 403 RequestError.

Suggestions for improvement:

  1. Consider extracting the batch processing logic into a separate function for better readability.
  2. Justify or remove the eslint disable comments if possible.
  3. Add comments explaining the batching strategy and its purpose.

Consider refactoring the batch processing logic:

async function processBatch(batch) {
  return Promise.all(batch.map(async (discussion) => {
    // ... existing processing logic
  }));
}

async function getHotDiscussions(discussions) {
  const result = [];
  const batchSize = 5;

  for (let i = 0; i < discussions.length; i += batchSize) {
    const batch = discussions.slice(i, i + batchSize);
    const batchResults = await processBatch(batch);
    result.push(...batchResults);
    await pause(1000);
  }

  // ... existing sorting and filtering logic
}

This refactoring improves readability and maintainability of the function.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 64-64: scripts/dashboard/build-dashboard.js#L64
Added line #L64 was not covered by tests


[warning] 66-67: scripts/dashboard/build-dashboard.js#L66-L67
Added lines #L66 - L67 were not covered by tests


[warning] 69-69: scripts/dashboard/build-dashboard.js#L69
Added line #L69 was not covered by tests


[warning] 71-71: scripts/dashboard/build-dashboard.js#L71
Added line #L71 was not covered by tests


[warning] 73-76: scripts/dashboard/build-dashboard.js#L73-L76
Added lines #L73 - L76 were not covered by tests


[warning] 80-80: scripts/dashboard/build-dashboard.js#L80
Added line #L80 was not covered by tests


[warning] 82-82: scripts/dashboard/build-dashboard.js#L82
Added line #L82 was not covered by tests


[warning] 84-84: scripts/dashboard/build-dashboard.js#L84
Added line #L84 was not covered by tests


[warning] 87-87: scripts/dashboard/build-dashboard.js#L87
Added line #L87 was not covered by tests


[warning] 89-89: scripts/dashboard/build-dashboard.js#L89
Added line #L89 was not covered by tests


[warning] 101-102: scripts/dashboard/build-dashboard.js#L101-L102
Added lines #L101 - L102 were not covered by tests


[warning] 108-108: scripts/dashboard/build-dashboard.js#L108
Added line #L108 was not covered by tests


[warning] 110-110: scripts/dashboard/build-dashboard.js#L110
Added line #L110 was not covered by tests


[warning] 112-114: scripts/dashboard/build-dashboard.js#L112-L114
Added lines #L112 - L114 were not covered by tests


Test Coverage Insufficient for build-dashboard.js

The current implementation of build-dashboard.js lacks adequate test coverage. No related test files or coverage reports were found, which poses a risk given the significant changes introduced, such as the new batching logic and API rate limit handling.

To ensure robustness and maintainability, please add the following tests:

  1. Test the pause function
  2. Test the batching logic in getHotDiscussions
  3. Test error handling with mocked API responses
  4. Test rate limit handling and pauses between API calls
🔗 Analysis chain

Line range hint 1-166: Overall improvements with a note on test coverage.

The changes made in this PR effectively address the issue of hitting API rate limits, particularly through the restructuring of the getHotDiscussions function. The introduction of batching and pauses should resolve the intermittent 403 RequestError.

However, it's important to note that many of the new lines are not covered by tests, according to the static analysis. Given the significant changes to the behavior of key functions, it would be beneficial to add or update tests to ensure the new batching logic and API call management work as expected.

To assess the current test coverage and identify areas needing additional tests, you can run the following command:

This script will help identify existing tests, coverage reports, and suggest areas where new tests might be needed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check test coverage for the dashboard script

# Find test files related to the dashboard script
echo "Related test files:"
fd -e test.js -e spec.js dashboard

# Check for existing test coverage reports
echo "Existing coverage reports:"
fd -e lcov -e info coverage

# If a coverage script exists in package.json, you might want to run it
if grep -q "\"test:coverage\"" package.json; then
  echo "Consider running the test coverage script defined in package.json"
fi

# Suggest areas that might need new tests based on the changes
echo "Suggestions for new tests:"
echo "1. Test the 'pause' function"
echo "2. Test the batching logic in 'getHotDiscussions'"
echo "3. Test error handling with mocked API responses"
echo "4. Test rate limit handling and pauses between API calls"

Length of output: 700

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 32-32: scripts/dashboard/build-dashboard.js#L32
Added line #L32 was not covered by tests


[warning] 34-34: scripts/dashboard/build-dashboard.js#L34
Added line #L34 was not covered by tests


[warning] 39-39: scripts/dashboard/build-dashboard.js#L39
Added line #L39 was not covered by tests


[warning] 43-43: scripts/dashboard/build-dashboard.js#L43
Added line #L43 was not covered by tests


[warning] 48-48: scripts/dashboard/build-dashboard.js#L48
Added line #L48 was not covered by tests


[warning] 59-59: scripts/dashboard/build-dashboard.js#L59
Added line #L59 was not covered by tests


[warning] 64-64: scripts/dashboard/build-dashboard.js#L64
Added line #L64 was not covered by tests


[warning] 66-67: scripts/dashboard/build-dashboard.js#L66-L67
Added lines #L66 - L67 were not covered by tests


[warning] 69-69: scripts/dashboard/build-dashboard.js#L69
Added line #L69 was not covered by tests


[warning] 71-71: scripts/dashboard/build-dashboard.js#L71
Added line #L71 was not covered by tests


[warning] 73-76: scripts/dashboard/build-dashboard.js#L73-L76
Added lines #L73 - L76 were not covered by tests


[warning] 80-80: scripts/dashboard/build-dashboard.js#L80
Added line #L80 was not covered by tests


[warning] 82-82: scripts/dashboard/build-dashboard.js#L82
Added line #L82 was not covered by tests


[warning] 84-84: scripts/dashboard/build-dashboard.js#L84
Added line #L84 was not covered by tests


[warning] 87-87: scripts/dashboard/build-dashboard.js#L87
Added line #L87 was not covered by tests


[warning] 89-89: scripts/dashboard/build-dashboard.js#L89
Added line #L89 was not covered by tests


[warning] 101-102: scripts/dashboard/build-dashboard.js#L101-L102
Added lines #L101 - L102 were not covered by tests


[warning] 108-108: scripts/dashboard/build-dashboard.js#L108
Added line #L108 was not covered by tests


[warning] 110-110: scripts/dashboard/build-dashboard.js#L110
Added line #L110 was not covered by tests


[warning] 112-114: scripts/dashboard/build-dashboard.js#L112-L114
Added lines #L112 - L114 were not covered by tests


[warning] 117-117: scripts/dashboard/build-dashboard.js#L117
Added line #L117 was not covered by tests


[warning] 120-120: scripts/dashboard/build-dashboard.js#L120
Added line #L120 was not covered by tests


[warning] 129-129: scripts/dashboard/build-dashboard.js#L129
Added line #L129 was not covered by tests


[warning] 135-136: scripts/dashboard/build-dashboard.js#L135-L136
Added lines #L135 - L136 were not covered by tests


[warning] 140-140: scripts/dashboard/build-dashboard.js#L140
Added line #L140 was not covered by tests


[warning] 142-143: scripts/dashboard/build-dashboard.js#L142-L143
Added lines #L142 - L143 were not covered by tests


[warning] 160-160: scripts/dashboard/build-dashboard.js#L160
Added line #L160 was not covered by tests


[warning] 166-166: scripts/dashboard/build-dashboard.js#L166
Added line #L166 was not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fca64ae and 0f14a3d.

📒 Files selected for processing (1)
  • scripts/dashboard/build-dashboard.js (2 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
scripts/dashboard/build-dashboard.js

[warning] 7-8: scripts/dashboard/build-dashboard.js#L7-L8
Added lines #L7 - L8 were not covered by tests


[warning] 14-14: scripts/dashboard/build-dashboard.js#L14
Added line #L14 was not covered by tests


[warning] 32-32: scripts/dashboard/build-dashboard.js#L32
Added line #L32 was not covered by tests


[warning] 34-34: scripts/dashboard/build-dashboard.js#L34
Added line #L34 was not covered by tests


[warning] 39-39: scripts/dashboard/build-dashboard.js#L39
Added line #L39 was not covered by tests


[warning] 43-43: scripts/dashboard/build-dashboard.js#L43
Added line #L43 was not covered by tests


[warning] 48-48: scripts/dashboard/build-dashboard.js#L48
Added line #L48 was not covered by tests


[warning] 59-59: scripts/dashboard/build-dashboard.js#L59
Added line #L59 was not covered by tests


[warning] 64-64: scripts/dashboard/build-dashboard.js#L64
Added line #L64 was not covered by tests


[warning] 66-67: scripts/dashboard/build-dashboard.js#L66-L67
Added lines #L66 - L67 were not covered by tests


[warning] 69-69: scripts/dashboard/build-dashboard.js#L69
Added line #L69 was not covered by tests


[warning] 71-71: scripts/dashboard/build-dashboard.js#L71
Added line #L71 was not covered by tests


[warning] 73-76: scripts/dashboard/build-dashboard.js#L73-L76
Added lines #L73 - L76 were not covered by tests


[warning] 80-80: scripts/dashboard/build-dashboard.js#L80
Added line #L80 was not covered by tests


[warning] 82-82: scripts/dashboard/build-dashboard.js#L82
Added line #L82 was not covered by tests


[warning] 84-84: scripts/dashboard/build-dashboard.js#L84
Added line #L84 was not covered by tests


[warning] 87-87: scripts/dashboard/build-dashboard.js#L87
Added line #L87 was not covered by tests


[warning] 89-89: scripts/dashboard/build-dashboard.js#L89
Added line #L89 was not covered by tests


[warning] 101-102: scripts/dashboard/build-dashboard.js#L101-L102
Added lines #L101 - L102 were not covered by tests


[warning] 108-108: scripts/dashboard/build-dashboard.js#L108
Added line #L108 was not covered by tests


[warning] 110-110: scripts/dashboard/build-dashboard.js#L110
Added line #L110 was not covered by tests


[warning] 112-114: scripts/dashboard/build-dashboard.js#L112-L114
Added lines #L112 - L114 were not covered by tests


[warning] 117-117: scripts/dashboard/build-dashboard.js#L117
Added line #L117 was not covered by tests


[warning] 120-120: scripts/dashboard/build-dashboard.js#L120
Added line #L120 was not covered by tests


[warning] 129-129: scripts/dashboard/build-dashboard.js#L129
Added line #L129 was not covered by tests


[warning] 135-136: scripts/dashboard/build-dashboard.js#L135-L136
Added lines #L135 - L136 were not covered by tests


[warning] 140-140: scripts/dashboard/build-dashboard.js#L140
Added line #L140 was not covered by tests


[warning] 142-143: scripts/dashboard/build-dashboard.js#L142-L143
Added lines #L142 - L143 were not covered by tests


[warning] 160-160: scripts/dashboard/build-dashboard.js#L160
Added line #L160 was not covered by tests


[warning] 166-166: scripts/dashboard/build-dashboard.js#L166
Added line #L166 was not covered by tests

🔇 Additional comments (5)
scripts/dashboard/build-dashboard.js (5)

14-14: LGTM! Good improvements for API management.

The changes in the getDiscussions function are well-implemented:

  1. Using const for result improves code quality.
  2. Adding a pause after the API call helps manage rate limits.
  3. Destructuring hasNextPage enhances readability.

These changes align well with the PR objectives of addressing API limit issues.

Note: The error handling remains unchanged. As mentioned in a previous review comment, consider throwing errors directly in async functions instead of using Promise.reject(e).

Also applies to: 32-34, 39-39, 43-43

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 14-14: scripts/dashboard/build-dashboard.js#L14
Added line #L14 was not covered by tests


48-52: Minor improvements noted.

The changes in the getDiscussionByID function are mostly cosmetic and improve code formatting.

As mentioned in a previous review comment and similar to the getDiscussions function, consider throwing errors directly in this async function instead of using Promise.reject(e).

Also applies to: 59-59

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 48-48: scripts/dashboard/build-dashboard.js#L48
Added line #L48 was not covered by tests


116-118: LGTM! Improved readability.

The use of template literals for path construction in the writeToFile function enhances code readability.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 117-117: scripts/dashboard/build-dashboard.js#L117
Added line #L117 was not covered by tests


119-132: LGTM! Enhanced code formatting.

The changes in the mapGoodFirstIssues function improve code readability through better formatting and the use of template literals.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 120-120: scripts/dashboard/build-dashboard.js#L120
Added line #L120 was not covered by tests


[warning] 129-129: scripts/dashboard/build-dashboard.js#L129
Added line #L129 was not covered by tests


134-137: Great job implementing the suggested improvement!

The getLabel function has been simplified using optional chaining, as suggested in a previous review. This change improves code readability and handles potential undefined values more elegantly.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 135-136: scripts/dashboard/build-dashboard.js#L135-L136
Added lines #L135 - L136 were not covered by tests

@akshatnema akshatnema linked an issue Oct 20, 2024 that may be closed by this pull request
2 tasks
Copy link

@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

🧹 Outside diff range and nitpick comments (3)
scripts/dashboard/build-dashboard.js (3)

27-35: Consider adjusting the rate limit warning threshold.

The current warning threshold of 100 remaining requests might be too low for early detection of potential rate limit issues. Consider increasing this threshold to provide more time for preventive actions.

-    if (result.rateLimit.remaining <= 100) {
+    if (result.rateLimit.remaining <= 1000) {
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 27-28: scripts/dashboard/build-dashboard.js#L27-L28
Added lines #L27 - L28 were not covered by tests


101-101: Improve error logging structure.

Consider using a structured error format for better parsing and monitoring:

-        console.error(`there was some issues while parsing this item: ${JSON.stringify(discussion)}`);
+        console.error('Error parsing discussion:', {
+          error: e.message,
+          discussion: JSON.stringify(discussion),
+          stack: e.stack
+        });
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 101-101: scripts/dashboard/build-dashboard.js#L101
Added line #L101 was not covered by tests


96-98: Document the score calculation formula.

The interaction score calculation formula needs documentation explaining the rationale behind the weights and the power of 1.8.

+          // Score formula: (total interactions) / (months since last update + 2)^1.8
+          // This formula prioritizes recent discussions with high engagement
+          // The power of 1.8 was chosen to balance between recency and interaction count
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 339ac4f and 79611d1.

📒 Files selected for processing (1)
  • scripts/dashboard/build-dashboard.js (2 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
scripts/dashboard/build-dashboard.js

[warning] 12-13: scripts/dashboard/build-dashboard.js#L12-L13
Added lines #L12 - L13 were not covered by tests


[warning] 18-19: scripts/dashboard/build-dashboard.js#L18-L19
Added lines #L18 - L19 were not covered by tests


[warning] 27-28: scripts/dashboard/build-dashboard.js#L27-L28
Added lines #L27 - L28 were not covered by tests


[warning] 37-37: scripts/dashboard/build-dashboard.js#L37
Added line #L37 was not covered by tests


[warning] 39-39: scripts/dashboard/build-dashboard.js#L39
Added line #L39 was not covered by tests


[warning] 41-42: scripts/dashboard/build-dashboard.js#L41-L42
Added lines #L41 - L42 were not covered by tests


[warning] 44-44: scripts/dashboard/build-dashboard.js#L44
Added line #L44 was not covered by tests


[warning] 46-46: scripts/dashboard/build-dashboard.js#L46
Added line #L46 was not covered by tests


[warning] 48-48: scripts/dashboard/build-dashboard.js#L48
Added line #L48 was not covered by tests


[warning] 52-53: scripts/dashboard/build-dashboard.js#L52-L53
Added lines #L52 - L53 were not covered by tests


[warning] 60-60: scripts/dashboard/build-dashboard.js#L60
Added line #L60 was not covered by tests


[warning] 62-62: scripts/dashboard/build-dashboard.js#L62
Added line #L62 was not covered by tests


[warning] 64-64: scripts/dashboard/build-dashboard.js#L64
Added line #L64 was not covered by tests


[warning] 69-69: scripts/dashboard/build-dashboard.js#L69
Added line #L69 was not covered by tests


[warning] 75-75: scripts/dashboard/build-dashboard.js#L75
Added line #L75 was not covered by tests


[warning] 82-82: scripts/dashboard/build-dashboard.js#L82
Added line #L82 was not covered by tests


[warning] 87-87: scripts/dashboard/build-dashboard.js#L87
Added line #L87 was not covered by tests


[warning] 101-101: scripts/dashboard/build-dashboard.js#L101
Added line #L101 was not covered by tests


[warning] 109-110: scripts/dashboard/build-dashboard.js#L109-L110
Added lines #L109 - L110 were not covered by tests


[warning] 112-113: scripts/dashboard/build-dashboard.js#L112-L113
Added lines #L112 - L113 were not covered by tests


[warning] 115-115: scripts/dashboard/build-dashboard.js#L115
Added line #L115 was not covered by tests


[warning] 118-118: scripts/dashboard/build-dashboard.js#L118
Added line #L118 was not covered by tests


[warning] 120-120: scripts/dashboard/build-dashboard.js#L120
Added line #L120 was not covered by tests


[warning] 123-123: scripts/dashboard/build-dashboard.js#L123
Added line #L123 was not covered by tests


[warning] 127-127: scripts/dashboard/build-dashboard.js#L127
Added line #L127 was not covered by tests


[warning] 139-139: scripts/dashboard/build-dashboard.js#L139
Added line #L139 was not covered by tests


[warning] 145-146: scripts/dashboard/build-dashboard.js#L145-L146
Added lines #L145 - L146 were not covered by tests


[warning] 170-170: scripts/dashboard/build-dashboard.js#L170
Added line #L170 was not covered by tests


[warning] 176-176: scripts/dashboard/build-dashboard.js#L176
Added line #L176 was not covered by tests

🔇 Additional comments (3)
scripts/dashboard/build-dashboard.js (3)

108-125: Effective implementation of batch processing for rate limit management.

The batched processing with pauses effectively addresses the secondary rate limit issues mentioned in issues #2894 and #3132. The implementation maintains the original functionality while adding necessary rate control.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 109-110: scripts/dashboard/build-dashboard.js#L109-L110
Added lines #L109 - L110 were not covered by tests


[warning] 112-113: scripts/dashboard/build-dashboard.js#L112-L113
Added lines #L112 - L113 were not covered by tests


[warning] 115-115: scripts/dashboard/build-dashboard.js#L115
Added line #L115 was not covered by tests


[warning] 118-118: scripts/dashboard/build-dashboard.js#L118
Added line #L118 was not covered by tests


[warning] 120-120: scripts/dashboard/build-dashboard.js#L120
Added line #L120 was not covered by tests


[warning] 123-123: scripts/dashboard/build-dashboard.js#L123
Added line #L123 was not covered by tests


176-176: Add test coverage for exported functions.

The static analysis shows that the new and modified code lacks test coverage. Consider adding unit tests for the exported functions:

  • getLabel
  • monthsSince
  • mapGoodFirstIssues
  • getHotDiscussions
  • getDiscussionByID

Let's check for existing test files:

#!/bin/bash
# Search for test files related to dashboard
fd -g '*dashboard*.test.{js,ts}'

Would you like me to help generate unit tests for these functions?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 176-176: scripts/dashboard/build-dashboard.js#L176
Added line #L176 was not covered by tests


6-15: Well-implemented delay function with good documentation.

The pause function is a clean implementation for managing API rate limits. However, it lacks test coverage.

Let's verify if similar implementations exist in the codebase:

✅ Verification successful

Let me try a different approach to verify the existence of similar implementations and test coverage.


Based on the search results, I can now generate the final response:

Unique implementation with no duplication concerns

The pause function appears to be the only implementation of its kind in the codebase, which is appropriate as it serves a specific purpose in handling GitHub API rate limits. While there's no test coverage, this is a simple utility function with minimal complexity, making it less critical for immediate test coverage.

  • The function follows Promise-based delay pattern which is a standard approach
  • No duplicate implementations found in the codebase
  • No existing test files for the dashboard functionality

Note: While the lack of test coverage is noted, it doesn't impact the correctness of this implementation as it's a straightforward utility function using standard JavaScript Promise and setTimeout patterns.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar delay/pause implementations
rg -g '!node_modules' -g '*.{js,ts}' 'setTimeout.*Promise.*resolve'

Length of output: 128


Script:

#!/bin/bash
# Search for similar delay/pause/sleep implementations with different patterns
rg -g '!node_modules' -g '*.{js,ts}' 'new Promise.*setTimeout'

# Check for test files related to the dashboard
fd -g '*dashboard*.test.{js,ts}'

# Search for any test files that might contain pause/delay testing
rg -g '!node_modules' -g '*.test.{js,ts}' 'pause|delay|setTimeout.*Promise'

Length of output: 177

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 12-13: scripts/dashboard/build-dashboard.js#L12-L13
Added lines #L12 - L13 were not covered by tests

Comment on lines +110 to +118
const batchSize = 5;

for (let i = 0; i < discussions.length; i += batchSize) {
const batch = discussions.slice(i, i + batchSize);
// eslint-disable-next-line no-await-in-loop
const batchResults = await processHotDiscussions(batch);

// eslint-disable-next-line no-await-in-loop
await pause(1000);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider making batch parameters configurable.

The batch size and pause duration are currently hardcoded. Consider making these configurable through environment variables for easier tuning:

+const BATCH_SIZE = parseInt(process.env.GITHUB_API_BATCH_SIZE, 10) || 5;
+const BATCH_PAUSE_MS = parseInt(process.env.GITHUB_API_BATCH_PAUSE_MS, 10) || 1000;
-  const batchSize = 5;
+  const batchSize = BATCH_SIZE;
-    await pause(1000);
+    await pause(BATCH_PAUSE_MS);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const batchSize = 5;
for (let i = 0; i < discussions.length; i += batchSize) {
const batch = discussions.slice(i, i + batchSize);
// eslint-disable-next-line no-await-in-loop
const batchResults = await processHotDiscussions(batch);
// eslint-disable-next-line no-await-in-loop
await pause(1000);
const BATCH_SIZE = parseInt(process.env.GITHUB_API_BATCH_SIZE, 10) || 5;
const BATCH_PAUSE_MS = parseInt(process.env.GITHUB_API_BATCH_PAUSE_MS, 10) || 1000;
for (let i = 0; i < discussions.length; i += batchSize) {
const batch = discussions.slice(i, i + batchSize);
// eslint-disable-next-line no-await-in-loop
const batchResults = await processHotDiscussions(batch);
// eslint-disable-next-line no-await-in-loop
await pause(BATCH_PAUSE_MS);
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 112-113: scripts/dashboard/build-dashboard.js#L112-L113
Added lines #L112 - L113 were not covered by tests


[warning] 115-115: scripts/dashboard/build-dashboard.js#L115
Added line #L115 was not covered by tests


[warning] 118-118: scripts/dashboard/build-dashboard.js#L118
Added line #L118 was not covered by tests

Copy link
Member

@anshgoyalevil anshgoyalevil left a comment

Choose a reason for hiding this comment

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

🚢

@anshgoyalevil
Copy link
Member

/rtm

@asyncapi-bot asyncapi-bot merged commit 2be7824 into asyncapi:master Oct 23, 2024
21 of 23 checks passed
@akshatnema akshatnema deleted the fix-build-dashboard-scripts branch October 23, 2024 06:23
@asyncapi-bot asyncapi-bot added the bounty AsyncAPI Bounty program related label label Oct 23, 2024
@aeworxet
Copy link
Contributor

@asyncapi/bounty_team

@aeworxet
Copy link
Contributor

Related to #3247.

@coderabbitai coderabbitai bot mentioned this pull request Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bounty AsyncAPI Bounty program related label ready-to-merge
Projects
Status: Completed
4 participants