-
Notifications
You must be signed in to change notification settings - Fork 28
fix : added validation in add image form. #1184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
All contributors have signed the CLA ✍️ ✅ |
WalkthroughAdds YAML validation metadata to an issue template and introduces a GitHub Actions workflow that parses issue fields, validates a provided token address format and optionally queries chain RPC getCode, then comments and labels issues on failure. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User as User
participant GH as GitHub Issues
participant GA as GitHub Actions
participant Script as Validation Script
participant RPC as Chain RPC (ethers JsonRpcProvider)
participant API as GitHub API
User->>GH: Open/Edit issue with label "addImage"
GH-->>GA: Trigger "Validate Token Address"
GA->>Script: Checkout, setup Node, install ethers, run script
Script->>GH: Read issue body (Network, Address)
Script->>Script: Check Address present and matches ^0x[a-fA-F0-9]{40}$
alt Missing or invalid format
Script-->>GA: Fail validation
else RPC mapping exists for Network
Script->>RPC: provider.getCode(Address)
alt getCode == "0x" or provider error indicating invalid
Script-->>GA: Fail (not a contract / invalid)
else Code present
Script-->>GA: Success
end
else No RPC mapping
Script-->>GA: Skip on-chain check (treat as pass)
end
opt On failure
GA->>API: Post comment with error details
GA->>API: Add "invalid-address" label
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
I have read the CLA Document and I hereby sign the CLA |
closes #109 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (7)
.github/ISSUE_TEMPLATE/2-addImageForm.yml (2)
43-43
: Broaden address regex to accept 0X prefix (optional)Some users paste addresses with 0X. Consider allowing both 0x/0X; checksum enforcement can remain out-of-band.
- pattern: "^0x[a-fA-F0-9]{40}$" + pattern: "^0[xX][a-fA-F0-9]{40}$"
53-53
: Relax URL regex; current pattern rejects valid URLs with query/fragment and allows underscores in hostSimplify to accept any http(s) URL without spaces; reduces false negatives and avoids host underscore ambiguity.
- pattern: "^(https?://[\\w.-]+(?:/[\\w\\-.~!$&'()*+,;=:@%]*)*)$" + pattern: "^https?://\\S+$".github/workflows/validate-token-address.yml (5)
20-22
: Avoid modifying repo deps; pin ethers and don’t savePrevent npm from touching package.json/lockfile and pin a known-major.
- - name: Install ethers.js - run: npm install ethers + - name: Install ethers.js + run: npm install --no-save ethers@6
23-40
: Harden extraction and sanitize outputs
- Make matching more specific to form headers to avoid accidental captures.
- Constrain network to the allowed set before exporting.
- name: Extract address and network id: extract uses: actions/github-script@v7 with: script: | const body = context.payload.issue.body; - // Extract Network - const networkMatch = body.match(/Network\s*\n\s*(.*)/); + // Extract Network (expects "### Network" section in issue form) + const networkMatch = body.match(/#+\s*Network\s*\n\s*([A-Z0-9_]+)/); const network = networkMatch ? networkMatch[1].trim() : null; - // Extract Address - const addressMatch = body.match(/Address\s*\n\s*(0x[a-fA-F0-9]{40})/); + // Extract Address (expects "### Address" section) + const addressMatch = body.match(/#+\s*Address\s*\n\s*(0x[a-fA-F0-9]{40})/); const address = addressMatch ? addressMatch[1].trim() : null; - core.setOutput('network', network || ''); + const allowed = new Set(['MAINNET','GNOSIS_CHAIN','ARBITRUM_ONE','BASE','POLYGON','AVALANCHE','BNB','LENS']); + core.setOutput('network', (network && allowed.has(network)) ? network : ''); core.setOutput('address', address || '');
55-64
: RPC map OK; consider fallbacks (optional)Public RPCs can rate-limit. Optional: add multiple URLs per network or a fallback map.
72-85
: Add explicit timeout and non-zero exit on provider hangYou added a step timeout above; that’s good to avoid hanging runs. Consider retry/backoff if RPC is flaky. Optional.
87-110
: Fix step condition syntax and de-duplicate labels/comments
- Use expression syntax for if.
- Optionally remove the invalid-address label when a subsequent edit passes validation.
- - name: Add comment and label if invalid - if: failure() + - name: Add comment and label if invalid + if: ${{ failure() }} uses: actions/github-script@v7 with: script: | const issue_number = context.issue.number; const address = '${{ steps.extract.outputs.address }}'; const network = '${{ steps.extract.outputs.network }}'; // Add comment await github.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number, body: `⚠️ The address \`${address || 'N/A'}\` does not exist or is invalid on network \`${network || 'N/A'}\`. Please verify.` }); // Add label - await github.issues.addLabels({ + await github.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, issue_number, labels: ['invalid-address'] });To remove the label on success, add the following step after validation:
- name: Remove invalid-address label on success if: ${{ success() }} uses: actions/github-script@v7 with: script: | const labels = (await github.issues.listLabelsOnIssue({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number })).data.map(l => l.name); if (labels.includes('invalid-address')) { await github.issues.removeLabel({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, name: 'invalid-address' }); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.github/ISSUE_TEMPLATE/2-addImageForm.yml
(1 hunks).github/workflows/validate-token-address.yml
(1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.8)
.github/workflows/validate-token-address.yml
13-13: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
16-16: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🔇 Additional comments (2)
.github/ISSUE_TEMPLATE/2-addImageForm.yml (2)
39-39
: Address description LGTMClear and helpful guidance for contributors.
49-50
: Image field copy/placeholder LGTMGood UX; sets expectation without blocking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution!
Please make sure to acknowledge/fix if appropriate comments by CodeRabbit as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
.yarn/install-state.gz
is excluded by!**/.yarn/**
,!**/*.gz
yarn.lock
is excluded by!**/yarn.lock
,!**/*.lock
📒 Files selected for processing (3)
.github/workflows/validate-token-address.yml
(1 hunks).yarnrc.yml
(1 hunks)package.json
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- .yarnrc.yml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
.github/workflows/validate-token-address.yml (1)
36-41
: Consider making extraction more robust.The regex patterns assume a specific issue body format. If the issue template changes or users edit the structure, extraction may fail silently.
Consider:
- Adding validation that both fields were extracted successfully
- Logging extracted values for debugging
- Using more forgiving regex patterns or structured parsing
Example improvement:
const addressMatch = body.match(/Address\s*\n\s*(0x[a-fA-F0-9]{40})/); const address = addressMatch ? addressMatch[1].trim() : null; + console.log('Extracted network:', network); + console.log('Extracted address:', address); + core.setOutput('network', network || ''); core.setOutput('address', address || '');
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.github/workflows/validate-token-address.yml
(1 hunks)
🔇 Additional comments (1)
.github/workflows/validate-token-address.yml (1)
112-135
: LGTM!The failure handling correctly uses the
failure()
condition, provides helpful feedback to users, and adds an appropriate label for triage.
@alfetopito @shoom3301 hey I have resolved all the coderabbit comments as well. |
This PR adds a GitHub Action that automatically checks token addresses submitted via the “Add Image” issue form.
What it does:
If invalid or missing:
Posts a comment to let the contributor know.
Adds an invalid-address label.
Summary by CodeRabbit
New Features
Documentation