[ENG-2185] Adding Consent #2974
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Check PR Size | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| jobs: | |
| check-pr-size: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check PR size | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const pr = context.payload.pull_request; | |
| // Fetch all files (handles pagination automatically) | |
| const files = await github.paginate(github.rest.pulls.listFiles, { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: pr.number, | |
| }); | |
| // Calculate total lines from ALL files (including renamed) | |
| const additions = files.reduce((sum, file) => sum + file.additions, 0); | |
| const deletions = files.reduce((sum, file) => sum + file.deletions, 0); | |
| const totalLinesChanged = additions; | |
| // Filter out renamed files and empty __init__.py files | |
| const nonExcludedFiles = files.filter(file => { | |
| const isRenamed = file.status === 'renamed'; | |
| const isEmptyInit = file.filename.endsWith('__init__.py') && | |
| file.additions === 0 && | |
| file.deletions === 0; | |
| return !isRenamed && !isEmptyInit; | |
| }); | |
| const changedFiles = nonExcludedFiles.length; | |
| const linesLimit = 500; | |
| const filesLimit = 15; | |
| let failMessage = ''; | |
| if (totalLinesChanged > linesLimit) { | |
| const lineWord = totalLinesChanged === 1 ? 'Line' : 'Lines'; | |
| failMessage += `${lineWord} changed: ${totalLinesChanged} (limit: ${linesLimit})\n`; | |
| } | |
| if (changedFiles > filesLimit) { | |
| const fileWord = changedFiles === 1 ? 'File' : 'Files'; | |
| failMessage += `${fileWord} changed: ${changedFiles} (limit: ${filesLimit})\n`; | |
| } | |
| if (failMessage) { | |
| const excludedCount = files.length - nonExcludedFiles.length; | |
| if (excludedCount > 0) { | |
| const excludedFileWord = excludedCount === 1 ? 'file' : 'files'; | |
| failMessage += `(${excludedCount} ${excludedFileWord} excluded: renamed files and empty __init__.py)\n`; | |
| } | |
| failMessage += '\nPlease consider splitting this PR into smaller, more focused changes.'; | |
| core.setFailed(failMessage); | |
| } else { | |
| const excludedCount = files.length - nonExcludedFiles.length; | |
| const lineWord = totalLinesChanged === 1 ? 'line' : 'lines'; | |
| const fileWord = changedFiles === 1 ? 'file' : 'files'; | |
| const excludedFileWord = excludedCount === 1 ? 'file' : 'files'; | |
| console.log(`PR size check passed (${totalLinesChanged} ${lineWord}, ${changedFiles} ${fileWord}${excludedCount > 0 ? `, ${excludedCount} ${excludedFileWord} excluded` : ''})`); | |
| } |