mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
refactor: no commits on GitHub
This commit is contained in:
@@ -14,46 +14,54 @@ jobs:
|
|||||||
has-web-commits:
|
has-web-commits:
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
|
- name: Check if PR author is allow-listed
|
||||||
|
id: pr_author
|
||||||
|
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
script: |
|
||||||
|
const prAuthor = context.payload.pull_request.user.login;
|
||||||
|
let isAllowListed = false;
|
||||||
|
|
||||||
|
if (prAuthor === 'renovate[bot]') {
|
||||||
|
isAllowListed = true;
|
||||||
|
} else {
|
||||||
|
const teams = ['ops', 'bots', 'staff', 'dev-team', 'moderators'];
|
||||||
|
for (const team of teams) {
|
||||||
|
const response = await github.rest.teams.getMembershipForUserInOrg({
|
||||||
|
org: context.repo.owner,
|
||||||
|
team_slug: team,
|
||||||
|
username: prAuthor
|
||||||
|
});
|
||||||
|
if (response.status == 200) {
|
||||||
|
isAllowListed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
core.setOutput('is_allow_listed', isAllowListed);
|
||||||
|
|
||||||
- name: Check if commits are made on GitHub Web UI
|
- name: Check if commits are made on GitHub Web UI
|
||||||
id: check-commits
|
id: check-commits
|
||||||
|
if: steps.pr_author.outputs.result.is_allow_listed == 'false'
|
||||||
run: |
|
run: |
|
||||||
PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
|
PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
|
||||||
COMMITS_URL="https://api.github.com/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/commits"
|
COMMITS_URL="https://api.github.com/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/commits"
|
||||||
|
IS_GITHUB_COMMIT=$(curl --header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "$COMMITS_URL" | jq '[.[] | .commit.committer.name] | any(.[]; . == "GitHub")')
|
||||||
IS_GITHUB_COMMIT=$(curl --header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "$COMMITS_URL" | jq '[.[] | select(.commit.committer.name == "GitHub" and (.commit.author.name == "renovate[bot]" or .commit.author.name == "camperbot"))] | any')
|
|
||||||
|
|
||||||
if [ "$IS_GITHUB_COMMIT" = "true" ]; then
|
if [ "$IS_GITHUB_COMMIT" = "true" ]; then
|
||||||
# Set variable for next task
|
|
||||||
echo "IS_GITHUB_COMMIT=true" >> $GITHUB_ENV
|
echo "IS_GITHUB_COMMIT=true" >> $GITHUB_ENV
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Add comment on PR if commits are made on GitHub Web UI
|
- name: Add comment on PR if commits are made on GitHub Web UI
|
||||||
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6
|
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6
|
||||||
if: env.IS_GITHUB_COMMIT == 'true'
|
if: steps.pr_author.outputs.result.is_allow_listed == 'false' && env.IS_GITHUB_COMMIT == 'true'
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
const isDev = await github.rest.teams.getMembershipForUserInOrg({
|
core.setFailed("Commits were added via the GitHub Web UI.");
|
||||||
org: "freeCodeCamp",
|
github.rest.issues.createComment({
|
||||||
team_slug: "dev-team",
|
issue_number: context.issue.number,
|
||||||
username: context.payload.pull_request.user.login
|
owner: context.repo.owner,
|
||||||
}).catch(() => ({status: 404}));
|
repo: context.repo.repo,
|
||||||
const isMod = await github.rest.teams.getMembershipForUserInOrg({
|
body: "Thanks for your pull request.\n\n**Please do not add commits via the GitHub Web UI.**\n\nIt generally means you have yet to test these changes in a development setup or complete any prerequisites. We need you to follow the guides mentioned in the checklist. Please revalidate these changes in a developer environment and confirm how you validated your changes.\n\nHappy contributing!\n\n---\n_**Note:** This message was automatically generated by a bot. If you feel this message is in error or would like help resolving it, feel free to reach us [in our contributor chat](https://discord.gg/PRyKn3Vbay)._"
|
||||||
org: "freeCodeCamp",
|
});
|
||||||
team_slug: "moderators",
|
|
||||||
username: context.payload.pull_request.user.login
|
|
||||||
}).catch(() => ({status: 404}));
|
|
||||||
if (
|
|
||||||
isDev.status !== 200 &&
|
|
||||||
isMod.status !== 200
|
|
||||||
) {
|
|
||||||
core.setFailed("Please do not add commits via the GitHub Web UI.");
|
|
||||||
github.rest.issues.createComment({
|
|
||||||
issue_number: context.issue.number,
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
body: "Thanks for your pull request.\n\n**Please do not add commits via the GitHub Web UI.**\n\nIt generally means you have yet to test these changes in a development setup or complete any prerequisites. We need you to follow the guides mentioned in the checklist. Please revalidate these changes in a developer environment and confirm how you validated your changes.\n\nHappy contributing!\n\n---\n_**Note:** This message was automatically generated by a bot. If you feel this message is in error or would like help resolving it, feel free to reach us [in our contributor chat](https://discord.gg/PRyKn3Vbay)._"
|
|
||||||
});
|
|
||||||
} else if (isDev.status === 200 || isMod.status === 200) {
|
|
||||||
core.notice('This PR adds commits made on GitHub Web UI by a member of staff or mod.');
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user