Skip to content

fix : added validation in add image form. #1184

Open
minato32 wants to merge 9 commits intocowprotocol:mainfrom
minato32:main
Open

fix : added validation in add image form. #1184
minato32 wants to merge 9 commits intocowprotocol:mainfrom
minato32:main

Conversation

@minato32
Copy link

@minato32 minato32 commented Oct 14, 2025

This PR adds a GitHub Action that automatically checks token addresses submitted via the “Add Image” issue form.

What it does:

  • added regex validation in github issue template file for address and image url
  • Runs when an issue is opened or edited.
  • Extracts the Network and Address from the form.
  • Checks if the address exists on the selected network.

If invalid or missing:
Posts a comment to let the contributor know.
Adds an invalid-address label.

Summary by CodeRabbit

  • New Features

    • Automatic token address validation for issues labeled "addImage", with clear feedback and labeling on failure.
  • Documentation

    • Enhanced issue form: strict 0x-prefixed address validation.
    • Added image URL guidance and placeholder.
    • Improved form clarity and formatting for new validation fields.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 14, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 14, 2025

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds YAML validation fields to an issue template and a new GitHub Actions workflow that extracts Network and Address from issue bodies, validates address format, optionally queries chain RPC getCode, and comments/labels issues on validation failure.

Changes

Cohort / File(s) Summary
Issue template validation
\.github/ISSUE_TEMPLATE/2-addImageForm.yml
Added descriptions, placeholders and regex patterns for address (^0x[a-fA-F0-9]{40}$) and imageUrl (^(https?://[\w.-]+(?:/[\w\-.~!$&'()*+,;=:@%]*)*)$); quoted strings and minor YAML formatting adjustments.
Issue-driven address validation workflow
\.github/workflows/validate-token-address.yml
New workflow triggered on issues with label addImage (opened/edited). Checks out repo, sets up Node 20, installs ethers, extracts Network and Address, validates presence/format, optionally maps network→RPC and calls provider.getCode, fails on missing/invalid address or empty code, and posts a comment plus invalid-address label on failure.

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 (JsonRpcProvider)
    participant API as GitHub API

    User->>GH: Open/Edit issue labeled "addImage"
    GH-->>GA: Trigger workflow

    GA->>Script: Checkout, setup Node, install ethers, run validation
    Script->>GH: Read issue body (Network, Address)
    Script->>Script: Check Address presence and ^0x[a-fA-F0-9]{40}$

    alt Missing or invalid format
        Script-->>GA: Fail validation
    else RPC mapping exists
        Script->>RPC: provider.getCode(Address)
        alt getCode == "0x" or provider error indicating invalid
            Script-->>GA: Fail validation
        else Code present
            Script-->>GA: Pass
        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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

I hop through YAML with whiskers bright,
Regex carrots gleam in candlelight.
A workflow checks each token's thread,
If bytecode's thin, I stamp it red.
I nibble bugs and bound with delight. 🐇

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: adding validation to the add image form through both regex patterns in the template and an automated GitHub Actions workflow.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

Migrating from UI to YAML configuration.

Use the @coderabbitai configuration command in a PR comment to get a dump of all your UI settings in YAML format. You can then edit this YAML file and upload it to the root of your repository to configure CodeRabbit programmatically.

@minato32
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

@minato32
Copy link
Author

closes #109

github-actions bot added a commit that referenced this pull request Oct 14, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 host

Simplify 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 save

Prevent 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 hang

You 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1603e3d and 8cecc3e.

📒 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 LGTM

Clear and helpful guidance for contributors.


49-50: Image field copy/placeholder LGTM

Good UX; sets expectation without blocking.

Copy link
Collaborator

@alfetopito alfetopito left a 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 696f6c2 and 008744c.

📒 Files selected for processing (1)
  • .github/workflows/validate-token-address.yml (1 hunks)

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 008744c and 39b0753.

⛔ 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

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 39b0753 and 6b67e84.

📒 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.

@minato32
Copy link
Author

appropriate comments by CodeRabbit as well.

@alfetopito @shoom3301 hey I have resolved all the coderabbit comments as well.

Copy link
Collaborator

@alfetopito alfetopito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for the contribution, and sorry for taking so long to review it.
Do you mind updating the PR so we can accept the change?

Added LINEA and PLASMA chain to rpc map as asked as well
@minato32
Copy link
Author

@alfetopito hey i have updated the PR. apologies for taking this long

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants