Skip to content

Commit

Permalink
add preliminary pipeline-notifier/github2teams.clj
Browse files Browse the repository at this point in the history
  • Loading branch information
jf committed Oct 2, 2024
1 parent acc01b7 commit 6539c65
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
branches:
- master
paths:
- pipeline-notifier/gitlab2teams.clj
- pipeline-notifier/*.clj
- pipeline-notifier/Dockerfile
- .github/workflows/build_push_docker_hub:_pipeline-notifier.yml

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
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/
2 changes: 1 addition & 1 deletion Dockerfile.alpine
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/
2 changes: 1 addition & 1 deletion pipeline-notifier/Dockerfile
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/
56 changes: 56 additions & 0 deletions pipeline-notifier/github2teams.clj
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})}))

0 comments on commit 6539c65

Please sign in to comment.