Skip to content

Commit 6cba503

Browse files
committed
feat: add tests
1 parent 8b7e09d commit 6cba503

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: PR Automated Comments Test
2+
3+
on:
4+
# Automatic triggers
5+
pull_request_target:
6+
types: [opened, ready_for_review, closed]
7+
8+
# Manual trigger for testing
9+
workflow_dispatch:
10+
inputs:
11+
test_event_type:
12+
description: 'Event type to simulate for testing'
13+
required: true
14+
type: choice
15+
options:
16+
- opened
17+
- ready_for_review
18+
- merged
19+
20+
jobs:
21+
# When manually triggered, we need to simulate the PR event context
22+
prepare-test-context:
23+
name: Prepare Test Context
24+
if: github.event_name == 'workflow_dispatch'
25+
runs-on: ubuntu-latest
26+
outputs:
27+
is_external: 'true'
28+
is_first_pr: ${{ steps.set-context.outputs.is_first_pr }}
29+
event_type: ${{ steps.set-context.outputs.event_type }}
30+
steps:
31+
- name: Set test context variables
32+
id: set-context
33+
run: |
34+
EVENT_TYPE="${{ github.event.inputs.test_event_type }}"
35+
echo "event_type=$EVENT_TYPE" >> $GITHUB_OUTPUT
36+
37+
# For the opened event, we need to simulate first PR status
38+
if [[ "$EVENT_TYPE" == "opened" ]]; then
39+
echo "is_first_pr=true" >> $GITHUB_OUTPUT
40+
else
41+
echo "is_first_pr=false" >> $GITHUB_OUTPUT
42+
fi
43+
44+
# Real workflow for actual PR events
45+
pr-comments-real:
46+
name: PR Comments (Real)
47+
if: github.event_name == 'pull_request_target'
48+
uses: ./.github/workflows/pr-auto-comments.yml@${{ github.ref_name }}
49+
with:
50+
org_name: "RequestNetwork"
51+
# You can specify additional internal users here if needed
52+
additional_internal_users: ""
53+
# Use default messages
54+
secrets:
55+
token: ${{ secrets.GITHUB_TOKEN }}
56+
57+
# Test workflow for manual triggering - using the actual reusable workflow
58+
first-pr-comment-test:
59+
name: First PR Comment (Test)
60+
needs: prepare-test-context
61+
if: github.event_name == 'workflow_dispatch' && needs.prepare-test-context.outputs.event_type == 'opened'
62+
uses: ./.github/workflows/pr-auto-comments.yml@${{ github.ref_name }}
63+
with:
64+
org_name: "RequestNetwork"
65+
first_pr_comment: "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! (TEST)"
66+
ready_for_review_comment: ""
67+
merged_pr_comment: ""
68+
secrets:
69+
token: ${{ secrets.GITHUB_TOKEN }}
70+
71+
ready-for-review-comment-test:
72+
name: Ready for Review Comment (Test)
73+
needs: prepare-test-context
74+
if: github.event_name == 'workflow_dispatch' && needs.prepare-test-context.outputs.event_type == 'ready_for_review'
75+
uses: ./.github/workflows/pr-auto-comments.yml@${{ github.ref_name }}
76+
with:
77+
org_name: "RequestNetwork"
78+
first_pr_comment: ""
79+
ready_for_review_comment: "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! (TEST)"
80+
merged_pr_comment: ""
81+
secrets:
82+
token: ${{ secrets.GITHUB_TOKEN }}
83+
84+
merged-pr-comment-test:
85+
name: Merged PR Comment (Test)
86+
needs: prepare-test-context
87+
if: github.event_name == 'workflow_dispatch' && needs.prepare-test-context.outputs.event_type == 'merged'
88+
uses: ./.github/workflows/pr-auto-comments.yml@${{ github.ref_name }}
89+
with:
90+
org_name: "RequestNetwork"
91+
first_pr_comment: ""
92+
ready_for_review_comment: ""
93+
merged_pr_comment: "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. (TEST)"
94+
secrets:
95+
token: ${{ secrets.GITHUB_TOKEN }}
96+
97+
# Add completion notification
98+
notify-test-completion:
99+
name: Notify Test Completion
100+
needs: [prepare-test-context]
101+
if: github.event_name == 'workflow_dispatch'
102+
runs-on: ubuntu-latest
103+
steps:
104+
- name: Create notification issue comment
105+
uses: actions/github-script@v6
106+
with:
107+
github-token: ${{ secrets.GITHUB_TOKEN }}
108+
script: |
109+
const eventType = '${{ needs.prepare-test-context.outputs.event_type }}';
110+
const repoName = context.repo.repo;
111+
const orgName = context.repo.owner;
112+
113+
const issue_number = context.issue.number || 1;
114+
115+
await github.rest.issues.createComment({
116+
owner: context.repo.owner,
117+
repo: context.repo.repo,
118+
issue_number: issue_number,
119+
body: `## Test for "${eventType}" PR Event Initiated
120+
121+
A test of the \`${eventType}\` PR event comment has been initiated.
122+
123+
**Note:** Since this is a manual test, this will use hard-coded test variables:
124+
- Repository: ${repoName}
125+
- Organization: ${orgName}
126+
- Testing as an external contributor
127+
128+
Check the [Actions tab](https://github.com/${orgName}/${repoName}/actions/workflows/repo-pr-comments.yml) to see the workflow execution.
129+
130+
*This is a notification from the manual test trigger.*`
131+
});

0 commit comments

Comments
 (0)