-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add preliminary pipeline-notifier/github2teams.clj
- Loading branch information
Showing
5 changed files
with
60 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
FROM babashka/babashka | ||
|
||
COPY \ | ||
pipeline-notifier/gitlab2teams.clj \ | ||
pipeline-notifier/*.clj \ | ||
vault-exec-agent/vault-exec-agent.clj \ | ||
\ | ||
/scripts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
FROM babashka/babashka:alpine | ||
|
||
COPY \ | ||
pipeline-notifier/gitlab2teams.clj \ | ||
pipeline-notifier/*.clj \ | ||
vault-exec-agent/vault-exec-agent.clj \ | ||
\ | ||
/scripts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
FROM babashka/babashka | ||
|
||
COPY pipeline-notifier/gitlab2teams.clj /scripts/ | ||
COPY pipeline-notifier/*.clj /scripts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env bb | ||
|
||
(require '[babashka.http-client :as http] | ||
'[cheshire.core :as json] | ||
'[hiccup2.core :as h]) | ||
|
||
(defn env [v] | ||
(System/getenv (str/upper-case (name v)))) | ||
|
||
#_(def MESSAGE_PRE | ||
(if-let [access-token (env :PN__GITLAB_ACCESS_TOKEN)] | ||
(-> (str "https://gitlab.com/api/v4/projects/" (env :CI_PROJECT_ID) "/repository/commits/" (env :CI_COMMIT_SHA)) | ||
(http/get {:headers {"PRIVATE-TOKEN" access-token}}) | ||
(:body) | ||
(json/parse-string) | ||
(get "message") | ||
(str/trimr)))) | ||
|
||
(def html-notification-string | ||
(let [triggering_actor (env :GITHUB_TRIGGERING_ACTOR) | ||
author (env :GITHUB_ACTOR) | ||
callout (if (env :PN__PIPELINE_PASSED) | ||
[:span {:style "background-color: green; color: white; padding: 4px; font-weight: bold"} "PASSED:"] | ||
[:span {:style "background-color: red; color: white; padding: 4px; font-weight: bold"} "FAILED:"]) | ||
|
||
project-trim-chars (env :PN__PROJECT_TRIM_CHARS) | ||
project-name (if project-trim-chars | ||
(str/replace-first (env :GITHUB_REPOSITORY) (re-pattern project-trim-chars) "") | ||
(env :GITHUB_REPOSITORY)) | ||
repo-url (str "https://" (env :GITHUB_REPOSITORY))] | ||
(str | ||
(h/html | ||
[:h1 callout | ||
" " | ||
[:a {:href (str repo-url "/tree/" (env :GITHUB_REF_NAME))} | ||
[:span {:style "background-color: blue; color: white"} | ||
[:em (env :GITHUB_REF_NAME)]]] | ||
" " | ||
[:a {:href repo-url} | ||
[:strong project-name]]] | ||
" by " | ||
[:a {:href (str "https://github.com/" author)} | ||
[:strong author]] | ||
": commit " | ||
[:a {:href (str repo-url "/commit/" (env :GITHUB_SHA))} (env :GITHUB_SHA)] | ||
[:br] | ||
" pipeline " | ||
[:a {:href (str repo-url "/actions/run/" (env :)} (env :GITHUB_RUN_ID)] | ||
[:br] | ||
[:br] | ||
#_[:pre MESSAGE_PRE])))) | ||
|
||
(let [webhook-url (env :PN__TEAMS_WEBHOOK_URL)] | ||
(http/post webhook-url | ||
{:headers {"Content-Type" "application/json"} | ||
:body (json/generate-string {:text html-notification-string})})) |