-
Notifications
You must be signed in to change notification settings - Fork 0
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
testing octokit auth #46
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe recent updates involve the integration of the Octokit client for GitHub API interactions across several files in the codebase. The focus has been on centralizing the instantiation of the Octokit client and updating functions to utilize this centralized approach. Additionally, the handling of GitHub webhooks has been refined, with a new file dedicated to setting up and processing webhook events, indicating a more robust and streamlined approach to event handling. Changes
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 6
Configuration used: CodeRabbit UI
Files ignored due to filter (2)
- package-lock.json
- package.json
Files selected for processing (7)
- src/auth/octokit.ts (1 hunks)
- src/fetch/fetch.ts (3 hunks)
- src/fetch/fetchFiles.ts (1 hunks)
- src/listeners/githubWebhookListener.ts (1 hunks)
- src/main.ts (2 hunks)
- src/services/pullRequestService.ts (1 hunks)
- src/webhooks/octokit.ts (1 hunks)
Files skipped from review due to trivial changes (1)
- src/services/pullRequestService.ts
Additional comments: 6
src/auth/octokit.ts (1)
- 4-6: Ensure that sensitive information such as
GITHUB_ACCESS_TOKEN
,APP_ID
, andPRIVATE_KEY
is not hardcoded and is securely managed, ideally through a secrets management system.src/fetch/fetch.ts (1)
- 1-20: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [8-37]
The refactoring of
fetchDetailsWithInstallationId
andfetchDetails
to use the new Octokit instance creation methods is a good improvement for modularity. Ensure that all error handling and logging are consistent and provide enough context for debugging.src/fetch/fetchFiles.ts (1)
- 86-86: Adding
installationId
to the log message ingetAllFilesFromPullRequest
improves the clarity and usefulness of the logs. Ensure that log message formats are consistent across the application.src/main.ts (3)
- 39-43: The
main
function has been updated to callreceiveGithubEvents
and handle GitHub events using theWebhooks
instance. Ensure that thereceiveGithubEvents
function is properly implemented and tested, as it is now a critical part of the event handling flow.Verification successful
The
receiveGithubEvents
function insrc/webhooks/octokit.ts
is designed to return aPromise
that resolves to aWebhooks
instance. The implementation sets up a webhook proxy URL and creates a newEventSource
with it. The function also includes error handling for an undefinedWEBHOOK_SECRET
, logging an error and rejecting the promise if the secret is not set.This implementation detail confirms that the function is designed to handle errors related to the webhook secret, which is a critical part of the event handling flow. It is important to ensure that the rest of the function continues to follow best practices and includes comprehensive error handling for other potential issues.
* 63-69: The `handlePullRequestOpenEvents` function has been updated to accept a `Webhooks` parameter. Verify that all calls to this function have been updated accordingly and that the function is properly handling the webhook payloads.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify the implementation of receiveGithubEvents ast-grep --lang javascript --pattern $'function receiveGithubEvents($_) { $$$ }'Length of output: 83
Script:
#!/bin/bash # Broad search for the receiveGithubEvents function definition using rg rg "function receiveGithubEvents"Length of output: 118
Script:
#!/bin/bash # Check the implementation details of receiveGithubEvents in src/webhooks/octokit.ts cat src/webhooks/octokit.ts | grep -A 10 "export function receiveGithubEvents"Length of output: 480
Verification successful
The
handlePullRequestOpenEvents
function insrc/main.ts
has been verified to accept aWebhooks
parameter, and the call to this function within the same file has been updated accordingly to pass the correct parameters. No other calls to the function were found in the codebase, suggesting that the function's usage has been properly updated to handle the webhook payloads as per the changes.* 90-93: The `handlePullRequestClosedEvents` function has been updated to accept a `Webhooks` parameter. Verify that all calls to this function have been updated accordingly and that the function is properly handling the webhook payloads.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify the usage of handlePullRequestOpenEvents ast-grep --lang javascript --pattern $'handlePullRequestOpenEvents($_, $_)'Length of output: 76
Script:
#!/bin/bash # Search for the usage of handlePullRequestOpenEvents in the codebase rg "handlePullRequestOpenEvents"Length of output: 175
export function getOctokitInstance(): Octokit { | ||
return new Octokit({ | ||
auth: token, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function getOctokitInstance
correctly creates an Octokit instance using a personal access token. However, consider adding error handling for cases where the token
might be undefined or invalid.
export function getOctokitWithInstallationId(installationId: number): Octokit { | ||
return new Octokit({ | ||
authStrategy: createAppAuth, | ||
auth: { | ||
appId: appId, | ||
privateKey: privateKey, | ||
installationId: installationId, | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function getOctokitWithInstallationId
correctly sets up an Octokit instance with app-based authentication. Ensure that appId
, privateKey
, and installationId
are validated before use to prevent runtime errors.
export function listeningForGithubWebhookEvents( | ||
app: Probot, | ||
events: any[], | ||
webhook: Webhooks | ||
): Promise<WebhookAndContext> { | ||
return new Promise(() => { | ||
try { | ||
app.log.info(`Listening for ${events} events`); | ||
|
||
app.on(events, async (context) => { | ||
resolve(context); | ||
let context: any; | ||
app.on(events, (res: any) => { | ||
context = res; | ||
}); | ||
webhook.on(events, (response: any) => { | ||
app.log.info(response); | ||
const data: WebhookAndContext = { | ||
context: context, | ||
webhook: response, | ||
}; | ||
Promise.resolve(data); | ||
}); | ||
} catch (error) { | ||
app.log.error(`Error occurred while listening for ${events} events`); | ||
reject(error); | ||
Promise.reject(error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The listeningForGithubWebhookEvents
function is intended to return a Promise
, but the resolve
and reject
methods are not being used correctly. They should be called with the appropriate values to resolve or reject the promise.
- return new Promise(() => {
+ return new Promise((resolve, reject) => {
- Promise.resolve(data);
+ resolve(data);
- Promise.reject(error);
+ reject(error);
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.
export function listeningForGithubWebhookEvents( | |
app: Probot, | |
events: any[], | |
webhook: Webhooks | |
): Promise<WebhookAndContext> { | |
return new Promise(() => { | |
try { | |
app.log.info(`Listening for ${events} events`); | |
app.on(events, async (context) => { | |
resolve(context); | |
let context: any; | |
app.on(events, (res: any) => { | |
context = res; | |
}); | |
webhook.on(events, (response: any) => { | |
app.log.info(response); | |
const data: WebhookAndContext = { | |
context: context, | |
webhook: response, | |
}; | |
Promise.resolve(data); | |
}); | |
} catch (error) { | |
app.log.error(`Error occurred while listening for ${events} events`); | |
reject(error); | |
Promise.reject(error); | |
export function listeningForGithubWebhookEvents( | |
app: Probot, | |
events: any[], | |
webhook: Webhooks | |
): Promise<WebhookAndContext> { | |
return new Promise((resolve, reject) => { | |
try { | |
app.log.info(`Listening for ${events} events`); | |
let context: any; | |
app.on(events, (res: any) => { | |
context = res; | |
}); | |
webhook.on(events, (response: any) => { | |
app.log.info(response); | |
const data: WebhookAndContext = { | |
context: context, | |
webhook: response, | |
}; | |
resolve(data); | |
}); | |
} catch (error) { | |
app.log.error(`Error occurred while listening for ${events} events`); | |
reject(error); |
const { WEBHOOK_SECRET } = process.env; | ||
const app = getProbotInstance(); | ||
|
||
export function recieveGithubWebhooks() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a typo in the function name recieveGithubWebhooks
. It should be corrected to receiveGithubWebhooks
to maintain consistency and avoid potential confusion.
- export function recieveGithubWebhooks() {
+ export function receiveGithubWebhooks() {
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.
export function recieveGithubWebhooks() { | |
export function receiveGithubWebhooks() { |
} | ||
|
||
export function receiveGithubEvents(): Promise<Webhooks> { | ||
const webhookProxyUrl = "https://smee.io/HQ7QNBCix9HCl6sL"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The receiveGithubEvents
function uses a hardcoded webhook proxy URL. Consider externalizing this value to configuration files or environment variables for better flexibility and security.
function handleAppInstallationCreatedEvents(app: Probot, webhook: Webhooks) { | ||
const events: any[] = [eventConfigs.app_installation.created]; | ||
|
||
listeningForGithubWebhookEvents(app, events) | ||
listeningForGithubWebhookEvents(app, events, webhook) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The handleAppInstallationCreatedEvents
function is commented out. If this is intentional and the function is no longer needed, consider removing the code. If it's temporarily disabled, ensure there's a tracking system or comment explaining the reason.
Summary by CodeRabbit