79285341

Date: 2024-12-16 16:19:04
Score: 2.5
Natty:
Report link

For Future Stackoverflow reader,

Below is the code I use to resolve my issue. First, I wanted to see what are all the files I have? After that ,I narrowed down to the path I wanted and was able to add the JSON to the issue. Note, I added entire JSON to the issue, but was able to capture what I was looking for. Thanks @jonrsharpe for pointers.

name: close-issue-after-lint-open

on:
  issues:
    types: [opened]

jobs:
  close-issue:
    runs-on: ubuntu-latest
    permissions:
      issues: write
      contents: read
      packages: read
      statuses: write
    
    steps:
      - name: Checkout code
        uses: actions/[email protected]
        with:
          fetch-depth: 0

      - name: Run Super-linter
        uses: super-linter/[email protected]
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          VALIDATE_SQLFLUFF: true
          ENABLE_GITHUB_ACTIONS_STEP_SUMMARY: true
          
          
      - name: Log error to the issue
        if: failure()
        env: 
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          ISSUE: ${{ github.event.issue.number }}
          ERROR_LOG_PATH: ${{ github.workspace }}/super-linter-output/super-linter/super-linter-worker-results-SQLFLUFF.json
        run: |
          echo "Listing all files and directories in workspace:"
          ls -R $GITHUB_WORKSPACE  # List everything recursively in the workspace
          
          # Optionally, list the contents of the specific super-linter output directory
          if [ -d "${GITHUB_WORKSPACE}/${{ env.SUPER_LINTER_OUTPUT_DIRECTORY_NAME }}/super-linter" ]; then
            echo "Listing contents of the Super Linter output directory:"
            ls -R "${GITHUB_WORKSPACE}/${{ env.SUPER_LINTER_OUTPUT_DIRECTORY_NAME }}/super-linter"
          else
            echo "Super Linter output directory not found."
          fi
          
          # Check if the error log exists
          if [ -f "$ERROR_LOG_PATH" ]; then
            ERROR_LOG=$(cat "$ERROR_LOG_PATH")
          else
            ERROR_LOG="No errors found."
          fi

          # Post the error log to the issue
          gh issue comment $ISSUE --body "Super Linter found the following issues:$ERROR_LOG"

      - name: Close issue
        env: 
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          REPO: ${{ github.repository }}
          ISSUE: ${{ github.event.issue.number }}
        run: |
          # Close the issue and add a comment
          gh issue close --repo "$REPO" --comment "Autoclosing issue $ISSUE due to linting errors."
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (1): Stackoverflow
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • User mentioned (1): @jonrsharpe
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: biggboss2019