11package github
22
3- import "fmt"
3+ import (
4+ "fmt"
5+ "regexp"
6+ "strconv"
7+ )
48
59// Maps repositories to namespace templates
610var repoToNamespaceTemplateMap map [string ]string
711
12+ // Deployment namespace regexes
13+ var namespaceRegexes []namespaceRegex
14+
815// Contains the list of Renku global images
916var globalImagesSlice []string
1017
@@ -20,9 +27,28 @@ func GetGlobalImages() []string {
2027 return globalImagesSlice [:]
2128}
2229
30+ func MatchDeploymentNamespace (namespace string ) (repository string , pr int ) {
31+ for i := range namespaceRegexes {
32+ res := namespaceRegexes [i ].regex .FindStringSubmatch (namespace )
33+ if res != nil {
34+ pr , err := strconv .Atoi (res [1 ])
35+ if err == nil && pr > 0 {
36+ return namespaceRegexes [i ].repository , pr
37+ }
38+ }
39+ }
40+ return "" , 0
41+ }
42+
43+ type namespaceRegex struct {
44+ regex * regexp.Regexp
45+ repository string
46+ }
47+
2348func init () {
2449 initRepoToNamespaceTemplateMap ()
2550 initGlobalImagesSlice ()
51+ initNamespaceRegexes ()
2652}
2753
2854func initRepoToNamespaceTemplateMap () {
@@ -31,6 +57,32 @@ func initRepoToNamespaceTemplateMap() {
3157 "SwissDataScienceCenter/renku" : "ci-renku-%d" ,
3258 "SwissDataScienceCenter/renku-data-services" : "renku-ci-ds-%d" ,
3359 "SwissDataScienceCenter/renku-ui" : "renku-ci-ui-%d" ,
60+ "SwissDataScienceCenter/renku-gateway" : "renku-ci-gw-%d" ,
61+ }
62+ }
63+
64+ func initNamespaceRegexes () {
65+ namespaceRegexes = []namespaceRegex {
66+ {
67+ regex : regexp .MustCompile (`^renku-ci-am-(\d+)$` ),
68+ repository : "SwissDataScienceCenter/amalthea" ,
69+ },
70+ {
71+ regex : regexp .MustCompile (`^ci-renku-(\d+)$` ),
72+ repository : "SwissDataScienceCenter/renku" ,
73+ },
74+ {
75+ regex : regexp .MustCompile (`^renku-ci-ds-(\d+)$` ),
76+ repository : "SwissDataScienceCenter/renku-data-services" ,
77+ },
78+ {
79+ regex : regexp .MustCompile (`^renku-ci-ui-(\d+)$` ),
80+ repository : "SwissDataScienceCenter/renku-ui" ,
81+ },
82+ {
83+ regex : regexp .MustCompile (`^renku-ci-gw-(\d+)$` ),
84+ repository : "SwissDataScienceCenter/renku-gateway" ,
85+ },
3486 }
3587}
3688
0 commit comments