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 | ||||
|   MAX_LABELS: 15 | ||||
|   TOO_BIG_THRESHOLD: 1000 | ||||
|   BOT_NAME: "esphome[bot]" | ||||
|  | ||||
| jobs: | ||||
|   label: | ||||
| @@ -122,6 +123,7 @@ jobs: | ||||
|             const smallPrThreshold = parseInt('${{ env.SMALL_PR_THRESHOLD }}'); | ||||
|             const maxLabels = parseInt('${{ env.MAX_LABELS }}'); | ||||
|             const tooBigThreshold = parseInt('${{ env.TOO_BIG_THRESHOLD }}'); | ||||
|             const botName = process.env.BOT_NAME; | ||||
|  | ||||
|             // Strategy: Merge to release or beta branch | ||||
|             const baseRef = context.payload.pull_request.base.ref; | ||||
| @@ -377,14 +379,14 @@ jobs: | ||||
|  | ||||
|             console.log('Computed labels:', finalLabels.join(', ')); | ||||
|  | ||||
|             // Check if PR is allowed to be too big | ||||
|             const allowedTooBig = currentLabels.includes('mega-pr'); | ||||
|             // Check if PR has mega-pr label | ||||
|             const isMegaPR = currentLabels.includes('mega-pr'); | ||||
|  | ||||
|             // Check if PR is too big (either too many labels or too many line changes) | ||||
|             const tooManyLabels = finalLabels.length > maxLabels; | ||||
|             const tooManyChanges = totalChanges > tooBigThreshold; | ||||
|  | ||||
|             if ((tooManyLabels || tooManyChanges) && !allowedTooBig) { | ||||
|             if ((tooManyLabels || tooManyChanges) && !isMegaPR) { | ||||
|               const originalLength = finalLabels.length; | ||||
|               console.log(`PR is too big - Labels: ${originalLength}, Changes: ${totalChanges}`); | ||||
|  | ||||
| @@ -399,11 +401,11 @@ jobs: | ||||
|               // Create appropriate review message | ||||
|               let reviewBody; | ||||
|               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) { | ||||
|                 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 { | ||||
|                 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 | ||||
| @@ -414,6 +416,49 @@ jobs: | ||||
|                 body: reviewBody, | ||||
|                 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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user