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

Discord GFI webhook #12436

Closed
wants to merge 8 commits into from
Closed

Discord GFI webhook #12436

wants to merge 8 commits into from

Conversation

pettinarip
Copy link
Member

@pettinarip pettinarip commented Mar 13, 2024

Summary by CodeRabbit

  • New Features
    • Added a GitHub Actions workflow to send "good first issues" from GitHub to Discord via webhook.
    • Introduced a script for fetching and formatting "good first issues" for Discord notifications.
  • Chores
    • Updated .env.example with configurations for Discord webhook and GitHub token.

Copy link
Contributor

coderabbitai bot commented Mar 13, 2024

Walkthrough

The recent update integrates a system to fetch new "good first issues" from GitHub and share them on Discord. It involves adding necessary configurations, setting up a GitHub Actions workflow for automation, and creating a script to fetch and send these issues to Discord. This integration aims to streamline the process of highlighting beginner-friendly contributions on Discord.

Changes

File(s) Change Summary
.env.example Added configurations for Discord webhook and GitHub token.
.github/workflows/gfi-discord-webhook.yml Introduced a GitHub Actions workflow for triggering Discord webhook.
src/lib/api/fetchGFIs.ts, src/scripts/gfi-discord-webhook.ts Added files to fetch and process "good first issues" from GitHub and send them to Discord.
src/lib/utils/gh.ts Added a function to convert labels to text based on mappings.

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>.
    • Generate unit-tests 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 tests 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@github-actions github-actions bot added dependencies 📦 Changes related to project dependencies review needed 👀 tooling 🔧 Changes related to tooling of the project labels Mar 13, 2024
Copy link

netlify bot commented Mar 13, 2024

Deploy Preview for ethereumorg ready!

Name Link
🔨 Latest commit f8550a1
🔍 Latest deploy log https://app.netlify.com/sites/ethereumorg/deploys/65f44c8dddcab70008ff5c51
😎 Deploy Preview https://deploy-preview-12436--ethereumorg.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.

@pettinarip
Copy link
Member Author

