-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathworkchat.message
More file actions
114 lines (114 loc) · 6.14 KB
/
Copy pathworkchat.message
File metadata and controls
114 lines (114 loc) · 6.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
{{- define "k8s-header"}}
{{- $t := timeFormat .time "02.01.06 15:04:05"}}
{{- printf "*%s*: %s / %s\n*%s*: %s\nby _%s_" (toUpper .data.operation) .data.kind .data.location .channel $t .data.user.name}}
{{- end}}
{{- define "k8s-namespace"}}{{- end}}
{{- define "k8s-node"}}{{- end}}
{{- define "k8s-replicaset"}}{{- end}}
{{- define "k8s-statefulset"}}
{{- printf "\n*Replicas* => %.0f\n*Selector* => %s" .spec.replicas .spec.selector}}
{{- template "k8s-pod" .spec.template}}
{{- end}}
{{- define "k8s-daemonset"}}{{- end}}
{{- define "k8s-secret"}}{{- end}}
{{- define "k8s-ingress"}}{{- end}}
{{- define "k8s-cronjob"}}{{- end}}
{{- define "k8s-job"}}{{- end}}
{{- define "k8s-configmap"}}{{- end}}
{{- define "k8s-role"}}{{- end}}
{{- define "k8s-deployment"}}
{{- printf "\n*Replicas* => %.0f\n*Selector* => %s" .spec.replicas .spec.selector}}
{{- template "k8s-pod" .spec.template}}
{{- end}}
{{- define "k8s-service"}}
{{- printf "\n*%s* => %s" .spec.type .spec.clusterIP}}
{{- range .spec.ports}}
{{- printf "\n*%s* %.0f => %.0f" .protocol .port .targetPort}}
{{- end}}
{{- printf "\n*Selector* => %s" .spec.selector}}
{{- end}}
{{- define "k8s-pod"}}
{{- range .spec.containers}}
{{- printf "\n*%s* => %s" .name .image}}
{{- range .ports}}
{{- printf " [%s: %.0f]" .protocol .containerPort}}
{{- end}}
{{- end}}
{{- end}}
{{- define "alertmanager-header"}}
{{- $t := timeFormat .time "02.01.06 15:04:05"}}
{{- printf "*%s*: %s\n*%s*: %s" (toUpper .data.status) .data.labels.alertname .channel $t}}
{{- end}}
{{- define "alertmanager-body"}}
{{- if eq .status "firing"}}{{- printf "\n*StartsAt*: %s" (timeFormat .startsAt "02.01.06 15:04:05") }}{{end}}
{{- if eq .status "resolved"}}{{- printf "\n*endsAt*: %s" (timeFormat .endsAt "02.01.06 15:04:05") }}{{end}}
{{- end}}
{{- define "gitlab-header"}}
{{- $t := timeFormat .time "02.01.06 15:04:05"}}
{{- if .data.project}}{{- printf "*%s*: %s / %s@%s\n*%s*: %s\nby _%s_" (toUpper .data.object_kind) .data.project.namespace .data.project.name .data.object_attributes.ref .channel $t .data.user.username}}
{{- else}}{{- printf "*%s*: %s@%s\n*%s*: %s\nby _%s_" (toUpper .data.object_kind) .data.project_name .data.ref .channel $t .data.user.username}}{{end}}
{{- end}}
{{- define "gitlab-commit"}}
{{- if .commit.author}}{{- printf "\n*Commit author* => %s" .commit.author.name}}{{else}}{{- printf "\n*Commit author* => %s" .commit.author_name}}{{end}}
{{- printf "\n*Commit message* => %s" .commit.message}}
{{- if .commit.url}}{{- printf "\n%s" .commit.url}}{{else}}{{- printf "\n%s/-/commit/%s" .repository.homepage .commit.sha}}{{end}}
{{- end}}
{{- define "gitlab-stages"}}
{{- $match := .match}}
{{- range .stages}}
{{- if and (.runner.description | regexMatch $match) (not (empty .finished_at))}}
{{- printf "\n*%s/%s* [%s] => %s" .stage .name .user.username .runner.description}}
{{- end}}
{{- end}}
{{- end}}
{{- define "gitlab-pipeline"}}
{{- $match := getEnv "EVENTS_GITLAB_RUNNERS"}}{{$ok := false}}
{{- range .data.builds}}
{{- if and (.runner.description | regexMatch $match) (not (empty .finished_at))}}{{$ok = true}}{{end}}
{{- end}}
{{- if $ok}}
{{- template "gitlab-header" .}}
{{- template "gitlab-commit" (dict "repository" "" "commit" .data.commit)}}
{{- template "gitlab-stages" (dict "stages" (reverse .data.builds) "match" $match)}}
{{- printf "\n%s/-/pipelines/%.0f" .data.project.web_url .data.object_attributes.id}}
{{- end}}
{{- end}}
{{- define "gitlab-build"}}
{{- $match := getEnv "EVENTS_GITLAB_RUNNERS"}}
{{- if and (.data.runner.description | regexMatch $match) (not (empty .data.build_duration))}}
{{- template "gitlab-header" .}}
{{- template "gitlab-commit" (dict "repository" .data.repository "commit" .data.commit)}}
{{- printf "\n*%s/%s* => %s" .data.build_stage .data.build_name .data.runner.description}}
{{- printf "\n%s/-/jobs/%.0f" .data.repository.homepage .data.build_id}}
{{- end}}
{{- end}}
{{- define "text"}}
{{- if eq .type "K8sEvent"}}
{{- if not (.data.user.name | regexMatch "(system:serviceaccount:*|system:*)")}}
{{- if .data.object}}
{{- if eq .data.kind "Namespace"}}{{template "k8s-header" .}}{{template "k8s-namespace" .data.object}}{{end}}
{{- if eq .data.kind "Node"}}{{template "k8s-header" .}}{{template "k8s-node" .data.object}}{{end}}
{{- if eq .data.kind "ReplicaSet"}}{{template "k8s-header" .}}{{template "k8s-replicaset" .data.object}}{{end}}
{{- if eq .data.kind "StatefulSet"}}{{template "k8s-header" .}}{{template "k8s-statefulset" .data.object}}{{end}}
{{- if eq .data.kind "DaemonSet"}}{{template "k8s-header" .}}{{template "k8s-daemonset" .data.object}}{{end}}
{{- if eq .data.kind "Secret"}}{{template "k8s-header" .}}{{template "k8s-secret" .data.object}}{{end}}
{{- if eq .data.kind "Ingress"}}{{template "k8s-header" .}}{{template "k8s-ingress" .data.object}}{{end}}
{{- if eq .data.kind "CronJob"}}{{template "k8s-header" .}}{{template "k8s-cronjob" .data.object}}{{end}}
{{- if eq .data.kind "Job"}}{{template "k8s-header" .}}{{template "k8s-job" .data.object}}{{end}}
{{- if eq .data.kind "ConfigMap"}}{{template "k8s-header" .}}{{template "k8s-configmap" .data.object}}{{end}}
{{- if eq .data.kind "Role"}}{{template "k8s-header" .}}{{template "k8s-role" .data.object}}{{end}}
{{- if eq .data.kind "Deployment"}}{{template "k8s-header" .}}{{template "k8s-deployment" .data.object}}{{end}}
{{- if eq .data.kind "Service"}}{{template "k8s-header" .}}{{template "k8s-service" .data.object}}{{end}}
{{- if eq .data.kind "Pod"}}{{template "k8s-header" .}}{{template "k8s-pod" .data.object}}{{end}}
{{- else}}{{template "k8s-header" .}}{{end}}
{{- end}}
{{- end}}
{{- if eq .type "AlertmanagerEvent"}}
{{template "alertmanager-header" .}}{{template "alertmanager-body" .data}}
{{- end}}
{{- if eq .type "GitlabEvent"}}
{{- if eq .data.object_kind "pipeline"}}{{template "gitlab-pipeline" .}}{{end}}
{{- if eq .data.object_kind "build"}}{{template "gitlab-build" .}}{{end}}
{{- end}}
{{- end}}
{{- define "workchat-message"}}{{template "text" .}}{{- end}}