mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	[CI] Dont create new review if existing and dont count tests (#9753)
This commit is contained in:
		
							
								
								
									
										38
									
								
								.github/workflows/auto-label-pr.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										38
									
								
								.github/workflows/auto-label-pr.yml
									
									
									
									
										vendored
									
									
								
							| @@ -201,6 +201,14 @@ jobs: | |||||||
|  |  | ||||||
|             const addedFiles = prFiles.filter(file => file.status === 'added').map(file => file.filename); |             const addedFiles = prFiles.filter(file => file.status === 'added').map(file => file.filename); | ||||||
|  |  | ||||||
|  |             // Calculate changes excluding root tests directory for too-big calculation | ||||||
|  |             const testChanges = prFiles | ||||||
|  |               .filter(file => file.filename.startsWith('tests/')) | ||||||
|  |               .reduce((sum, file) => sum + (file.additions || 0) + (file.deletions || 0), 0); | ||||||
|  |  | ||||||
|  |             const nonTestChanges = totalChanges - testChanges; | ||||||
|  |             console.log(`Test changes: ${testChanges}, Non-test changes: ${nonTestChanges}`); | ||||||
|  |  | ||||||
|             // Strategy: New Component detection |             // Strategy: New Component detection | ||||||
|             for (const file of addedFiles) { |             for (const file of addedFiles) { | ||||||
|               // Check for new component files: esphome/components/{component}/__init__.py |               // Check for new component files: esphome/components/{component}/__init__.py | ||||||
| @@ -385,11 +393,25 @@ jobs: | |||||||
|  |  | ||||||
|             // 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 = nonTestChanges > tooBigThreshold; | ||||||
|  |  | ||||||
|             if ((tooManyLabels || tooManyChanges) && !isMegaPR) { |             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} (non-test: ${nonTestChanges})`); | ||||||
|  |  | ||||||
|  |               // Get all reviews on this PR to check for existing bot reviews | ||||||
|  |               const { data: reviews } = await github.rest.pulls.listReviews({ | ||||||
|  |                 owner, | ||||||
|  |                 repo, | ||||||
|  |                 pull_number: pr_number | ||||||
|  |               }); | ||||||
|  |  | ||||||
|  |               // Check if there's already an active bot review requesting changes | ||||||
|  |               const existingBotReview = reviews.find(review => | ||||||
|  |                 review.user.type === 'Bot' && | ||||||
|  |                 review.state === 'CHANGES_REQUESTED' && | ||||||
|  |                 review.body && review.body.includes(BOT_COMMENT_MARKER) | ||||||
|  |               ); | ||||||
|  |  | ||||||
|               // If too big due to line changes only, keep original labels and add too-big |               // If too big due to line changes only, keep original labels and add too-big | ||||||
|               // If too big due to too many labels, replace with just too-big |               // If too big due to too many labels, replace with just too-big | ||||||
| @@ -399,14 +421,16 @@ jobs: | |||||||
|                 finalLabels = ['too-big']; |                 finalLabels = ['too-big']; | ||||||
|               } |               } | ||||||
|  |  | ||||||
|  |               // Only create a new review if there isn't already an active bot review | ||||||
|  |               if (!existingBotReview) { | ||||||
|                 // Create appropriate review message |                 // Create appropriate review message | ||||||
|                 let reviewBody; |                 let reviewBody; | ||||||
|                 if (tooManyLabels && tooManyChanges) { |                 if (tooManyLabels && tooManyChanges) { | ||||||
|                 reviewBody = `${BOT_COMMENT_MARKER}\nThis 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`; |                   reviewBody = `${BOT_COMMENT_MARKER}\nThis PR is too large with ${nonTestChanges} line changes (excluding tests) 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 = `${BOT_COMMENT_MARKER}\nThis 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`; |                   reviewBody = `${BOT_COMMENT_MARKER}\nThis 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 = `${BOT_COMMENT_MARKER}\nThis 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`; |                   reviewBody = `${BOT_COMMENT_MARKER}\nThis PR is too large with ${nonTestChanges} line changes (excluding tests). 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 | ||||||
| @@ -417,6 +441,10 @@ jobs: | |||||||
|                   body: reviewBody, |                   body: reviewBody, | ||||||
|                   event: 'REQUEST_CHANGES' |                   event: 'REQUEST_CHANGES' | ||||||
|                 }); |                 }); | ||||||
|  |                 console.log('Created new "too big" review requesting changes'); | ||||||
|  |               } else { | ||||||
|  |                 console.log('Skipping review creation - existing bot review already requesting changes'); | ||||||
|  |               } | ||||||
|             } else { |             } else { | ||||||
|               // Check if PR was previously too big but is now acceptable |               // Check if PR was previously too big but is now acceptable | ||||||
|               const wasPreviouslyTooBig = currentLabels.includes('too-big'); |               const wasPreviouslyTooBig = currentLabels.includes('too-big'); | ||||||
| @@ -424,7 +452,7 @@ jobs: | |||||||
|               if (wasPreviouslyTooBig || isMegaPR) { |               if (wasPreviouslyTooBig || isMegaPR) { | ||||||
|                 console.log('PR is no longer too big or has mega-pr label - dismissing bot reviews'); |                 console.log('PR is no longer too big or has mega-pr label - dismissing bot reviews'); | ||||||
|  |  | ||||||
|                 // Get all reviews on this PR |                 // Get all reviews on this PR to find reviews to dismiss | ||||||
|                 const { data: reviews } = await github.rest.pulls.listReviews({ |                 const { data: reviews } = await github.rest.pulls.listReviews({ | ||||||
|                   owner, |                   owner, | ||||||
|                   repo, |                   repo, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user