Skip to content
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

Closing an issue support #6

Open
ncrmro opened this issue Apr 24, 2024 · 0 comments
Open

Closing an issue support #6

ncrmro opened this issue Apr 24, 2024 · 0 comments

Comments

@ncrmro
Copy link

ncrmro commented Apr 24, 2024

My team used this action as inspiration but added the ability to close an issue, I can open a PR with the following if yall would like.

#!/usr/bin/env bash
set -ex

if [ $# -lt 1 ]; then
    echo "No arguments provided"
    echo "Provide an environment"
    exit 1
fi

alias=${1}
action=${2}

# Make sure an alias was defined
if [[ -z "${ALIAS}" ]]; then
    echo "ERROR: No alert alias was set while attempting to generate OpsGenie alert"
    exit 2;
fi

# Make sure an action was defined
if [ "$action" != "open" ] && [ "$action" != "close" ]; then
    echo "Invalid action, should be open or close"
    exit 1
fi

if [ "$action" = "open" ]; then
    priority=${3}
    message=${4}

    # Make sure an acceptable priority level was defined
    if [[ "P1" != "${priority}" ]] && [[ "P2" != "${priority}" ]] && [[ "P3" != "${priority}" ]] && [[ "P4" != "${priority}" ]] && [[ "P5" != "${priority}" ]]; then
        echo "ERROR: An invalid alert priority level (${priority}) was set, it must be one of the valid OpsGenie alert levels (P1-P5)"
        exit 3;
    fi

    # Make sure a message was defined
    if [[ -z "${message}" ]]; then
        echo "ERROR: No alert message was set while attempting to generate OpsGenie alert"
        exit 1;
    fi
    curl -X POST https://api.opsgenie.com/v2/alerts \
        -H "Content-Type: application/json" \
        -H "Authorization: GenieKey ${OPSGENIE_API_KEY}" \
        -d \
    '{
        "entity": "github-actions",
        "source": "'${GITHUB_REPOSITORY}'",
        "details": {
            "github_repository": "$'{GITHUB_REPOSITORY}'",
            "github_ref": "'${GITHUB_REF}'",
            "github_workflow": "'${GITHUB_WORKFLOW}'",
            "github_action": "'${GITHUB_ACTION}'",
            "github_event_name": "'${GITHUB_EVENT_NAME}'",
            "github_event_path": "'${GITHUB_EVENT_PATH}'",
            "github_actor": "'${GITHUB_ACTOR}'",
            "github_sha": "'${GITHUB_SHA}'"
        },
        "message": "Release failure on '${current_branch}'",
        "alias": "release-failure-'${current_branch}'",
        "description":"Release failure on '${current_branch}' see '${workflow_url}'",
        "priority":"'${priority}'"
    }'
else
    curl -X POST "https://api.opsgenie.com/v2/alerts/${alias}/close?identifierType=alias" \
        -H "Content-Type: application/json" \
        -H "Authorization: GenieKey ${OPSGENIE_API_KEY}" \
        -d  '{}'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant