Skip to content

πŸ” Searching for a Discord Webhook URL within commit contents #3

πŸ” Searching for a Discord Webhook URL within commit contents

πŸ” Searching for a Discord Webhook URL within commit contents #3

name: πŸ‘€ Detect committed Discord Webhook
run-name: πŸ” Searching for a Discord Webhook URL within commit contents
on: [pull_request]
jobs:
detect-discord-webhooks:
runs-on: ubuntu-latest
steps:
- name: πŸ†• Check out repository code
uses: actions/checkout@v4
- name: πŸ” Search for a Discord Webhook URL
id: regex_search
run: |
set +e
git grep -P -q "(discord|discordapp).com\/api\/webhooks\/([\d]+)\/([a-zA-Z0-9_.-])*" $(git rev-list --all)
echo "exit_code=$?" >> $GITHUB_OUTPUT
- name: πŸ’¬ Place a comment on the PR and close
if: steps.regex_search.outputs.exit_code == 0
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '# πŸ”΄ WEBHOOK URL DETECTED\n\n### A Discord Webhook URL has been detected within your commit contents.\n\nPlease refer to the `README.md` and use the `.env` file for inputting a Webhook URL.\n\n*This PR will now be closed for your own safety, **please reset your Webhook URL** as other people could use it to send messages to the channel where the Webhook was created!*'
})
github.rest.pulls.update({
pull_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed'
})