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

Update code to support @octokit/request v9 and @octokit/graphql v8 #3704

Closed

Conversation

Recxsmacx
Copy link

@Recxsmacx Recxsmacx commented Feb 18, 2025

Fixes #3690

Update code to support @octokit/request v9.2.2 and @octokit/graphql v8.2.1.

  • netlify/functions/github_discussions.ts

    • Remove unused import of GraphQlQueryResponseData.
    • Update graphql function call to use the new syntax.
    • Update authorization header to use the new token format.
  • netlify/functions/save-discussion-background/helpers.ts

    • Update authorization header to use the new token format.

Summary by CodeRabbit

  • Chores
    • Improved API interactions by reformatting GraphQL queries.
    • Standardized the authentication method by updating to the "Bearer" token format for enhanced integration with external services.

Fixes asyncapi#3690

Update code to support `@octokit/request` v9.2.2 and `@octokit/graphql` v8.2.1.

* **netlify/functions/github_discussions.ts**
  - Remove unused import of `GraphQlQueryResponseData`.
  - Update `graphql` function call to use the new syntax.
  - Update authorization header to use the new token format.

* **netlify/functions/save-discussion-background/helpers.ts**
  - Update authorization header to use the new token format.
Copy link
Contributor

coderabbitai bot commented Feb 18, 2025

Walkthrough

This pull request updates the way GraphQL requests are constructed and authenticated. In the github_discussions.ts file, the query call has been changed from a string template to an object format, with the explicit owner and repo properties removed and an unused type import removed. In both this file and the save-discussion-background/helpers.ts file, the authorization header has been updated from using the token prefix to the standard Bearer prefix. No changes were made to the exported or public entity declarations.

Changes

File(s) Change Summary
netlify/functions/github_discussions.ts - Removed unused type import (GraphQlQueryResponseData).
- Modified GraphQL query call from a string template to an object format.
- Removed owner and repo properties.
- Updated auth header from token to Bearer.
netlify/functions/save-discussion-background/helpers.ts - Updated the authorization header in the fetchGraphql function from token to Bearer.

Sequence Diagram(s)

sequenceDiagram
    participant Handler as Netlify Function Handler
    participant GitHubAPI as GitHub GraphQL API

    Handler->>GitHubAPI: Send GraphQL query (object format, Bearer token)
    GitHubAPI-->>Handler: Return response
Loading

Poem

I'm a hopping rabbit with a joyful beat,
New Bearer tokens make our code complete.
Queries strutted as objects, sleek and neat,
Old props have left, vanishing in retreat.
Celebrating change with each happy tweet!
🐰💻🎉

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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.

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Feb 18, 2025

We require all PRs to follow Conventional Commits specification.
More details 👇🏼

 No release type found in pull request title "Update code to support @octokit/request v9 and @octokit/graphql v8". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

Copy link

netlify bot commented Feb 18, 2025

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 993d94a
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/67b477e4b4576400085fa47c
😎 Deploy Preview https://deploy-preview-3704--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.

@asyncapi-bot
Copy link
Contributor

Hello, @coderabbitai[bot]! 👋🏼

    I'm 🧞🧞🧞 Genie 🧞🧞🧞 from the magic lamp. Looks like somebody needs a hand!

    At the moment the following comments are supported in pull requests:

    - `/please-take-a-look` or `/ptal` - This comment will add a comment to the PR asking for attention from the reviewrs who have not reviewed the PR yet.
    - `/ready-to-merge` or `/rtm` - This comment will trigger automerge of PR in case all required checks are green, approvals in place and do-not-merge label is not added
    - `/do-not-merge` or `/dnm` - This comment will block automerging even if all conditions are met and ready-to-merge label is added
    - `/autoupdate` or `/au` - This comment will add `autoupdate` label to the PR and keeps your PR up-to-date to the target branch's future changes. Unless there is a merge conflict or it is a draft PR. (Currently only works for upstream branches.)
    - `/update` or `/u` - This comment will update the PR with the latest changes from the target branch. Unless there is a merge conflict or it is a draft PR. NOTE: this only updates the PR once, so if you need to update again, you need to call the command again.

Copy link
Contributor

coderabbitai bot commented Feb 18, 2025

Tip

For best results, initiate chat on the files or code changes.

@asyncapi-bot Thank you for the information about the supported PR commands! I'll keep these in mind for future interactions.

(`・ω・´)ゞ


✏️ Learnings added
Learnt from: asyncapi-bot
URL: https://github.com/asyncapi/website/pull/3704

Timestamp: 2025-02-18T12:07:42.042Z
Learning: The following PR commands are supported in the asyncapi/website repository:
- `/please-take-a-look` or `/ptal`: Requests attention from reviewers who haven't reviewed the PR
- `/ready-to-merge` or `/rtm`: Triggers automerge when all conditions are met
- `/do-not-merge` or `/dnm`: Blocks automerge even if all conditions are met
- `/autoupdate` or `/au`: Adds autoupdate label to keep PR in sync with target branch
- `/update` or `/u`: One-time update of PR with latest changes from target branch

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@asyncapi-bot
Copy link
Contributor

@derberg @devilkiller-ag @akshatnema @sambhavgupta0705 @anshgoyalevil @Mayaleeeee Please take a look at this PR. Thanks! 👋

Copy link

codecov bot commented Feb 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (b1c7f7c) to head (993d94a).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #3704   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           20        20           
  Lines          732       732           
=========================================
  Hits           732       732           

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

🧹 Nitpick comments (1)
netlify/functions/github_discussions.ts (1)

27-40: Consider adding input validation for GraphQL mutation parameters.

While the new object syntax for the GraphQL query is cleaner, the template literals could be vulnerable to injection attacks. Consider validating the title and feedback parameters before interpolating them into the query.

Here's a suggested approach to add input validation:

// Add input validation helper
function validateDiscussionInput(title: string, feedback: string) {
  if (!title?.trim()) {
    throw new Error('Title cannot be empty');
  }
  if (!feedback?.trim()) {
    throw new Error('Feedback cannot be empty');
  }
  // Add more validation rules as needed
}

// Use in the handler
const { title, feedback } = JSON.parse(event.body || '');
validateDiscussionInput(title, feedback);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b1c7f7c and 993d94a.

📒 Files selected for processing (2)
  • netlify/functions/github_discussions.ts (1 hunks)
  • netlify/functions/save-discussion-background/helpers.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 180000ms (4)
  • GitHub Check: Redirect rules - asyncapi-website
  • GitHub Check: Header rules - asyncapi-website
  • GitHub Check: Pages changed - asyncapi-website
  • GitHub Check: Lighthouse CI
🔇 Additional comments (2)
netlify/functions/save-discussion-background/helpers.ts (1)

21-21:

❓ Verification inconclusive

LGTM! Authorization header updated to use Bearer token.

The change from token to Bearer aligns with OAuth 2.0 standards and the latest Octokit library requirements.

Let's verify that all GitHub API calls consistently use the Bearer token format:


🏁 Script executed:

#!/bin/bash
# Description: Check for any remaining instances of the old token format
# and ensure consistent use of Bearer token format across the codebase

# Search for old token format
echo "Checking for old token format..."
rg -i "authorization.*token.*\$\{.*TOKEN.*\}"

# Search for new Bearer format to ensure consistency
echo "Checking Bearer token format..."
rg -i "authorization.*Bearer.*\$\{.*TOKEN.*\}"

Length of output: 242


LGTM! The authorization header is now correctly using the Bearer token format in netlify/functions/save-discussion-background/helpers.ts, which meets the Octokit and OAuth 2.0 requirements.

However, the automated checks using the regex script produced no conclusive output for either the old token format or the new Bearer format across the codebase. I'd recommend manually verifying (or running a more targeted search) to ensure that no legacy token formatting is lurking elsewhere in the project. This extra step will help avoid inconsistencies in GitHub API authentication.

netlify/functions/github_discussions.ts (1)

37-37: LGTM! Authorization header updated to use Bearer token.

The change from token to Bearer maintains consistency with the helper function and aligns with OAuth 2.0 standards.

@Recxsmacx Recxsmacx closed this Feb 18, 2025
@Recxsmacx Recxsmacx reopened this Feb 18, 2025
@Recxsmacx Recxsmacx closed this Feb 18, 2025
@Recxsmacx Recxsmacx deleted the update-octokit-dependencies branch February 18, 2025 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix: Update code to support @octokit/request v9 and @octokit/graphql v8
2 participants