mirror of
https://github.com/herdrdev/herdr.git
synced 2026-09-23 00:01:08 +00:00
Bumps the github-actions group with 7 updates: | Package | From | To | | --- | --- | --- | | [actions/checkout](https://github.com/actions/checkout) | `4` | `6` | | [actions/github-script](https://github.com/actions/github-script) | `7` | `9` | | [actions/upload-artifact](https://github.com/actions/upload-artifact) | `4` | `7` | | [extractions/setup-just](https://github.com/extractions/setup-just) | `3` | `4` | | [taiki-e/install-action](https://github.com/taiki-e/install-action) | `2.75.19` | `2.79.1` | | [actions/download-artifact](https://github.com/actions/download-artifact) | `4` | `8` | | [softprops/action-gh-release](https://github.com/softprops/action-gh-release) | `2` | `3` | Updates `actions/checkout` from 4 to 6 - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v4...v6) Updates `actions/github-script` from 7 to 9 - [Release notes](https://github.com/actions/github-script/releases) - [Commits](https://github.com/actions/github-script/compare/v7...v9) Updates `actions/upload-artifact` from 4 to 7 - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v4...v7) Updates `extractions/setup-just` from 3 to 4 - [Release notes](https://github.com/extractions/setup-just/releases) - [Commits](https://github.com/extractions/setup-just/compare/v3...v4) Updates `taiki-e/install-action` from 2.75.19 to 2.79.1 - [Release notes](https://github.com/taiki-e/install-action/releases) - [Changelog](https://github.com/taiki-e/install-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/taiki-e/install-action/compare/5f57d6cb7cd20b14a8a27f522884c4bc8a187458...b550161ef8a7bc4f2a671c0b03a18ac9ccedea1e) Updates `actions/download-artifact` from 4 to 8 - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v4...v8) Updates `softprops/action-gh-release` from 2 to 3 - [Release notes](https://github.com/softprops/action-gh-release/releases) - [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md) - [Commits](https://github.com/softprops/action-gh-release/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: actions/github-script dependency-version: '9' dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: actions/upload-artifact dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: extractions/setup-just dependency-version: '4' dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: taiki-e/install-action dependency-version: 2.79.1 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions - dependency-name: actions/download-artifact dependency-version: '8' dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: softprops/action-gh-release dependency-version: '3' dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
119 lines
4.7 KiB
YAML
119 lines
4.7 KiB
YAML
name: PR Gate
|
|
|
|
on:
|
|
pull_request_target:
|
|
types: [opened, reopened]
|
|
|
|
jobs:
|
|
check-contributor:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
issues: write
|
|
pull-requests: write
|
|
steps:
|
|
- name: Check if contributor is approved
|
|
uses: actions/github-script@v9
|
|
with:
|
|
script: |
|
|
const prAuthor = context.payload.pull_request.user.login;
|
|
const reopener = context.payload.sender?.login ?? null;
|
|
const action = context.payload.action;
|
|
const defaultBranch = context.payload.repository.default_branch;
|
|
const maintainerPermissions = ['admin', 'maintain', 'write'];
|
|
|
|
if (prAuthor.endsWith('[bot]') || prAuthor === 'dependabot[bot]') {
|
|
console.log(`Skipping bot: ${prAuthor}`);
|
|
return;
|
|
}
|
|
|
|
async function getPermission(username) {
|
|
try {
|
|
const { data: permissionLevel } = await github.rest.repos.getCollaboratorPermissionLevel({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
username,
|
|
});
|
|
return permissionLevel.permission;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
async function getTextFile(path) {
|
|
const { data: fileContent } = await github.rest.repos.getContent({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
path,
|
|
ref: defaultBranch,
|
|
});
|
|
|
|
if (!('content' in fileContent) || typeof fileContent.content !== 'string') {
|
|
throw new Error(`Expected file content for ${path}`);
|
|
}
|
|
|
|
return Buffer.from(fileContent.content, 'base64').toString('utf8');
|
|
}
|
|
|
|
async function closePullRequest(message) {
|
|
await github.rest.issues.createComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: context.payload.pull_request.number,
|
|
body: message,
|
|
});
|
|
|
|
await github.rest.pulls.update({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
pull_number: context.payload.pull_request.number,
|
|
state: 'closed',
|
|
});
|
|
}
|
|
|
|
const authorPermission = await getPermission(prAuthor);
|
|
if (maintainerPermissions.includes(authorPermission)) {
|
|
console.log(`${prAuthor} is a collaborator with ${authorPermission} access`);
|
|
return;
|
|
}
|
|
|
|
if (action === 'reopened') {
|
|
const reopenerPermission = reopener ? await getPermission(reopener) : null;
|
|
if (maintainerPermissions.includes(reopenerPermission)) {
|
|
console.log(`${reopener} reopened this PR with ${reopenerPermission} access; leaving it open`);
|
|
return;
|
|
}
|
|
}
|
|
|
|
const approvedContent = await getTextFile('.github/APPROVED_CONTRIBUTORS');
|
|
const approvedList = approvedContent
|
|
.split('\n')
|
|
.map(line => line.trim().toLowerCase())
|
|
.filter(line => line && !line.startsWith('#'));
|
|
const isApprovedContributor = approvedList.includes(prAuthor.toLowerCase());
|
|
|
|
if (isApprovedContributor) {
|
|
console.log(`${prAuthor} is in the approved contributors list`);
|
|
return;
|
|
}
|
|
|
|
console.log(`${prAuthor} is not approved, closing PR`);
|
|
|
|
const message = [
|
|
`Hi @${prAuthor}, thanks for your interest in contributing!`,
|
|
'',
|
|
'We ask new contributors to open an issue first before submitting a PR. This helps us discuss the approach and avoid wasted effort.',
|
|
'',
|
|
'Herdr is opinionated about how it should look, feel, and work. If your change affects UI, behavior, interaction patterns, or product direction, discuss it in an issue first.',
|
|
'',
|
|
'**Next steps:**',
|
|
'1. Open an issue describing what you want to change and why',
|
|
'2. Keep it concise and write in your own voice',
|
|
'3. If a maintainer approves with `/approve`, you will be added to the approved contributors list',
|
|
'4. Then you can submit your PR',
|
|
'',
|
|
`This PR will be closed automatically. See https://github.com/${context.repo.owner}/${context.repo.repo}/blob/${defaultBranch}/CONTRIBUTING.md for more details.`,
|
|
].join('\n');
|
|
|
|
await closePullRequest(message);
|