Browse Source

Reintegrate Port specific code that was removed at the beginning of the rewrite

tags/v0.2.0
Bernhard Fröhlich 1 month ago
parent
commit
231f8bdab0
Signed by: Bernhard Froehlich <decke@bluelife.at> GPG Key ID: 4DD88C3F9F3B8333
2 changed files with 58 additions and 2 deletions
  1. 54
    2
      main.go
  2. 4
    0
      templates/index.html

+ 54
- 2
main.go View File

@@ -66,6 +66,7 @@ type queue struct {
66 66
 
67 67
 type job struct {
68 68
 	ID        string
69
+	Port      string
69 70
 	Startdate time.Time
70 71
 	Enddate   time.Time
71 72
 	Build     map[string]*build
@@ -111,6 +112,24 @@ func calcSignature(payload *[]byte, secret string) string {
111 112
 	return fmt.Sprintf("sha1=%x", mac.Sum(nil))
112 113
 }
113 114
 
115
+func getAffectedPort(data gitPushEventData) string {
116
+	lines := strings.Split(data.Commits[0].Message, "\n")
117
+
118
+	if len(lines) < 1 || strings.IndexByte(lines[0], ':') < 1 {
119
+		return ""
120
+	}
121
+
122
+	re := regexp.MustCompile(`^([a-z0-9-]+)/([a-zA-Z0-9-_.]+)$`)
123
+
124
+	port := strings.TrimSpace(lines[0][:strings.IndexByte(lines[0], ':')])
125
+
126
+	if re.MatchString(port) {
127
+		return port
128
+	}
129
+
130
+	return ""
131
+}
132
+
114 133
 func (c *controller) matchQueues(data gitPushEventData) []queue {
115 134
 	queues := make([]queue, 0)
116 135
 
@@ -119,6 +138,7 @@ NEXTQUEUE:
119 138
 		re := regexp.MustCompile(c.cfg.Queues[i].PathMatch)
120 139
 
121 140
 		for commit := range data.Commits {
141
+			// Queue name match against PathMatch config
122 142
 			for _, file := range data.Commits[commit].Added {
123 143
 				if re.MatchString(file) {
124 144
 					queues = append(queues, c.cfg.Queues[i])
@@ -132,6 +152,28 @@ NEXTQUEUE:
132 152
 					continue NEXTQUEUE
133 153
 				}
134 154
 			}
155
+
156
+			// Queue name from commit message tags (CI: yes/no/true/false)
157
+			lines := strings.Split(data.Commits[commit].Message, "\n")
158
+			for _, line := range lines {
159
+				line = strings.ToLower(line)
160
+				if strings.HasPrefix(line, "ci:") {
161
+					if strings.Contains(line, "no") || strings.Contains(line, "false") {
162
+						continue NEXTQUEUE
163
+					}
164
+					if strings.Contains(line, "yes") || strings.Contains(line, "true") {
165
+						queues = append(queues, c.cfg.Queues[i])
166
+						continue NEXTQUEUE
167
+					}
168
+				}
169
+			}
170
+		}
171
+
172
+		// Queue name from DefaultQueues config
173
+		for _, q := range c.cfg.DefaultQueues {
174
+			if q == c.cfg.Queues[i].Name {
175
+				queues = append(queues, c.cfg.Queues[i])
176
+			}
135 177
 		}
136 178
 	}
137 179
 
@@ -301,6 +343,12 @@ func (c *controller) handleWebhook(w http.ResponseWriter, r *http.Request) {
301 343
 		}
302 344
 	}
303 345
 
346
+	port := getAffectedPort(data)
347
+	if port == "" {
348
+		fmt.Fprint(w, "No category/port detected")
349
+		return
350
+	}
351
+
304 352
 	job := job{
305 353
 		ID:        time.Now().Format("20060102150405.000"),
306 354
 		Startdate: time.Now(),
@@ -406,9 +454,8 @@ func parseConfig(file string) config {
406 454
 
407 455
 	for i := range cfg.Queues {
408 456
 		if cfg.Queues[i].PathMatch == "" {
409
-			cfg.Queues[i].PathMatch = "^.*$"
457
+			cfg.Queues[i].PathMatch = "^$"
410 458
 		}
411
-
412 459
 		_, err := regexp.Compile(cfg.Queues[i].PathMatch)
413 460
 		if err != nil {
414 461
 			log.Fatalf("Error: %v", err)
@@ -419,6 +466,11 @@ func parseConfig(file string) config {
419 466
 			cfg.Queues[i].Environment["JOB_ID"] = "{{.ID}}"
420 467
 		}
421 468
 
469
+		_, ok = cfg.Queues[i].Environment["JOB_PORT"]
470
+		if ! ok {
471
+			cfg.Queues[i].Environment["JOB_PORT"] = "{{.Port}}"
472
+		}
473
+
422 474
 		_, ok = cfg.Queues[i].Environment["COMMIT_ID"]
423 475
 		if ! ok {
424 476
 			cfg.Queues[i].Environment["COMMIT_ID"] = "{{.PushEvent.CommitID}}"

+ 4
- 0
templates/index.html View File

@@ -42,6 +42,10 @@
42 42
 						<div class="column column-25"><b>Repository</b></div>
43 43
 						<div class="column column-75"><a href="{{.PushEvent.Repository.HTMLURL}}">{{.PushEvent.Repository.HTMLURL}}</a></div>
44 44
 					</div>
45
+					<div class="row">
46
+						<div class="column column-25"><b>Port</b></div>
47
+						<div class="column column-75"><a href="https://www.freshports.org/{{.Port}}/">{{.Port}}</a></div>
48
+					</div>
45 49
 					<div class="row">
46 50
 						<div class="column column-100"><b>Message</b></div>
47 51
 					</div>

Loading…
Cancel
Save