mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	[CI] Label PR too-big if it has more than 1000 lines changed (#9744)
This commit is contained in:
		
							
								
								
									
										26
									
								
								.github/workflows/auto-label-pr.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										26
									
								
								.github/workflows/auto-label-pr.yml
									
									
									
									
										vendored
									
									
								
							| @@ -56,6 +56,7 @@ env: | |||||||
|     valve |     valve | ||||||
|   SMALL_PR_THRESHOLD: 30 |   SMALL_PR_THRESHOLD: 30 | ||||||
|   MAX_LABELS: 15 |   MAX_LABELS: 15 | ||||||
|  |   TOO_BIG_THRESHOLD: 1000 | ||||||
|  |  | ||||||
| jobs: | jobs: | ||||||
|   label: |   label: | ||||||
| @@ -147,6 +148,7 @@ jobs: | |||||||
|             const platformComponents = `${{ env.PLATFORM_COMPONENTS }}`.split('\n').filter(p => p.trim().length > 0).map(p => p.trim()); |             const platformComponents = `${{ env.PLATFORM_COMPONENTS }}`.split('\n').filter(p => p.trim().length > 0).map(p => p.trim()); | ||||||
|             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 }}'); | ||||||
|  |  | ||||||
|             // 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; | ||||||
| @@ -402,18 +404,34 @@ jobs: | |||||||
|  |  | ||||||
|             console.log('Computed labels:', finalLabels.join(', ')); |             console.log('Computed labels:', finalLabels.join(', ')); | ||||||
|  |  | ||||||
|             // Don't set more than max labels |             // Check if PR is allowed to be too big | ||||||
|             if (finalLabels.length > maxLabels) { |             const allowedTooBig = 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) { | ||||||
|               const originalLength = finalLabels.length; |               const originalLength = finalLabels.length; | ||||||
|               console.log(`Not setting ${originalLength} labels because out of range`); |               console.log(`PR is too big - Labels: ${originalLength}, Changes: ${totalChanges}`); | ||||||
|               finalLabels = ['too-big']; |               finalLabels = ['too-big']; | ||||||
|  |  | ||||||
|  |               // 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.`; | ||||||
|  |               } 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.`; | ||||||
|  |               } 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.`; | ||||||
|  |               } | ||||||
|  |  | ||||||
|               // Request changes on the PR |               // Request changes on the PR | ||||||
|               await github.rest.pulls.createReview({ |               await github.rest.pulls.createReview({ | ||||||
|                 owner, |                 owner, | ||||||
|                 repo, |                 repo, | ||||||
|                 pull_number: pr_number, |                 pull_number: pr_number, | ||||||
|                 body: `This PR is too large 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.`, |                 body: reviewBody, | ||||||
|                 event: 'REQUEST_CHANGES' |                 event: 'REQUEST_CHANGES' | ||||||
|               }); |               }); | ||||||
|             } |             } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user