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

Implement GitHub PR Issue Checker Workflow #2336

Closed
wants to merge 1 commit into from

Conversation

smog-root
Copy link

@smog-root smog-root commented Oct 17, 2024

Fixes #2309

Usage:

  1. When a pull request is created or edited, the workflow automatically triggers.

  2. The workflow checks for:

  • A non-empty PR description.
  • A valid issue reference format (Fixes #<issue-number> or Fixes #NEW).
  1. If either check fails, the PR will be marked as failing, and the author will receive clear error messages in the PR comments.
  2. If all checks pass, a confirmation message will indicate that the PR is valid.

Note: Kindly add all the labels added to the issue, to this PR!

Summary by CodeRabbit

  • New Features
    • Introduced a new GitHub Actions workflow to validate pull request descriptions, ensuring they are not empty and follow a specific format.
  • Bug Fixes
    • Improved error handling for pull requests missing descriptions or required formatting.

Copy link

vercel bot commented Oct 17, 2024

@smog-root is attempting to deploy a commit to the Vivek Prajapati's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Oct 17, 2024

Walkthrough

A new GitHub Actions workflow file named pr-checker.yml has been added to validate pull request descriptions. This workflow is triggered on pull request events, specifically when a pull request is opened or edited. It includes a job that checks for the presence of a description and ensures it follows a specific format, particularly requiring the phrase "Fixes #" if no existing issues are addressed.

Changes

File Path Change Summary
.github/workflows/pr-checker.yml Added a new workflow to validate pull request descriptions.

Assessment against linked issues

Objective Addressed Explanation
Validate email domains for signup (2309) The changes do not address email validation.

🐰 In the meadow, where bunnies play,
A workflow blooms to guide the way!
With checks in place, both bright and clear,
Pull requests now bring no fear!
Hop along, let the good times roll,
For every detail, we now have control! 🐇✨


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
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: 3

🧹 Outside diff range and nitpick comments (1)
.github/workflows/pr-checker.yml (1)

1-5: Remove unnecessary comment and LGTM for the rest.

The workflow name and trigger events are well-defined and appropriate for the task. However, I suggest removing the comment on line 2 as it's not a standard practice in workflow files and doesn't add value to the configuration.

Apply this diff to remove the unnecessary comment:

name: PR Issue Checker
- # Created my @smog-root.
on:
  pull_request:
    types: [opened, edited]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 70afccd and c92d87e.

📒 Files selected for processing (1)
  • .github/workflows/pr-checker.yml (1 hunks)
🧰 Additional context used
🪛 actionlint
.github/workflows/pr-checker.yml

13-13: the runner of "actions/checkout@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


17-17: "github.event.pull_request.body" is potentially untrusted. avoid using it directly in inline scripts. instead, pass it through an environment variable. see https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions for more details

(expression)

Comment on lines +15 to +30
- name: Check PR Description
id: check_pr_description
run: |
PR_DESCRIPTION="${{ github.event.pull_request.body }}"
if [[ -z "$PR_DESCRIPTION" ]]; then
echo "PR description is missing."
exit 1
fi

if [[ ! "$PR_DESCRIPTION" =~ Fixes\ #[0-9]+ ]]; then
echo "The PR description should include 'Fixes #<issue-number>' if not addressing any issue."
echo "##[error]Fixes #NEW must be included in the description."
exit 1
fi

echo "PR description is valid."
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Improve security and flexibility of PR description check.

The PR description check logic is generally good, but there are some security and flexibility improvements to be made:

  1. Avoid using github.event.pull_request.body directly in the inline script for security reasons.
  2. Make the issue reference check more flexible to account for variations like "Closes" or multiple issue references.
  3. Consider adding a check for the "Fixes #NEW" case mentioned in the PR objectives.

Here's an improved version of the step:

      - name: Check PR Description
        env:
          PR_BODY: ${{ github.event.pull_request.body }}
        run: |
          if [[ -z "$PR_BODY" ]]; then
            echo "PR description is missing."
            exit 1
          fi

          if ! grep -qE "(Fixes|Closes) #([0-9]+|NEW)( *, *#([0-9]+|NEW))*" <<< "$PR_BODY"; then
            echo "The PR description should include 'Fixes #<issue-number>' or 'Fixes #NEW'."
            echo "##[error]Invalid issue reference format in the description."
            exit 1
          fi

          echo "PR description is valid."

This version:

  1. Uses an environment variable to pass the PR body, improving security.
  2. Allows for "Fixes" or "Closes" keywords.
  3. Supports multiple issue references.
  4. Includes the "Fixes #NEW" case.
🧰 Tools
🪛 actionlint

17-17: "github.event.pull_request.body" is potentially untrusted. avoid using it directly in inline scripts. instead, pass it through an environment variable. see https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions for more details

(expression)

Comment on lines +32 to +33
- name: Output result
run: echo "All checks passed."
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add label reminder and consider removing redundant output.

The current output step is redundant as the workflow will fail if any previous step fails. Additionally, it doesn't include the reminder about labels mentioned in the PR objectives.

Consider replacing this step with a more useful reminder about labels:

      - name: Reminder about labels
        run: |
          echo "PR checks passed successfully."
          echo "Reminder: Please ensure you've added all labels associated with the linked issue to this pull request."

This step provides value by reminding the PR author about the labels while still indicating that all checks have passed.

Comment on lines +7 to +13
jobs:
check_pr_description:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Update the checkout action to the latest version.

The job definition and runner selection look good. However, the actions/checkout action is using an outdated version.

Update the checkout action to the latest version by applying this diff:

    steps:
      - name: Checkout code
-       uses: actions/checkout@v2
+       uses: actions/checkout@v3

This will ensure you're using the most up-to-date and secure version of the action.

📝 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
jobs:
check_pr_description:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
jobs:
check_pr_description:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
🧰 Tools
🪛 actionlint

13-13: the runner of "actions/checkout@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

Copy link

vercel bot commented Oct 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vigybag ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2024 1:15pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant