Skip to content

fix: remove unit tests (#3) #9

fix: remove unit tests (#3)

fix: remove unit tests (#3) #9

name: PR Automated Comments
on:
workflow_call:
inputs:
org_name:
description: 'GitHub organization name to identify internal team members'
required: true
type: string
additional_internal_users:
description: 'Additional comma-separated list of usernames to consider as internal'
required: false
type: string
default: ''
first_pr_comment:
description: 'Message for first PR comments (leave empty to disable first PR comments)'
required: false
type: string
default: 'Hello @{{username}}, thank you for submitting your first pull request to the {{repository}} repository. We value your contribution and encourage you to review our contribution guidelines to ensure your submission meets our standards. Please note that every merged PR is automatically enrolled in our Best PR Initiative, offering a chance to win $500 each quarter. Our team is available via GitHub Discussions or Discord if you have any questions. Welcome aboard!'
ready_for_review_comment:
description: 'Message for PR ready for review comments (leave empty to disable ready for review comments)'
required: false
type: string
default: 'Thank you for your submission! As you prepare for the review process, please ensure that your PR title, description, and any linked issues fully comply with our contribution guidelines. A clear explanation of your changes and their context will help expedite the review process. Every merged PR is automatically entered into our Best PR Initiative, offering a chance to win $500 every quarter. We appreciate your attention to detail and look forward to reviewing your contribution!'
merged_pr_comment:

Check failure on line 25 in .github/workflows/pr-auto-comments.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/pr-auto-comments.yml

Invalid workflow file

You have an error in your yaml syntax on line 25
description: 'Message for merged PR comments (leave empty to disable merged PR comments)'
required: false
type: string
default: 'Congratulations, your pull request has been merged! Thank you for your valuable contribution to Request Network. As a reminder, every merged PR is automatically entered into our Best PR Initiative, offering a quarterly prize of $500. Your work significantly supports our project\'s growth, and we encourage you to continue engaging with our community. Additionally, if you want to build or add crypto payments and invoicing features, explore how our API can reduce deployment time from months to hours while offering advanced features. Book a call with our expert to learn more and fast-track your development.'
secrets:
token:
description: 'GitHub token with org:read permission'
required: false
jobs:
# Central job to check if contributor is external and determine PR status
check-contributor:
name: Check Contributor Status
runs-on: ubuntu-latest
outputs:
is_external: ${{ steps.check.outputs.is_external }}
is_first_pr: ${{ steps.check.outputs.is_first_pr }}
event_type: ${{ steps.event.outputs.type }}
steps:
- name: Determine event type
id: event
run: |
if [[ "${{ github.event_name }}" == "pull_request_target" ]]; then
if [[ "${{ github.event.action }}" == "opened" ]]; then
echo "type=opened" >> $GITHUB_OUTPUT
elif [[ "${{ github.event.action }}" == "ready_for_review" ]]; then
echo "type=ready_for_review" >> $GITHUB_OUTPUT
elif [[ "${{ github.event.action }}" == "closed" && "${{ github.event.pull_request.merged }}" == "true" ]]; then
echo "type=merged" >> $GITHUB_OUTPUT
else
echo "type=other" >> $GITHUB_OUTPUT
fi
else
echo "type=other" >> $GITHUB_OUTPUT
fi
- name: Check if external contributor
id: check
run: |
# Get the PR author
PR_AUTHOR="${{ github.event.pull_request.user.login }}"
ORG_NAME="${{ inputs.org_name }}"
ADDITIONAL_USERS="${{ inputs.additional_internal_users }}"
# First check if user is in the additional internal users list
if [[ "$ADDITIONAL_USERS" == *"$PR_AUTHOR"* ]]; then
echo "User is in additional internal users list, skipping comment"
echo "is_external=false" >> $GITHUB_OUTPUT
echo "is_first_pr=false" >> $GITHUB_OUTPUT
exit 0
fi
# Check if user is an org member
echo "Checking if user is a member of organization $ORG_NAME"
ORG_MEMBER=$(gh api -H "Accept: application/vnd.github+json" \
"/orgs/$ORG_NAME/members/$PR_AUTHOR" --silent || echo "not_found")
if [[ "$ORG_MEMBER" != "not_found" ]]; then
echo "User is an organization member, skipping comment"
echo "is_external=false" >> $GITHUB_OUTPUT
echo "is_first_pr=false" >> $GITHUB_OUTPUT
exit 0
fi
# User is external
echo "is_external=true" >> $GITHUB_OUTPUT
# Only check if this is their first PR if needed
if [[ "${{ steps.event.outputs.type }}" == "opened" ]]; then
# Check if this is their first PR to the repo
PR_COUNT=$(gh api graphql -f query='
query($owner:String!, $repo:String!, $author:String!) {
repository(owner:$owner, name:$repo) {
pullRequests(first:100, states:[OPEN, CLOSED, MERGED], author:$author) {
totalCount
}
}
}' -f owner=${{ github.repository_owner }} -f repo=${{ github.event.repository.name }} -f author=$PR_AUTHOR | jq '.data.repository.pullRequests.totalCount')
if [ "$PR_COUNT" -eq 1 ]; then
echo "First PR from this contributor"
echo "is_first_pr=true" >> $GITHUB_OUTPUT
else
echo "Not the first PR from this contributor"
echo "is_first_pr=false" >> $GITHUB_OUTPUT
fi
else
echo "is_first_pr=false" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ secrets.token || github.token }}
# Leave a comment on first PRs
first-pr-comment:
name: First PR Comment
needs: check-contributor
if: needs.check-contributor.outputs.event_type == 'opened' && needs.check-contributor.outputs.is_external == 'true' && needs.check-contributor.outputs.is_first_pr == 'true' && inputs.first_pr_comment != ''
runs-on: ubuntu-latest
steps:
- name: Leave first PR comment
uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
script: |
const variables = {
username: context.payload.pull_request.user.login,
repository: context.payload.repository.name,
org: context.repo.owner,
};
let commentBody = `${{ inputs.first_pr_comment }}`;
Object.entries(variables).forEach(([key, value]) => {
const regex = new RegExp(`\\{\\{${key}\\}\\}`, 'g');
commentBody = commentBody.replace(regex, value);
});
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
# Leave a comment when PR is marked ready for review
ready-for-review-comment:
name: Ready for Review Comment
needs: check-contributor
if: needs.check-contributor.outputs.event_type == 'ready_for_review' && needs.check-contributor.outputs.is_external == 'true' && inputs.ready_for_review_comment != ''
runs-on: ubuntu-latest
steps:
- name: Leave ready for review comment
uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
script: |
const variables = {
username: context.payload.pull_request.user.login,
repository: context.payload.repository.name,
org: context.repo.owner,
};
let commentBody = `${{ inputs.ready_for_review_comment }}`;
Object.entries(variables).forEach(([key, value]) => {
const regex = new RegExp(`\\{\\{${key}\\}\\}`, 'g');
commentBody = commentBody.replace(regex, value);
});
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
# Leave a comment when PR is merged
merged-pr-comment:
name: Merged PR Comment
needs: check-contributor
if: needs.check-contributor.outputs.event_type == 'merged' && needs.check-contributor.outputs.is_external == 'true' && inputs.merged_pr_comment != ''
runs-on: ubuntu-latest
steps:
- name: Leave merged PR comment
uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
script: |
const variables = {
username: context.payload.pull_request.user.login,
repository: context.payload.repository.name,
org: context.repo.owner,
};
let commentBody = `${{ inputs.merged_pr_comment }}`;
Object.entries(variables).forEach(([key, value]) => {
const regex = new RegExp(`\\{\\{${key}\\}\\}`, 'g');
commentBody = commentBody.replace(regex, value);
});
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});