Conversation
This commit replaces the `tsickert/discord-webhook` GitHub Action with a custom TypeScript script (`send-webhook.ts`) for sending notifications. The primary motivation for this change is to enable file attachments in Discord notifications, a feature not easily supported by the previous action. This new implementation allows for: - Attaching build artifacts (extensions, userscripts) directly to the success notification. - Attaching the full, raw job log to failure notifications for more comprehensive debugging. The `get-failed-step-log.ts` script has also been updated to save the full log to a file to facilitate this.
- Add @types/axios@0.9.36 - Update axios to v1.11.0 - Update form-data to v4.0.4 - Update @types/form-data to v2.5.2
This introduces a new step in the build workflow to automatically run the `add-csp.ts` script. This script injects the required Content Security Policy directives for the `fakeProfile` user plugin, ensuring it functions correctly in the built extension.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Here's the code health analysis summary for commits Analysis Summary
|
There was a problem hiding this comment.
Summary of Changes
Hello @sang765, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
I am introducing new functionality to enhance the build process and communication for the fP extension. This includes adding a robust Discord webhook utility for sending messages and attaching files, particularly useful for reporting build failures. I've also updated the project's dependencies to support these new features and improved the README with more informative badges. Additionally, a new script is included to automate the modification of Content Security Policy (CSP) rules for specific Discord projects, enabling integration with a "fakeProfile" API.
Highlights
- Discord Webhook Integration: Added new TypeScript files (api/discord-webhook.ts and src/send-webhook.ts) to facilitate sending rich messages and file attachments to Discord webhooks, enabling automated notifications for build processes.
- Automated CSP Rule Addition: Introduced src/add-csp.ts, a script designed to programmatically add a Content Security Policy rule for "fakeprofile.is-always.online" to relevant project files, supporting integration with the fakeProfile API.
- Enhanced Build Log Retrieval: Modified src/get-failed-step-log.ts to save the full job log to a file, which can then be attached to Discord webhook notifications, providing more comprehensive failure details.
- Dependency Updates: Updated package.json and package-lock.json to include axios and form-data for HTTP requests and multipart form data handling, along with their respective type definitions.
- README.md Enhancements: Refreshed the README.md with new, more descriptive badges for technologies used (TypeScript, YAML, NodeJS), GitHub stars, workflow status, and Discord community links, improving project visibility and information.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request introduces several new scripts and utilities for interacting with Discord webhooks and managing build artifacts. The changes include a new API for sending webhook messages, a script to add CSP rules, and updates to the log retrieval script to save full logs.
My review focuses on improving the robustness and maintainability of the new TypeScript code. I've identified a critical issue in how file uploads are handled in src/send-webhook.ts that needs to be addressed. I've also suggested improvements for using asynchronous methods correctly in api/discord-webhook.ts and cleaning up dependencies in package.json. Additionally, I've recommended replacing magic numbers with enums to improve code clarity.
| for (const filePath of paths) { | ||
| if (fs.existsSync(filePath)) { | ||
| const fileName = path.basename(filePath); | ||
| form.append('file', fs.createReadStream(filePath), fileName); | ||
| fileAttached = true; | ||
| } else { | ||
| console.warn(`File not found at path: ${filePath}.`); | ||
| } | ||
| } |
There was a problem hiding this comment.
When sending multiple files to a Discord webhook, the field names for the files must be unique and follow the pattern files[n], where n is the index of the file. Currently, you are using the same field name 'file' for all attachments, which will likely result in only the last file being sent or an error. You should use a loop with an index to generate unique field names.
| for (const filePath of paths) { | |
| if (fs.existsSync(filePath)) { | |
| const fileName = path.basename(filePath); | |
| form.append('file', fs.createReadStream(filePath), fileName); | |
| fileAttached = true; | |
| } else { | |
| console.warn(`File not found at path: ${filePath}.`); | |
| } | |
| } | |
| paths.forEach((filePath, index) => { | |
| if (fs.existsSync(filePath)) { | |
| const fileName = path.basename(filePath); | |
| form.append(`files[${index}]`, fs.createReadStream(filePath), fileName); | |
| fileAttached = true; | |
| } else { | |
| console.warn(`File not found at path: ${filePath}.`); | |
| } | |
| }); |
| }, | ||
| "homepage": "https://github.com/TheLumiDevs/fP-extension-build#readme", | ||
| "devDependencies": { | ||
| "@types/form-data": "^2.5.2", |
| return axios.post(webhookUrl, formData, { | ||
| headers: { | ||
| ...formData.getHeaders(), | ||
| 'Content-Length': formData.getLengthSync() | ||
| } | ||
| }); |
There was a problem hiding this comment.
The formData.getLengthSync() method is synchronous and can block the event loop. Since this function is already async, it's better to use the asynchronous formData.getLength() method to keep your code non-blocking and more performant.
You could refactor this part like so:
formData.append('payload_json', JSON.stringify(payload));
const contentLength = await new Promise<number>((resolve, reject) => {
formData.getLength((err, length) => {
if (err) {
reject(err);
return;
}
resolve(length);
});
});
return axios.post(webhookUrl, formData, {
headers: {
...formData.getHeaders(),
'Content-Length': contentLength,
},
});| export function createLinkButton(label: string, url: string) { | ||
| return { | ||
| type: 1, | ||
| components: [{ | ||
| type: 2, | ||
| label, | ||
| style: 5, | ||
| url | ||
| }] | ||
| } as Component; | ||
| } No newline at end of file |
There was a problem hiding this comment.
Using magic numbers for component types and styles (e.g., type: 1, style: 5) makes the code harder to read and maintain. It's better to define and use enums for these values, which is a common practice when working with Discord's API. This will make the code more self-documenting and less prone to errors.
You could define enums like these at the top of your file:
export enum ComponentType {
ActionRow = 1,
Button = 2,
// ... other component types
}
export enum ButtonStyle {
Primary = 1,
Secondary = 2,
Success = 3,
Danger = 4,
Link = 5,
}Then, you can refactor createLinkButton and your type definitions to use them.
No description provided.