Skip to content

Commit

Permalink
feat(actions): add a comment when web ui is used
Browse files Browse the repository at this point in the history
  • Loading branch information
raisedadead committed Nov 6, 2023
1 parent b02c292 commit e8f9f95
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions .github/workflows/dont-use-github.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
name: Do not use GitHub Web

name: GitHub - No Commits on GitHub Web
on:
pull_request:
types: [synchronize, opened, reopened]
pull_request_target:

jobs:
check-first-commit:
runs-on: ubuntu-latest
has-web-commits:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
with:
fetch-depth: 0

- name: Check for web UI first commit
- name: Check if commits are made on GitHub Web UI
id: check-commits
run: |
PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
COMMITS_URL="https://api.github.com/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/commits"
first_commit=$(curl --header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "$COMMITS_URL" | jq '.[0]')
web_ui_commit=$(echo "$first_commit" | jq 'select(.commit.message | test("Update"))')
IS_GITHUB_COMMIT=$(curl --header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "$COMMITS_URL" | jq '[.[] | .commit.committer.name] | any(.[]; . == "GitHub")')
if [ -n "$web_ui_commit" ]; then
echo "The first commit in the pull request was created via the GitHub web UI."
exit 1
if [ "$IS_GITHUB_COMMIT" = "true" ]; then
# Set a output for next task
echo "IS_GITHUB_COMMIT=true" >> $GITHUB_OUTPUT
fi
- name: Add comment on PR if commits are made on GitHub Web UI
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6
env:
IS_GITHUB_COMMIT: ${{ steps.check-commits.outputs.IS_GITHUB_COMMIT }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
core.setFailed('This PR adds commits made on 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 add commits via the GitHub Web UI. It generally means you have not tested these changes in a development setup or completed any pre-requisites.**\n\nWe require you to follow the guides mentioned in the checklist in the description. 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)._"
})

0 comments on commit e8f9f95

Please sign in to comment.