Last active
July 17, 2023 17:19
-
-
Save adamcrews/c340b2a3f59cdee4357a8a3b8964d623 to your computer and use it in GitHub Desktop.
github reject non-corp email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .github/workflows/check_email.yml | |
jobs: | |
validate_email: | |
name: Validate email | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Extract author email | |
id: author | |
run: | | |
git log -2 | |
echo "::set-output name=EMAIL::$(git show -s --format='%ae' HEAD~0)" | |
# TODO: Fail the workflow in future instead of adding comment | |
- name: Validate author email | |
if: ${{ !endsWith(steps.author.outputs.EMAIL, '@mycompany.com') }} | |
uses: actions/github-script@v6 | |
env: | |
EMAIL: ${{ steps.author.outputs.EMAIL }} | |
with: | |
script: | | |
const { EMAIL } = process.env | |
await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `⚠️ We detect that you are using a non-corporate email \`${EMAIL}\` address to contribute to the repo. :( | |
Please update your repo config \`.git/config\`: | |
\`\`\` | |
[user] | |
name = Your Name | |
email = [email protected] | |
\`\`\` | |
> You may see \`<id>+<name>@users.noreply.github.com\` email, then you need to turn off [Keep my email addresses private](https://github.com/settings/emails) setting in your account. | |
`}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment