mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2026-03-27 13:50:22 -06:00
github: Add first time contributor verification (#1663)
This commit is contained in:
parent
d48d51828e
commit
a4c3135bf3
13
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
13
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
---
|
||||
<!--
|
||||
If you are contributing to Azahar for the first time please
|
||||
keep the block of text between `---` and write your
|
||||
PR description below it. Do not write anything inside
|
||||
or change this block of text!
|
||||
|
||||
If you are a recurrent contributor, remove this entire
|
||||
block of text and proceed as normal.
|
||||
-->
|
||||
|
||||

|
||||
---
|
||||
BIN
.github/ignore_unless_human.png
vendored
Normal file
BIN
.github/ignore_unless_human.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
51
.github/workflows/first_time_contributor_detect.yml
vendored
Normal file
51
.github/workflows/first_time_contributor_detect.yml
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
name: Detect first-time contributors
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [opened]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
issues: write
|
||||
|
||||
jobs:
|
||||
detect:
|
||||
runs-on: ubuntu-latest
|
||||
if: >-
|
||||
(github.repository == 'azahar-emu/azahar') &&
|
||||
(github.event.pull_request.author_association != 'COLLABORATOR') &&
|
||||
(github.event.pull_request.author_association != 'CONTRIBUTOR') &&
|
||||
(github.event.pull_request.author_association != 'MANNEQUIN') &&
|
||||
(github.event.pull_request.author_association != 'MEMBER') &&
|
||||
(github.event.pull_request.author_association != 'OWNER')
|
||||
steps:
|
||||
- name: Detect PR if author is first-time contributor
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const { owner, repo } = context.repo;
|
||||
const pr = context.payload.pull_request;
|
||||
|
||||
// Add needs verification label so that the reopen action runs on comment.
|
||||
await github.rest.issues.addLabels({
|
||||
owner,
|
||||
repo,
|
||||
issue_number: pr.number,
|
||||
labels: ['needs verification'],
|
||||
});
|
||||
|
||||
// Close the pull request and wait for verification.
|
||||
await github.rest.pulls.update({
|
||||
owner,
|
||||
repo,
|
||||
pull_number: pr.number,
|
||||
state: 'closed',
|
||||
});
|
||||
|
||||
// Show the new contributor how to verify (they need to write a short poem about the Wii and 3DS being lovers)
|
||||
await github.rest.issues.createComment({
|
||||
owner,
|
||||
repo,
|
||||
issue_number: pr.number,
|
||||
body: 'Welcome to the Azahar Emulator repository! Due to the surge of AI bots we have decided to add an extra verification step to new contributors. Please follow the exact instructions in your own written Pull Request description to reopen it.',
|
||||
});
|
||||
79
.github/workflows/first_time_contributor_reopen.yml
vendored
Normal file
79
.github/workflows/first_time_contributor_reopen.yml
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
name: Verify first-time contributors
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
issues: write
|
||||
|
||||
jobs:
|
||||
verify:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event.issue.pull_request && contains(github.event.issue.labels.*.name, 'needs verification')
|
||||
steps:
|
||||
- name: Verify and reopen PR
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const { owner, repo } = context.repo;
|
||||
const issue = context.payload.issue;
|
||||
const comment = context.payload.comment;
|
||||
const { data: pr } = await github.rest.pulls.get({
|
||||
owner,
|
||||
repo,
|
||||
pull_number: issue.number,
|
||||
});
|
||||
|
||||
// Only allow verification of the comment user is the author
|
||||
if (comment.user.login !== pr.user.login) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch user display and login names (lowercase)
|
||||
const { data: user } = await github.rest.users.getByUsername({
|
||||
username: pr.user.login,
|
||||
});
|
||||
const username = pr.user.login.toLowerCase();
|
||||
const displayName = (user.name || '').toLowerCase();
|
||||
|
||||
// Make comment body lowercase and split words
|
||||
const body = comment.body.toLowerCase().trim().split(/\s+/);
|
||||
|
||||
// Check that the user verified themselves by writing a song about the NES and the SNES.
|
||||
const verified =
|
||||
(body.includes(username) ||
|
||||
(displayName && body.includes(displayName))) &&
|
||||
body.includes('azahar');
|
||||
|
||||
// Only reopen the PR and remove the label if verification succeeded
|
||||
if (verified) {
|
||||
await github.rest.pulls.update({
|
||||
owner,
|
||||
repo,
|
||||
pull_number: issue.number,
|
||||
state: 'open',
|
||||
});
|
||||
await github.rest.issues.createComment({
|
||||
owner,
|
||||
repo,
|
||||
issue_number: issue.number,
|
||||
body: 'Verification successful! Pull request has been reopened. Please also edit your PR description to remove the block of text between `---` to make the description easier to read.',
|
||||
});
|
||||
try {
|
||||
await github.rest.issues.removeLabel({
|
||||
owner,
|
||||
repo,
|
||||
issue_number: issue.number,
|
||||
name: 'needs verification',
|
||||
});
|
||||
} catch {}
|
||||
} else {
|
||||
await github.rest.issues.createComment({
|
||||
owner,
|
||||
repo,
|
||||
issue_number: issue.number,
|
||||
body: 'Verification failed! Pull request will remain closed.',
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user