-
Notifications
You must be signed in to change notification settings - Fork 4
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
#158013889 Add slack configuration #1
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reviewed your PR add, try to ensure that his funtion can be used by anyone whether is within andela or not. Make it as dynamic as possible.
k8s/deploy
Outdated
EMOJIS=(":celebrate:" ":party_dinosaur:" ":hammer-time:" ":andela:" ":victory-danch:" ":aw-yeah:" ":carlton-dance:" ":yes:" ":partyparrot:" ":dancing-penguin:" ":aww-yeah-remix:" ) | ||
RANDOM=$$$(date +%s) | ||
EMOJI=${EMOJIS[$RANDOM % ${#EMOJIS[@]} ]} | ||
COMMIT_LINK="https://github.com/AndelaOSP/${CIRCLE_PROJECT_REPONAME}/commit/${CIRCLE_SHA1}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line assumes all projects will be on andelaOSP organization, this will not work with the project on other organization best case HOF. YOu can break this line further to something like this.
COMMIT_LINK="https://github.com/${USERNAME}/${BRANCH_NAME}/commit/${CIRCLE_SHA1}"
@@ -225,3 +224,18 @@ isAllowedDeployEnvironment() { | |||
[ -z $(echo $ALLOWED_DEPLOY_ENVIRONMENTS | grep -o $__environment) ] && error "$__environment is not an allowed deployment environment" | |||
success "Setting up deployments for $__environment environment" | |||
} | |||
|
|||
configureSlackNotifications() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add $USERNAME, $BRANCH_NAME, $CIRCLE_SHA1
as required variables for this function.
k8s/deploy
Outdated
RANDOM=$$$(date +%s) | ||
EMOJI=${EMOJIS[$RANDOM % ${#EMOJIS[@]} ]} | ||
COMMIT_LINK="https://github.com/AndelaOSP/${CIRCLE_PROJECT_REPONAME}/commit/${CIRCLE_SHA1}" | ||
DEPLOYMENT_TEXT="Tag: ${IMG_TAG} has just been deployed to ${CONTAINER_NAME} in ${ENVIRONMENT} $COMMIT_LINK " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line makes use of unknown variables IMG_TAG, CONTAINER_NAME
refer to previous functions and ensure that you use the already pre-existing set variables or make the required variables for this function.
k8s/deploy
Outdated
echo "sending deployment notification to configured slack channel" | ||
curl -X POST --data-urlencode \ | ||
"payload={\"channel\": \"${CHANNEL}\", \"username\": \"DeployNotification\", \"text\": \"${SLACK_DEPLOYMENT_TEXT}\", \"icon_emoji\": \":rocket:\"}" \ | ||
https://hooks.slack.com/services/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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a public repository I think this should be passed as an environment variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, thanks for the review. Going to make the changes
Add slack integration
Thomas, I have made the changes by integrating more env variables to make the script dynamic and usable to all people. One direct variable I have made is the airplane emoji on the last line because it comes in all slack versions |
k8s/deploy
Outdated
EMOJIS=(":celebrate:" ":party_dinosaur:" ":hammer-time:" ":andela:" ":victory-danch:" ":aw-yeah:" ":carlton-dance:" ":yes:" ":partyparrot:" ":dancing-penguin:" ":aww-yeah-remix:" ) | ||
# declare any 10 emojis | ||
# for example; EMOJIS=(":celebrate:" ":party_dinosaur:" ":hammer-time:" ":andela:" ":victory-danch:" ":aw-yeah:" ":carlton-dance:" ":partyparrot:" ":dancing-penguin:" ":aww-yeah-remix:" ) | ||
EMOJIS=(${EMOJI_1} ${EMOJI_2} ${EMOJI_3} ${EMOJI_4} ${EMOJI_5} ${EMOJI_6} ${EMOJI_7} ${EMOJI_8} ${EMOJI_9} ${EMOJI_10} ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of making user add so many emojis, you as them to pass an array of them. And assign default is not specified.
configureSlackNotifications() {
# get the user emojis
DEFAULT_EMOJIS=(
":celebrate:"
":party_dinosaur:"
":hammer-time:"
":andela:"
":victory-danch:"
":aw-yeah:"
":carlton-dance:"
":partyparrot:"
":dancing-penguin:"
":aww-yeah-remix:"
)
local __emojis=$1
if [ "$__emojis" ]; then
EMOJIS=$__emojis
else
EMOJIS=$DEFAULT_EMOJIS
fi
# your logic goes here
}
What does this PR do?
This PR adds Slack notification configurations to the bash-module-scripts
Description of Task to be completed
With the current implementation, the deployment process can successfully take place but no notification is given. If the changes are merged, the script will be able to send notifications to the set variables channel and slack-web-hook in the Circleci dashboard.
What are the relevant pivotal tracker stories?
Completes #158013889
Mistakes
Forgot to branch off master. This means the comparisons are to be made on master of the forked against master on the remote.