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

Added Merge Conflict Check #3138

Merged

Conversation

Aad1tya27
Copy link
Contributor

@Aad1tya27 Aad1tya27 commented Jan 4, 2025

What kind of change does this PR introduce?
Feature

Issue Number:

Fixes #3015

Did you add tests for your changes?
No

Snapshots/Videos:
image

If relevant, did you update the documentation?
No

Summary
Added the Merge Conflict Check in .github/workflows/pull-request.yml

Does this PR introduce a breaking change?
No

Other information

Have you read the contributing guide?
Yes

Summary by CodeRabbit

  • New Features
    • Added an automated merge conflict detection job to GitHub Actions workflow.
    • Provides real-time status of pull request mergeable conditions.

@Aad1tya27 Aad1tya27 requested a review from palisadoes as a code owner January 4, 2025 13:22
Copy link
Contributor

coderabbitai bot commented Jan 4, 2025

Walkthrough

A new GitHub Actions job called Merge-Conflict-Check has been added to the .github/workflows/pull-request.yml workflow. This job is designed to detect merge conflicts in pull requests by utilizing GitHub's API to check the mergeable status. It runs on Ubuntu and performs two primary steps: checking out the code and retrieving the pull request's mergeable status, providing clear output about potential merge conflicts.

Changes

File Change Summary
.github/workflows/pull-request.yml Added new Merge-Conflict-Check job to detect merge conflicts using GitHub API

Assessment against linked issues

Objective Addressed Explanation
Detect PR merge conflicts
Check conflicts after PR submission
Avoid external dependencies Uses native GitHub API

Possibly related PRs

Suggested reviewers

  • palisadoes
  • varshith257
  • pranshugupta54
  • AVtheking
  • gautam-divyanshu

Poem

🐰 Merge conflicts, oh what a fright!
Our GitHub Action shines so bright
Checking PRs with rabbit-like care
No conflicts shall slip past our stare
Code harmony is now our delight! 🔍


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.

Copy link

github-actions bot commented Jan 4, 2025

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

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

🧹 Nitpick comments (3)
.github/workflows/pull-request.yml (3)

453-463: Add workflow dependencies for better integration

The merge conflict check should run early in the workflow to fail fast and prevent unnecessary builds. Consider adding this job as a dependency for other jobs.

Add the following to integrate with the workflow:

  Merge-Conflict-Check:
    name: Check for Merge Conflicts
    runs-on: ubuntu-latest
+   needs: []  # Run early in the workflow
+   if: github.actor != 'dependabot[bot]'  # Consistent with other jobs
    steps:

Then update other jobs to depend on this check:

  Code-Quality-Checks:
    name: Performs linting, formatting, type-checking...
    runs-on: ubuntu-latest
+   needs: [Merge-Conflict-Check]
    steps:

452-452: Consider job placement in workflow

The merge conflict check is added at the end of the workflow file. Consider moving it closer to the beginning, near other early validation jobs like Check-Target-Branch, to maintain a logical grouping of validation checks.


453-479: Add documentation for the merge conflict check

Consider adding documentation about this new workflow job:

  1. Update the workflow file's header comments to mention this check
  2. Add a section in the PR guidelines (PR_GUIDELINES.md) about merge conflict detection
🧰 Tools
🪛 yamllint (1.35.1)

[error] 465-465: trailing spaces

(trailing-spaces)


[error] 479-479: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fb48e16 and bb5268e.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
.github/workflows/pull-request.yml

[error] 465-465: trailing spaces

(trailing-spaces)


[error] 479-479: no new line character at the end of file

(new-line-at-end-of-file)

.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
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: 1

🔭 Outside diff range comments (1)
.github/workflows/pull-request.yml (1)

Line range hint 12-16: Add workflow trigger for target branch updates

The current workflow trigger configuration doesn't automatically re-run when the target branch is updated. This can lead to stale merge conflict status.