@coderabbitai review

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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d419871 and 9744ef0.
Files ignored due to path filters (1)
  • package.json is excluded by: !**/*.json
Files selected for processing (4)
  • .env.example (1 hunks)
  • .github/workflows/gfi-discord-webhook.yml (1 hunks)
  • src/lib/api/fetchGFIs.ts (1 hunks)
  • src/scripts/gfi-discord-webhook.ts (1 hunks)
Check Runs (1)
label completed (2)
Additional comments: 8
.github/workflows/gfi-discord-webhook.yml (2)
  • 3-6: The cron schedule is set to run hourly. Consider if this frequency aligns with the project's needs for posting GFIs to Discord. Too frequent updates might overwhelm the channel, while too infrequent might miss timely engagement opportunities.
  • 18-22: Ensure that the yarn discord-issues command correctly references the script intended to be executed. Additionally, verify that the secrets used here are correctly set up in the repository's settings to avoid runtime errors.
src/lib/api/fetchGFIs.ts (2)
  • 16-39: The fetchGFIs function correctly fetches issues from GitHub using the provided parameters and handles errors. However, consider adding more detailed logging or error handling for specific HTTP status codes to improve maintainability and debugging.
  • 24-24: Using a read-only token (ISSUES_GITHUB_TOKEN_READ_ONLY) is a good practice for security, as it minimizes potential damage if the token is compromised. Ensure this token has the minimal permissions necessary for fetching issues.
.env.example (1)
  • 33-40: The added configurations for Discord and GitHub tokens are clear and follow best practices for sensitive data management by not including actual values in the example file. Ensure that the actual .env file is properly secured and not included in version control.
src/scripts/gfi-discord-webhook.ts (3)
  • 5-5: Loading environment variables from .env.local is a good practice for local development. Ensure that for production deployments, the environment variables are securely provided by the deployment environment or CI/CD pipeline.
  • 48-58: The POST request to the Discord webhook URL is correctly formatted. However, consider adding error handling for specific error responses from Discord to provide more detailed feedback in case of failures.
  • 46-46: Ensure that the DISCORD_ID and DISCORD_TOKEN are securely managed and have the minimal permissions necessary for posting messages to the designated Discord channel.

.github/workflows/gfi-discord-webhook.yml Outdated Show resolved Hide resolved
.github/workflows/gfi-discord-webhook.yml Outdated Show resolved Hide resolved
@pettinarip pettinarip marked this pull request as ready for review March 13, 2024 15:50
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9744ef0 and 5e26735.
Files selected for processing (3)
  • .github/workflows/gfi-discord-webhook.yml (1 hunks)
  • src/lib/api/fetchGFIs.ts (1 hunks)
  • src/scripts/gfi-discord-webhook.ts (1 hunks)
Check Runs (1)
label completed (2)
Files skipped from review as they are similar to previous changes (3)
  • .github/workflows/gfi-discord-webhook.yml
  • src/lib/api/fetchGFIs.ts
  • src/scripts/gfi-discord-webhook.ts


import { fetchGFIs } from "../lib/api/fetchGFIs"

dotenv.config({ path: `.env.local` })
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
dotenv.config({ path: `.env.local` })
dotenv.config()

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
dotenv.config({ path: `.env.local` })
import "dotenv/config"

@@ -0,0 +1,61 @@
import * as dotenv from "dotenv"
Copy link
Member Author

Choose a reason for hiding this comment

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

Probably we won't need this

Suggested change
import * as dotenv from "dotenv"

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5e26735 and f8550a1.
Files selected for processing (3)
  • .github/workflows/gfi-discord-webhook.yml (1 hunks)
  • src/lib/utils/gh.ts (1 hunks)
  • src/scripts/gfi-discord-webhook.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • .github/workflows/gfi-discord-webhook.yml
  • src/scripts/gfi-discord-webhook.ts

Comment on lines +48 to +78
const LABELS_TO_SEARCH = ["content", "design", "dev", "doc", "translation"]
const LABELS_TO_TEXT = {
content: "content",
design: "design",
dev: "dev",
doc: "docs",
translation: "translation",
}

// Given a list of labels, it returns a string with the labels that match the
// LABELS_TO_SEARCH list, using the LABELS_TO_TEXT values
// Example:
// - ["content :pencil:", "ux design"] => "content, design"
// - ["documentation :emoji:", "dev required", "good first issue"] => "docs, dev"
export const rawLabelsToText = (labels: string[]) => {
return labels
.map((label) => {
const labelIndex = LABELS_TO_SEARCH.findIndex((l) =>
label.toLocaleLowerCase().includes(l)
)

if (labelIndex === -1) {
return
}

const labelMatched = LABELS_TO_SEARCH[labelIndex]
return LABELS_TO_TEXT[labelMatched]
})
.filter(Boolean)
.join(", ")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The rawLabelsToText function introduces a straightforward way to convert issue labels into a more readable format. A few suggestions for improvement:

  1. Performance: The current implementation uses findIndex inside a map, which results in O(n^2) complexity for large label lists. Consider optimizing this if the label list grows significantly.
  2. Clarity: The function assumes all labels will be in lowercase for matching. It's a good practice to document this assumption or ensure labels are normalized before this function is called.
  3. Error Handling: While the function handles non-matching labels gracefully, consider adding explicit error handling or logging for unexpected inputs to aid in debugging.

Overall, the function is well-implemented but could benefit from these refinements.

@pettinarip pettinarip mentioned this pull request Mar 19, 2024
Comment on lines +1 to +2
import * as dotenv from "dotenv"

Copy link
Member

Choose a reason for hiding this comment

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

In the getTranslationProgress.ts script we have import "dotenv/config", which points to node_modules/dotenv/config.d.ts containing export {};... This may be all we need to get the default env vars from the workflow

Suggested change
import * as dotenv from "dotenv"


import { fetchGFIs } from "../lib/api/fetchGFIs"

dotenv.config({ path: `.env.local` })
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
dotenv.config({ path: `.env.local` })
import "dotenv/config"

Comment on lines +35 to +40
# DISCORD_ID=
# DISCORD_TOKEN=

# Github token used for fetching good first issues
# ISSUES_GITHUB_TOKEN_READ_ONLY
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Discord environment (ID and token required for Discord webhook call)
# DISCORD_ID=
# DISCORD_TOKEN=
# Github token used for fetching good first issues
# ISSUES_GITHUB_TOKEN_READ_ONLY

Copy link
Member

Choose a reason for hiding this comment

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

@pettinarip
Copy link
Member Author

Thanks for the review @wackerow. I've created a new approach in #12500. We need to decide which approach is better for the use case. Once I have a decision I'll fix this comments 👍🏼

@pettinarip pettinarip marked this pull request as draft March 21, 2024 11:56
@pettinarip
Copy link
Member Author

Closing this implementation in favor of #12500.

@pettinarip pettinarip closed this Mar 21, 2024
@github-actions github-actions bot added the abandoned This has been abandoned or will not be implemented label Mar 21, 2024
@nhsz nhsz deleted the discord-gfi-webhook branch March 26, 2024 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
abandoned This has been abandoned or will not be implemented dependencies 📦 Changes related to project dependencies tooling 🔧 Changes related to tooling of the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants