From 5504d6dfb7011801dd7a330a38d0a0b7bbe97b27 Mon Sep 17 00:00:00 2001 From: Nicolas COMPAIN Date: Mon, 12 Oct 2026 20:54:08 +0200 Subject: [PATCH] MODIF - Remplacement de la notification Slack par une notification Google Chat dans le pipeline Drone --- .drone.yml | 55 +++++++++++++++++++++++++++++++++++++++++------------- .gitignore | 1 + 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/.drone.yml b/.drone.yml index f737154..1ba6cd9 100644 --- a/.drone.yml +++ b/.drone.yml @@ -38,19 +38,48 @@ steps: branch: - prod - - name: slack - image: plugins/slack - settings: - webhook: https://hooks.slack.com/services/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 - channel: modules-communs - template: > - {{#success build.status}} - :white_check_mark: Déploiement <${DRONE_BUILD_LINK}|#${DRONE_BUILD_NUMBER}>. Beau travail, ${DRONE_COMMIT_AUTHOR_NAME} ! - {{else}} - :x: Déploiement <${DRONE_BUILD_LINK}|#${DRONE_BUILD_NUMBER}> c'est un échec, ${DRONE_COMMIT_AUTHOR_NAME}. - {{/success}} - - Repository : <${DRONE_REPO_LINK}|${DRONE_REPO_NAME}> depuis branche ${DRONE_BRANCH} + - name: google-chat + image: badouralix/curl-jq + failure: ignore + environment: + GOOGLE_CHAT_WEBHOOK: "https://chat.googleapis.com/v1/spaces/AAQAGPSk8N0/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=QA6EDa74Bv-zWs7NiWrq54npANfaUtgqQBjOd35ZRCs" + NOTIFICATION_CONTEXT: "Build" + NOTIFICATION_TARGET_LABEL: "Voir le dépôt" + NOTIFICATION_TARGET_URL: "https://git.nwb.fr/modules-communs-php/multi-downloader-client" + commands: + - | + set -eu + jq -n ' + def html: gsub("&"; "&") | gsub("<"; "<") | gsub(">"; ">"); + (env.DRONE_BUILD_STATUS == "success") as $success | + (env.NOTIFICATION_CONTEXT // "Build") as $context | + { + cardsV2: [{ + cardId: "drone-notification", + card: { + header: { + title: (if env.NOTIFICATION_PHASE == "start" then "🚀 " + $context + (if $context == "Publication" then " démarrée" else " démarré" end) elif $success then "✅ " + $context + (if $context == "Publication" then " réussie" else " réussi" end) else "❌ " + $context + " en échec" end), + subtitle: ((env.DRONE_REPO_NAME // "Projet") + " · build #" + (env.DRONE_BUILD_NUMBER // "?")) + }, + sections: [{ + widgets: [ + {decoratedText: {startIcon: {materialIcon: {name: "person"}}, topLabel: "Auteur", text: ((env.DRONE_COMMIT_AUTHOR_NAME // env.DRONE_COMMIT_AUTHOR // "Inconnu") | html)}}, + {decoratedText: {startIcon: {materialIcon: {name: "account_tree"}}, topLabel: "Branche", text: ((env.DRONE_BRANCH // "Inconnue") | html)}}, + {decoratedText: {startIcon: {materialIcon: {name: "commit"}}, topLabel: "Commit", text: (((env.DRONE_COMMIT_SHA // "")[0:8] + " : " + (env.DRONE_COMMIT_MESSAGE // "")) | html), wrapText: true}}, + {buttonList: {buttons: ([ + {text: env.NOTIFICATION_TARGET_LABEL, onClick: {openLink: {url: env.NOTIFICATION_TARGET_URL}}}, + {text: "Voir les logs Drone", onClick: {openLink: {url: env.DRONE_BUILD_LINK}}}, + {text: "Voir le commit", onClick: {openLink: {url: env.DRONE_COMMIT_LINK}}} + ] | map(select(.onClick.openLink.url != null and .onClick.openLink.url != "")))}} + ] + }] + } + }] + } + ' > /tmp/google-chat-payload.json + curl --fail-with-body --silent --show-error --connect-timeout 10 --max-time 30 \ + -X POST -H "Content-Type: application/json; charset=UTF-8" \ + --data-binary @/tmp/google-chat-payload.json "$GOOGLE_CHAT_WEBHOOK" when: status: - failure diff --git a/.gitignore b/.gitignore index 2a5246d..2bdab99 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ vendor composer.lock .DS_Store +Icon?