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

ClickUp Integration #57

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/pantheon/drush-commands
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if [[ -z "$P_SITE" ]] || [[ -z "$P_ENV" ]]; then
exit 1
fi

echo "Starting environment deploy commmands."
echo "Starting environment deploy commands."
# Update the Drupal database
terminus -n drush "$P_SITE.$P_ENV" -- updatedb -y

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
@@ -0,0 +1,9 @@
Hello!

Security updates are required for some of the code that runs your website, [SITE_NAME].

We''ll run the upgrade and the work will be billed to your flat-rate annual/monthly security updates account.
In other words, this will not count towards your subscription hours.

Security updates are required for: [PROJECTS]

These updates are being performed automatically and we'll let you know when it is complete.
These updates are being performed automatically, and we'll let you know when it is complete.
Thank You!
108 changes: 92 additions & 16 deletions scripts/security-updates/automatic-update
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ echo "Updating projects"
DIR=$(pwd)
COMPOSER_CMD=$(which composer)
NOW=$(date +'%F')
UNIX_TIMESTAMP_MS=$(($(date -d "$NOW" '+%s')*1000))
cd $DIR
source "./vendor/fourkitchens/pots/scripts/security-updates/4k-openai-lib.sh"
BRANCH_NAME="feature/automated-sec-update-$NOW"
Expand All @@ -18,7 +19,7 @@ ADVISORIES=$(echo "$JSON_DATA" | jq '.advisories')

MESSAGE=""
TEST_STEPS=""
ZD_PROJECTS_UPDATED=""
PROJECTS_UPDATED=""

# Helper function to check if branch exist on remote repository.
gh_branch_exist () {
Expand All @@ -42,7 +43,7 @@ create_gh_branch () {
echo "true"
}

# Helper function to check if there are avaiable sec update to apply.
# Helper function to check if there are available sec update to apply.
security_updates_available () {
# 3. Loop through each key-value pair in the "advisories" object.
AVAILABLE_UPDATE="false"
Expand Down Expand Up @@ -84,7 +85,7 @@ if [[ $(security_updates_available) == "true" ]]; then
# Building PR information.
# Remove prefix "drupal/" from the project name
AUX=${PROJECT//drupal\//''}
ZD_PROJECTS_UPDATED+="${AUX}, "
PROJECTS_UPDATED+="${AUX}, "
if [ $AUX == 'core' ]; then
AUX="- Update [${PROJECT}](https://www.drupal.org/project/drupal/releases)."
else
Expand Down Expand Up @@ -156,24 +157,22 @@ if [[ $(security_updates_available) == "true" ]]; then
echo "Creating security updates Zendesk Ticket."
echo "-------------------------------------------"
ZD_API=https://advomatic.zendesk.com/api/v2
# Hardcode Requester ID.
# To get this project's Requester ID from Zendesk:
# group_id: 360007800612; Assigns the ticket to the security group.
# Environment variables; should be defined as CircleCI variables.
# ZD_REQUESTER_ID: Found by following the steps below.
# 1. Visit: https://advomatic.zendesk.com/agent/user_filters
# 2. Search for the user you need the requester ID for.
# 3. The user ID can be obtained from the user's url.
# e.g. https://advomatic.zendesk.com/agent/users/378771022972/requested_tickets
# e.g. Requester ID: 378771022972
# 4. Replace the value below.
# ZD_REQUESTER_ID : Env varible, should be define into the CircleCI variables, User into the client Org.
# ZD_TOKEN: Env varible, should be define into the CircleCI variables, you could find it into 1password
# ZD_LEAD_EMAIL: Env varible, should be define into the CircleCI variables (TL, TS)
# group_id: 360007800612 : This line into the JSON is assignning the ticket to security group

ZD_BODY_MESSAGE=`cat ./vendor/fourkitchens/pots/scripts/security-updates/ZD_TICKET_TEMPLATE.md`
# Replacing placehoders into the template.
# ZD_TOKEN: Located in 1Pass.
# ZD_LEAD_EMAIL: Find lead in engagements database.

ZD_BODY_MESSAGE=`cat ./vendor/fourkitchens/pots/scripts/security-updates/TICKET_TEMPLATE.md`
# Replacing placeholders in the template.
ZD_BODY_MESSAGE=${ZD_BODY_MESSAGE//\[SITE_NAME\]/$SITE_NAME}
ZD_BODY_MESSAGE=${ZD_BODY_MESSAGE//\[PROJECTS\]/$ZD_PROJECTS_UPDATED}
# Scaping new lines characters.
ZD_BODY_MESSAGE=${ZD_BODY_MESSAGE//\[PROJECTS\]/$PROJECTS_UPDATED}
# Scraping new line characters.
ZD_BODY_MESSAGE=${ZD_BODY_MESSAGE//$'\n'/\\n}
ZD_TICKET_TITLE="Security Updates Required For Your Website - ${SITE_NAME}"
ZD_JSON_DATA=$(printf '{
Expand Down Expand Up @@ -230,7 +229,84 @@ if [[ $(security_updates_available) == "true" ]]; then
echo "Zendesk Ticket successfully created."
echo "-------------------------------------------"
fi

# Create a ticket for ClickUp.
if [ -n "${CU_REQUESTER_ID}" -a -n "${CU_TOKEN}" -a -n "${CU_LEAD_EMAIL}" ]; then

# Creating ClickUp ticket.
echo "Creating security updates ClickUp Ticket."
echo "-------------------------------------------"
CU_API=https://api.clickup.com/api/v2
# Environment variables; should be defined as CircleCI variables.
# CU_CLIENT_ID: Look in ClickUp for id. e.g. 16
# CU_REQUESTER_ID: Look in ClickUp for id. e.g. 54648604
# CU_LIST_ID: Look in ClickUp for id. e.g. 901300865356
# CU_TOKEN: Located in 1Pass.
# CU_LEAD_EMAIL: Find lead in engagements database.

CU_BODY_MESSAGE=`cat ./vendor/fourkitchens/pots/scripts/security-updates/TICKET_TEMPLATE.md`
# Replacing placeholders in the template.
CU_BODY_MESSAGE=${CU_BODY_MESSAGE//\[SITE_NAME\]/$SITE_NAME}
CU_BODY_MESSAGE=${CU_BODY_MESSAGE//\[PROJECTS\]/$PROJECTS_UPDATED}
# Scraping new line characters.
CU_BODY_MESSAGE=${CU_BODY_MESSAGE//$'\n'/\\n}
CU_TICKET_TITLE="Security Updates Required For Your Website - ${SITE_NAME}"
CU_JSON_DATA=$(printf '{
"name": "%s",
"assignees": [
82036728
],
"tags": [
"autosec update"
],
"status": "in progress",
"priority": 2,
"start_date": "%s",
"start_date_time": false,
"notify_all": false,
"parent": null,
"links_to": null,
"check_required_custom_fields": true,
"custom_fields": [
{
"id": "b8bbcb75-a7c8-4eb7-9202-e56d227eefbf",
"value": "%s"
}
],
"description": "%s"
}' "$CU_TICKET_TITLE" "$UNIX_TIMESTAMP_MS" "$CU_CLIENT_ID" "$CU_BODY_MESSAGE")

# Create the ticket and capture the response.
RESPONSE=$(
curl -s ${CU_API}/list/901300865356/task \
-i -X POST \
-H "Authorization: ${CU_TOKEN}" \
-H "Content-Type: application/json" \
-d "$CU_JSON_DATA"
)

# Extract the task id from the response; I could not get jq to work.
cbfannin marked this conversation as resolved.
Show resolved Hide resolved
TASK_ID=$(echo "$RESPONSE" | awk -F'"id":' '{print $2}' | awk -F',' '{print $1}' | sed 's/"//g' | tr -d '[:space:]')

# Use the task id to add the requester to the "Requester" custom field.
CU_JSON_DATA_REQUESTER=$(printf '{
"value": {
"add": [
%s
]
}
}' "$CU_REQUESTER_ID")

curl -s ${CU_API}/task/${TASK_ID}/field/601d8088-a5d6-41c2-ad32-9bec68eac624 \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: ${CU_TOKEN}" \
-d "$CU_JSON_DATA_REQUESTER"

echo "ClickUp Ticket successfully created."
echo "-------------------------------------------"
fi
fi
else
echo "Nothing to do, None available sec updates."
echo "Nothing to do! No available security updates."
fi