Add pull_request_target event or modify the existing trigger:

 on:
   pull_request:
     branches:
       - '**'
+    types:
+      - opened
+      - reopened
+      - synchronize
+      - ready_for_review
+  pull_request_target:
+    types:
+      - synchronized
🧰 Tools
🪛 yamllint (1.35.1)

[error] 461-461: trailing spaces

(trailing-spaces)


[error] 475-475: no new line character at the end of file

(new-line-at-end-of-file)

🧹 Nitpick comments (1)
.github/workflows/pull-request.yml (1)

461-461: Fix YAML formatting issues

There are two formatting issues to address:

  1. Remove trailing spaces
  2. Add newline at end of file

Apply this diff:

-        run: |  
+        run: |
           PR_NUMBER=${{ github.event.pull_request.number }}
           # ... rest of the script ...
-          fi
-        shell: bash
\ No newline at end of file
+          fi
+        shell: bash
+

Also applies to: 475-475

🧰 Tools
🪛 yamllint (1.35.1)

[error] 461-461: trailing spaces

(trailing-spaces)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bb5268e and c3a7335.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
.github/workflows/pull-request.yml

[error] 461-461: trailing spaces

(trailing-spaces)


[error] 475-475: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (2)
.github/workflows/pull-request.yml (2)

457-459: LGTM!

The checkout step is correctly implemented using the latest version of the action.


460-475: Improve error handling and reliability

The implementation needs improvements for error handling and retry mechanism.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 461-461: trailing spaces

(trailing-spaces)


[error] 475-475: no new line character at the end of file

(new-line-at-end-of-file)

.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 4, 2025
Copy link

codecov bot commented Jan 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.64%. Comparing base (fb48e16) to head (7788b49).

Additional details and impacted files
@@                  Coverage Diff                  @@
##           develop-postgres    #3138       +/-   ##
=====================================================
+ Coverage             20.93%   89.64%   +68.70%     
=====================================================
  Files                   301      322       +21     
  Lines                  7685     8451      +766     
  Branches               1678     1900      +222     
=====================================================
+ Hits                   1609     7576     +5967     
+ Misses                 5977      646     -5331     
- Partials                 99      229      +130     

☔ 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 (3)
.github/workflows/pull-request.yml (3)

18-25: Align pull_request_target events with pull_request events

The pull_request_target trigger only listens for synchronize events, while pull_request listens for multiple events. Consider aligning them to ensure consistent merge conflict detection across all PR events.

  pull_request_target:
    types:
+     - opened
+     - reopened
      - synchronize
+     - ready_for_review

470-505: Improve shell script style and error handling

While the script logic is solid, we can improve the shell scripting style:

  1. Check curl exit code directly instead of using $?
  2. Use heredoc for better script readability
       - name: Check Mergeable Status via API
-        run: |  
-          PR_NUMBER=${{ github.event.pull_request.number }}
-          max_retries=3
-          retry_delay=5
-          
-          for ((i=1; i<=max_retries; i++)); do
-            echo "Attempt $i of $max_retries"
-            
-            response=$(curl -s -f -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-              "https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER")
-            
-            if [ $? -ne 0 ]; then
+        run: |
+          cat << 'EOF' > check_mergeable.sh
+          #!/bin/bash
+          set -euo pipefail
+
+          PR_NUMBER=$1
+          GITHUB_TOKEN=$2
+          GITHUB_REPOSITORY=$3
+          max_retries=3
+          retry_delay=5
+
+          for ((i=1; i<=max_retries; i++)); do
+            echo "Attempt $i of $max_retries"
+
+            if ! response=$(curl -s -f -H "Authorization: Bearer ${GITHUB_TOKEN}" \
+              "https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}"); then
               echo "Failed to call GitHub API"
               if [ $i -eq $max_retries ]; then
                 exit 1
               fi
               sleep $retry_delay
               continue
-            fi
-            
-            mergeable=$(echo "$response" | jq -r '.mergeable')
-            if [ "$mergeable" == "true" ]; then
+            fi
+
+            if mergeable=$(echo "$response" | jq -r '.mergeable'); then
+              if [ "$mergeable" == "true" ]; then
               echo "No conflicts detected."
               exit 0
-            elif [ "$mergeable" == "false" ]; then
+              elif [ "$mergeable" == "false" ]; then
               echo "Merge conflicts detected."
               exit 1
-            else
+              else
               echo "Mergeable status unknown."
               if [ $i -eq $max_retries ]; then
                 exit 1
               fi
               sleep $retry_delay
-            fi
+              fi
+            else
+              echo "Failed to parse mergeable status"
+              exit 1
+            fi
           done
+          EOF
+
+          chmod +x check_mergeable.sh
+          ./check_mergeable.sh \
+            "${{ github.event.pull_request.number }}" \
+            "${{ secrets.GITHUB_TOKEN }}" \
+            "${{ github.repository }}"
🧰 Tools
🪛 actionlint (1.7.4)

471-471: shellcheck reported issue in this script: SC2181:style:11:8: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)

🪛 yamllint (1.35.1)

[error] 471-471: trailing spaces

(trailing-spaces)


[error] 475-475: trailing spaces

(trailing-spaces)


[error] 478-478: trailing spaces

(trailing-spaces)


[error] 481-481: trailing spaces

(trailing-spaces)


[error] 490-490: trailing spaces

(trailing-spaces)


[error] 505-505: no new line character at the end of file

(new-line-at-end-of-file)


471-505: Fix YAML formatting issues

There are several YAML formatting issues that should be fixed:

  1. Remove trailing spaces
  2. Add newline at end of file
-        run: |  
+        run: |
           PR_NUMBER=${{ github.event.pull_request.number }}
           max_retries=3
           retry_delay=5
-          
+
           for ((i=1; i<=max_retries; i++)); do
             echo "Attempt $i of $max_retries"
-            
+
             response=$(curl -s -f -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
               "https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER")
-            
+
             if [ $? -ne 0 ]; then
               echo "Failed to call GitHub API"
               if [ $i -eq $max_retries ]; then
                 exit 1
               fi
               sleep $retry_delay
               continue
             fi
-            
+
             mergeable=$(echo "$response" | jq -r '.mergeable')
             # ... rest of the script ...
           done
+
🧰 Tools
🪛 actionlint (1.7.4)

471-471: shellcheck reported issue in this script: SC2181:style:11:8: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)

🪛 yamllint (1.35.1)

[error] 471-471: trailing spaces

(trailing-spaces)


[error] 475-475: trailing spaces

(trailing-spaces)


[error] 478-478: trailing spaces

(trailing-spaces)


[error] 481-481: trailing spaces

(trailing-spaces)


[error] 490-490: trailing spaces

(trailing-spaces)


[error] 505-505: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c3a7335 and 84e518d.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (2 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/pull-request.yml

471-471: shellcheck reported issue in this script: SC2181:style:11:8: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)

🪛 yamllint (1.35.1)
.github/workflows/pull-request.yml

[error] 471-471: trailing spaces

(trailing-spaces)


[error] 475-475: trailing spaces

(trailing-spaces)


[error] 478-478: trailing spaces

(trailing-spaces)


[error] 481-481: trailing spaces

(trailing-spaces)


[error] 490-490: trailing spaces

(trailing-spaces)


[error] 505-505: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (1)
.github/workflows/pull-request.yml (1)

461-466: LGTM! Job configuration follows project conventions

The job configuration is well-structured and consistent with other jobs in the workflow:

  • Runs on ubuntu-latest
  • Skips dependabot PRs
  • Appropriate dependency on Code-Quality-Checks

Copy link
Member

@noman2002 noman2002 left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ignore-sensitive-files-pr The contributor has a legitimate reason for editiing protected files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants