JS-1423 Fix S7778 false positives for custom class methods with single argument #683
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
| name: Label ESLint Plugin PRs | |
| on: | |
| pull_request: | |
| types: ["opened", "synchronize", "edited"] | |
| paths: | |
| - 'packages/jsts/src/rules/**' | |
| jobs: | |
| add_eslint_plugin_label: | |
| name: Add eslint-plugin label to Jira | |
| runs-on: github-ubuntu-latest-s | |
| permissions: | |
| id-token: write | |
| pull-requests: read | |
| contents: read | |
| # Only run for internal PRs (not forks) | |
| if: github.event.pull_request.head.repo.full_name == github.repository | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 # Fetch full history to access base branch | |
| - name: Check if changes are only in external/decorated rules | |
| id: check-rules | |
| run: | | |
| # Get list of changed rule directories | |
| CHANGED_RULES=$(gh pr diff ${{ github.event.pull_request.number }} --name-only | \ | |
| grep -oE 'packages/jsts/src/rules/S[0-9]+' | sort -u || echo "") | |
| if [ -z "$CHANGED_RULES" ]; then | |
| echo "No rule directories changed" | |
| echo "should_label=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| echo "Changed rule directories:" | |
| echo "$CHANGED_RULES" | |
| # Check if any changed rule is NOT external or decorated | |
| # We check both HEAD and base branch to handle: | |
| # - Deleted rules (check base) | |
| # - Rules converted from original to external/decorated (check base) | |
| # - New original rules (check HEAD) | |
| SHOULD_LABEL="false" | |
| BASE_REF="${{ github.event.pull_request.base.ref }}" | |
| for RULE_DIR in $CHANGED_RULES; do | |
| META_FILE="$RULE_DIR/meta.ts" | |
| # Get implementation from HEAD (current PR state) | |
| if [ -f "$META_FILE" ]; then | |
| IMPL_HEAD=$(grep -oP "implementation\s*=\s*['\"]\\K[^'\"]*" "$META_FILE" || echo "original") | |
| else | |
| IMPL_HEAD="" | |
| fi | |
| # Get implementation from base branch (before PR changes) | |
| IMPL_BASE=$(git show "origin/$BASE_REF:$META_FILE" 2>/dev/null | grep -oP "implementation\s*=\s*['\"]\\K[^'\"]*" || echo "original") | |
| echo "Rule $RULE_DIR - HEAD: '${IMPL_HEAD:-deleted}', BASE: '$IMPL_BASE'" | |
| # Label if EITHER HEAD or BASE has original implementation | |
| if [ -n "$IMPL_HEAD" ] && [ "$IMPL_HEAD" != "external" ] && [ "$IMPL_HEAD" != "decorated" ]; then | |
| SHOULD_LABEL="true" | |
| echo "Found original rule implementation in HEAD for $RULE_DIR" | |
| elif [ "$IMPL_BASE" != "external" ] && [ "$IMPL_BASE" != "decorated" ]; then | |
| SHOULD_LABEL="true" | |
| echo "Found original rule implementation in BASE for $RULE_DIR" | |
| fi | |
| done | |
| echo "should_label=$SHOULD_LABEL" >> $GITHUB_OUTPUT | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| - name: Extract Jira key from PR title | |
| id: extract-jira-key | |
| if: steps.check-rules.outputs.should_label == 'true' | |
| env: | |
| PR_TITLE: ${{ github.event.pull_request.title }} | |
| run: | | |
| # Extract Jira key (e.g., JS-1234) from the beginning of the title | |
| JIRA_KEY=$(echo "$PR_TITLE" | grep -oE '^[A-Z]+-[0-9]+' || echo "") | |
| if [ -z "$JIRA_KEY" ]; then | |
| echo "No Jira key found in PR title: $PR_TITLE" | |
| echo "has_jira_key=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "Found Jira key: $JIRA_KEY" | |
| echo "jira_key=$JIRA_KEY" >> $GITHUB_OUTPUT | |
| echo "has_jira_key=true" >> $GITHUB_OUTPUT | |
| fi | |
| - id: secrets | |
| if: steps.check-rules.outputs.should_label == 'true' && steps.extract-jira-key.outputs.has_jira_key == 'true' | |
| uses: SonarSource/vault-action-wrapper@v3 | |
| with: | |
| secrets: | | |
| development/kv/data/jira user | JIRA_USER; | |
| development/kv/data/jira token | JIRA_TOKEN; | |
| - name: Add eslint-plugin label | |
| if: steps.check-rules.outputs.should_label == 'true' && steps.extract-jira-key.outputs.has_jira_key == 'true' | |
| env: | |
| VAULT_OUTPUT: ${{ steps.secrets.outputs.vault }} | |
| JIRA_KEY: ${{ steps.extract-jira-key.outputs.jira_key }} | |
| run: | | |
| JIRA_USER=$(echo "$VAULT_OUTPUT" | jq -r '.JIRA_USER') | |
| JIRA_TOKEN=$(echo "$VAULT_OUTPUT" | jq -r '.JIRA_TOKEN') | |
| # Use Jira REST API to add label | |
| HTTP_CODE=$(curl -s -o response.json -w "%{http_code}" -X PUT \ | |
| -H "Content-Type: application/json" \ | |
| -u "$JIRA_USER:$JIRA_TOKEN" \ | |
| -d '{"update": {"labels": [{"add": "eslint-plugin"}]}}' \ | |
| "https://sonarsource.atlassian.net/rest/api/3/issue/$JIRA_KEY") | |
| if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then | |
| echo "Successfully added 'eslint-plugin' label to $JIRA_KEY" | |
| else | |
| echo "Failed to add label to $JIRA_KEY. HTTP status: $HTTP_CODE" | |
| cat response.json | |
| exit 1 | |
| fi |