mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	[CI] Add url and dismiss reviews once conditions are met (#9748)
This commit is contained in:
		
							
								
								
									
										57
									
								
								.github/workflows/auto-label-pr.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										57
									
								
								.github/workflows/auto-label-pr.yml
									
									
									
									
										vendored
									
									
								
							| @@ -14,6 +14,7 @@ env: | |||||||
|   SMALL_PR_THRESHOLD: 30 |   SMALL_PR_THRESHOLD: 30 | ||||||
|   MAX_LABELS: 15 |   MAX_LABELS: 15 | ||||||
|   TOO_BIG_THRESHOLD: 1000 |   TOO_BIG_THRESHOLD: 1000 | ||||||
|  |   BOT_NAME: "esphome[bot]" | ||||||
|  |  | ||||||
| jobs: | jobs: | ||||||
|   label: |   label: | ||||||
| @@ -122,6 +123,7 @@ jobs: | |||||||
|             const smallPrThreshold = parseInt('${{ env.SMALL_PR_THRESHOLD }}'); |             const smallPrThreshold = parseInt('${{ env.SMALL_PR_THRESHOLD }}'); | ||||||
|             const maxLabels = parseInt('${{ env.MAX_LABELS }}'); |             const maxLabels = parseInt('${{ env.MAX_LABELS }}'); | ||||||
|             const tooBigThreshold = parseInt('${{ env.TOO_BIG_THRESHOLD }}'); |             const tooBigThreshold = parseInt('${{ env.TOO_BIG_THRESHOLD }}'); | ||||||
|  |             const botName = process.env.BOT_NAME; | ||||||
|  |  | ||||||
|             // Strategy: Merge to release or beta branch |             // Strategy: Merge to release or beta branch | ||||||
|             const baseRef = context.payload.pull_request.base.ref; |             const baseRef = context.payload.pull_request.base.ref; | ||||||
| @@ -377,14 +379,14 @@ jobs: | |||||||
|  |  | ||||||
|             console.log('Computed labels:', finalLabels.join(', ')); |             console.log('Computed labels:', finalLabels.join(', ')); | ||||||
|  |  | ||||||
|             // Check if PR is allowed to be too big |             // Check if PR has mega-pr label | ||||||
|             const allowedTooBig = currentLabels.includes('mega-pr'); |             const isMegaPR = currentLabels.includes('mega-pr'); | ||||||
|  |  | ||||||
|             // Check if PR is too big (either too many labels or too many line changes) |             // Check if PR is too big (either too many labels or too many line changes) | ||||||
|             const tooManyLabels = finalLabels.length > maxLabels; |             const tooManyLabels = finalLabels.length > maxLabels; | ||||||
|             const tooManyChanges = totalChanges > tooBigThreshold; |             const tooManyChanges = totalChanges > tooBigThreshold; | ||||||
|  |  | ||||||
|             if ((tooManyLabels || tooManyChanges) && !allowedTooBig) { |             if ((tooManyLabels || tooManyChanges) && !isMegaPR) { | ||||||
|               const originalLength = finalLabels.length; |               const originalLength = finalLabels.length; | ||||||
|               console.log(`PR is too big - Labels: ${originalLength}, Changes: ${totalChanges}`); |               console.log(`PR is too big - Labels: ${originalLength}, Changes: ${totalChanges}`); | ||||||
|  |  | ||||||
| @@ -399,11 +401,11 @@ jobs: | |||||||
|               // Create appropriate review message |               // Create appropriate review message | ||||||
|               let reviewBody; |               let reviewBody; | ||||||
|               if (tooManyLabels && tooManyChanges) { |               if (tooManyLabels && tooManyChanges) { | ||||||
|                 reviewBody = `This PR is too large with ${totalChanges} line changes and affects ${originalLength} different components/areas. Please consider breaking it down into smaller, focused PRs to make review easier and reduce the risk of conflicts.`; |                 reviewBody = `This PR is too large with ${totalChanges} line changes and affects ${originalLength} different components/areas. Please consider breaking it down into smaller, focused PRs to make review easier and reduce the risk of conflicts.\n\nFor guidance on breaking down large PRs, see: https://developers.esphome.io/contributing/submitting-your-work/#but-howwww-looonnnggg`; | ||||||
|               } else if (tooManyLabels) { |               } else if (tooManyLabels) { | ||||||
|                 reviewBody = `This PR affects ${originalLength} different components/areas. Please consider breaking it down into smaller, focused PRs to make review easier and reduce the risk of conflicts.`; |                 reviewBody = `This PR affects ${originalLength} different components/areas. Please consider breaking it down into smaller, focused PRs to make review easier and reduce the risk of conflicts.\n\nFor guidance on breaking down large PRs, see: https://developers.esphome.io/contributing/submitting-your-work/#but-howwww-looonnnggg`; | ||||||
|               } else { |               } else { | ||||||
|                 reviewBody = `This PR is too large with ${totalChanges} line changes. Please consider breaking it down into smaller, focused PRs to make review easier and reduce the risk of conflicts.`; |                 reviewBody = `This PR is too large with ${totalChanges} line changes. Please consider breaking it down into smaller, focused PRs to make review easier and reduce the risk of conflicts.\n\nFor guidance on breaking down large PRs, see: https://developers.esphome.io/contributing/submitting-your-work/#but-howwww-looonnnggg`; | ||||||
|               } |               } | ||||||
|  |  | ||||||
|               // Request changes on the PR |               // Request changes on the PR | ||||||
| @@ -414,6 +416,49 @@ jobs: | |||||||
|                 body: reviewBody, |                 body: reviewBody, | ||||||
|                 event: 'REQUEST_CHANGES' |                 event: 'REQUEST_CHANGES' | ||||||
|               }); |               }); | ||||||
|  |             } else { | ||||||
|  |               // Check if PR was previously too big but is now acceptable | ||||||
|  |               const wasPreviouslyTooBig = currentLabels.includes('too-big'); | ||||||
|  |  | ||||||
|  |               if (wasPreviouslyTooBig || isMegaPR) { | ||||||
|  |                 console.log('PR is no longer too big or has mega-pr label - dismissing bot reviews'); | ||||||
|  |  | ||||||
|  |                 // Get all reviews on this PR | ||||||
|  |                 const { data: reviews } = await github.rest.pulls.listReviews({ | ||||||
|  |                   owner, | ||||||
|  |                   repo, | ||||||
|  |                   pull_number: pr_number | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |                 // Find bot reviews that requested changes | ||||||
|  |                 const botReviews = reviews.filter(review => | ||||||
|  |                   review.user.login === botName && | ||||||
|  |                   review.state === 'CHANGES_REQUESTED' && | ||||||
|  |                   review.body && ( | ||||||
|  |                     review.body.includes('This PR is too large') || | ||||||
|  |                     review.body.includes('This PR affects') || | ||||||
|  |                     review.body.includes('different components/areas') | ||||||
|  |                   ) | ||||||
|  |                 ); | ||||||
|  |  | ||||||
|  |                 // Dismiss bot reviews | ||||||
|  |                 for (const review of botReviews) { | ||||||
|  |                   try { | ||||||
|  |                     await github.rest.pulls.dismissReview({ | ||||||
|  |                       owner, | ||||||
|  |                       repo, | ||||||
|  |                       pull_number: pr_number, | ||||||
|  |                       review_id: review.id, | ||||||
|  |                       message: isMegaPR ? | ||||||
|  |                         'Review dismissed: mega-pr label was added' : | ||||||
|  |                         'Review dismissed: PR size is now acceptable' | ||||||
|  |                     }); | ||||||
|  |                     console.log(`Dismissed review ${review.id}`); | ||||||
|  |                   } catch (error) { | ||||||
|  |                     console.log(`Failed to dismiss review ${review.id}:`, error.message); | ||||||
|  |                   } | ||||||
|  |                 } | ||||||
|  |               } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             // Add new labels |             // Add new labels | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user