name: MSHUWAP Issue Handler on: issues: types: [opened] # Triggers when an issue is opened jobs: check_keywords: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v3 - name: Check for keywords in issue title and body id: check_keywords run: | # Define the list of keywords keywords=("Virus" "Malware" "Windows Defender" "Antivirus" "bitdefender" "defender" "kaspersky" "unwanted" "harmful") # Get the issue title and body from the event context ISSUE_TITLE="${{ github.event.issue.title }}" ISSUE_BODY="${{ github.event.issue.body }}" # Convert both title and body to lowercase for case-insensitive comparison ISSUE_TITLE_LOWER=$(echo "$ISSUE_TITLE" | tr '[:upper:]' '[:lower:]') ISSUE_BODY_LOWER=$(echo "$ISSUE_BODY" | tr '[:upper:]' '[:lower:]') # Check if any of the keywords are present in the title or body for keyword in "${keywords[@]}"; do # Convert the keyword to lowercase as well KEYWORD_LOWER=$(echo "$keyword" | tr '[:upper:]' '[:lower:]') if [[ "$ISSUE_TITLE_LOWER" == *"$KEYWORD_LOWER"* ]] || [[ "$ISSUE_BODY_LOWER" == *"$KEYWORD_LOWER"* ]]; then echo "'$keyword' found" echo "contains_keyword=true" >> $GITHUB_ENV break fi done - name: Comment, label, and close issue if keyword found if: env.contains_keyword == 'true' # Only run if a keyword was found run: | ISSUE_NUMBER="${{ github.event.issue.number }}" REPO="${{ github.repository }}" # Define the body of the comment with Markdown formatting COMMENT_BODY="I wish I was a little bit taller, I wish I was a baller I wish I had a girl who looked good, I would call her I wish I had a rabbit in a hat with a bat And a six-four Impala I wish I was a little bit taller, I wish I was a baller I wish I had a girl who looked good, I would call her I wish I had a rabbit in a hat with a bat And a six-four Impala I wish I was a little bit taller, I wish I was a baller I wish I had a girl who looked good, I would call her I wish I had a rabbit in a hat with a bat And a six-four Impala I wish I was a little bit taller, I wish I was a baller I wish I had a girl who looked good, I would call her I wish I had a rabbit in a hat with a bat And a six-four Impala I wish I was a little bit taller, I wish I was a baller I wish I had a girl who looked good, I would call her I wish I had a rabbit in a hat with a bat And a six-four Impala I wish I was a little bit taller, I wish I was a baller I wish I had a girl who looked good, I would call her I wish I had a rabbit in a hat with a bat And a six-four Impala I wish I was a little bit taller, I wish I was a baller I wish I had a girl who looked good, I would call her I wish I had a rabbit in a hat with a bat And a six-four Impala I wish I was a little bit taller, I wish I was a baller I wish I had a girl who looked good, I would call her I wish I had a rabbit in a hat with a bat And a six-four Impala I wish I was a little bit taller, I wish I was a baller I wish I had a girl who looked good, I would call her I wish I had a rabbit in a hat with a bat And a six-four Impala I wish I was a little bit taller, I wish I was a baller I wish I had a girl who looked good, I would call her I wish I had a rabbit in a hat with a bat And a six-four Impala" # Use printf to properly escape the string and handle special characters (e.g., newlines, apostrophes) COMMENT_BODY_ESCAPED=$(printf "%s" "$COMMENT_BODY" | jq -Rs .) # Post a comment on the issue with formatted text curl -X POST \ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ -d "{\"body\": $COMMENT_BODY_ESCAPED}" \ "https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER/comments" # Add the "duplicate" label to the issue curl -X POST \ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ -d '{"labels":["duplicate"]}' \ "https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER/labels" # Close the issue curl -X PATCH \ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ -d '{"state": "closed"}' \ "https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER"