Skip to content

Cannot Dismiss/Delete more than 25 alerts at a time from UI #8250

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

Closed
mismailkhan88 opened this issue Feb 25, 2022 · 4 comments
Closed

Cannot Dismiss/Delete more than 25 alerts at a time from UI #8250

mismailkhan88 opened this issue Feb 25, 2022 · 4 comments
Labels
question Further information is requested

Comments

@mismailkhan88
Copy link

In a project I am currently working on, there are 4000+ code scanning alerts (coming from the security-and-quality query) rules we've investigated, which are not a real problem for us, so we'd like to close all of them together.

Through the UI on the Code Scanning Alerts page, I see that only 25 entries can be selected at a time that appears on a single page.

Is this possible to select all of the alerts in bulk and apply some action on all of them at once?

@mismailkhan88 mismailkhan88 added the question Further information is requested label Feb 25, 2022
@mismailkhan88 mismailkhan88 changed the title Gen Cannot Dismiss/Delete more than 25 alerts at a time from UI Cannot Dismiss/Delete more than 25 alerts at a time from UI Feb 25, 2022
@RasmusWL
Copy link
Member

Hi @mismailkhan88, thanks for your question.

As far as I'm aware, it's not possible to dismiss more than 25 at a time using the UI. You should be able to use the API to dismiss alerts though, which is described here: https://docs.github.com/en/rest/reference/code-scanning#update-a-code-scanning-alert

@mismailkhan88
Copy link
Author

Hi @RasmusWL,
Thanks for the quick response and really appreciate it, I have one more question, currently, we are using the enterprise GitHub, so does that mean that my enterprise admin will have to set up the API for us to use? Or will it be available out of the box on enterprise github?

@aibaars
Copy link
Contributor

aibaars commented Feb 25, 2022

@mismailkhan88 It's available out of the box. See https://docs.github.com/en/rest/reference/code-scanning#update-a-code-scanning-alert .

The github-cli is a handy tool for making scripted Rest-API call.

@ChrisCarini
Copy link

ChrisCarini commented Jan 4, 2025

I was testing out an action that checked the spelling of words in a repository, and it opened 5k+ code scanning alerts.

I found this thread, which helped expedite me finding that there was an API for dismissing alerts.

Because sharing is caring, below is the script I crafted to bulk search + dismiss alerts:

#!/bin/bash

TOOL_NAME="check-spelling"
STATE="open"
GITHUB_REPO="ChrisCarini/sample-intellij-plugin"

DESIRED_STATE="dismissed"
DISMISSAL_REASON="won't fix"
DISMISSAL_COMMENT="I was trying out check-spelling; but it opened a ton of code scanning issues and covered **WAY** more than I wanted/expected. I've since removed it from this repo, and am now dismissing all alerts it generated."

# Loop until no alerts are found
while true; do
  # Fetch the results and extract the URLs using jq
  result=$(gh api "/repos/${GITHUB_REPO}/code-scanning/alerts?tool_name=${TOOL_NAME}&per_page=100&state=${STATE}" | jq -r '.[].url')

  # Check if the result is empty
  if [ -z "$result" ]; then
    echo "No ${STATE} alerts found for the ${TOOL_NAME} tool. Exiting."
    break
  else
    alert_count=$(echo "$result" | grep -c '^')
    echo "Found ${alert_count} ${STATE} alerts for the ${TOOL_NAME} tool."
    
    # Pipe each URL into xargs, and execute the gh api command without using sh -c
    echo "$result" | xargs -n 1 -I{} \
      gh api --method PATCH {} \
      -f "state=${DESIRED_STATE}" \
      -f "dismissed_reason=${DISMISSAL_REASON}" \
      -f "dismissed_comment=${DISMISSAL_COMMENT}" \
      | jq -r '"Alert \(.number) dismissed:\n\tURL:          \(.html_url)\n\tState:        \(.state)\n\tDismissed by: \(.dismissed_by.login)\n\tDismissed at: \(.dismissed_at)\n\tReason:       \(.dismissed_reason)"'
  fi

  echo "Sleeping for 10 seconds..."
  sleep 10
done

Hopefully it helps save someone else a bit of time from needing to craft a similar script in the future. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants