Entity store/schedule maintainers #2
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
| # Generic auto-approve for machine-created PRs. | |
| # Add new rules to the whitelist in the check step; approval runs when any rule matches. | |
| on: | |
| pull_request_target: | |
| types: | |
| - opened | |
| jobs: | |
| approve: | |
| name: Auto-approve machine PR | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: write | |
| steps: | |
| - id: check | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | |
| with: | |
| script: | | |
| const user = context.payload.pull_request.user.login; | |
| const headRef = context.payload.pull_request.head.ref; | |
| const baseRef = context.payload.pull_request.base.ref; | |
| const whitelist = [ | |
| // { user: 'kibanamachine', branchPrefix: 'api_docs', baseMatch: /^main$/ }, | |
| // { user: 'kibanamachine', branchPrefix: 'backport', baseNotMatch: /^main$/ }, | |
| { user: 'kibanamachine', branchPrefix: 'scout_metadata_update' }, | |
| // { user: 'elasticmachine', branchPrefix: 'update-bundled-packages', paths: ['fleet_packages.json'] }, | |
| ]; | |
| // Fetch the list of changed files in the PR | |
| const files = await github.rest.pulls.listFiles({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: context.payload.pull_request.number, | |
| }); | |
| const changedFiles = files.data.map(file => file.filename); | |
| core.info(`Changed files: ${changedFiles.join(', ')}`); | |
| const matches = whitelist.some((rule) => { | |
| if (rule.user !== user) return false; | |
| if (!headRef.startsWith(rule.branchPrefix)) return false; | |
| if (rule.baseMatch && !rule.baseMatch.test(baseRef)) return false; | |
| if (rule.baseNotMatch && rule.baseNotMatch.test(baseRef)) return false; | |
| // If paths is specified, verify at least one changed file matches | |
| if (rule.paths) { | |
| const hasMatchingFile = changedFiles.some(file => | |
| rule.paths.some(path => { | |
| // Support glob patterns | |
| if (path.includes('*')) { | |
| const regex = new RegExp('^' + path.replace(/\*/g, '.*') + '$'); | |
| return regex.test(file); | |
| } | |
| return file === path; | |
| }) | |
| ); | |
| if (!hasMatchingFile) { | |
| core.info(`File check failed for rule ${rule.user}/${rule.branchPrefix}: no changed files match paths`); | |
| return false; | |
| } | |
| } | |
| return true; | |
| }); | |
| core.setOutput('should_approve', matches ? 'true' : 'false'); | |
| - uses: hmarr/auto-approve-action@f0939ea97e9205ef24d872e76833fa908a770363 # v4.0.0 | |
| if: steps.check.outputs.should_approve == 'true' | |
| with: | |
| github-token: ${{ secrets.KIBANAMACHINE_TOKEN }} |