-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_trigger.go
More file actions
38 lines (32 loc) · 874 Bytes
/
api_trigger.go
File metadata and controls
38 lines (32 loc) · 874 Bytes
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
package main
import (
"errors"
"net/http"
"strings"
)
// apiTrigger pulls the latest update for a repository and notifies any watchers.
// TODO: Actually implement watchers.
func apiTrigger(w http.ResponseWriter, r *http.Request) error {
q := r.URL.Query()
username := q.Get("user")
token := q.Get("token")
username = strings.Trim(username, "\n ")
user := users.Get(username)
if user == nil {
return errors.New("unknown user " + username)
}
if user.Token != token {
return errors.New("token mismatch for user " + username)
}
name := q.Get("name")
name = strings.Trim(name, "\n ")
trigger := triggermap[name]
if trigger == nil {
return errors.New("unknown repository " + name)
}
info("Updating %s (%s) from %s", trigger.Name, trigger.Path, trigger.URL)
if trigger.CLI {
return gitExternalPull(trigger.Path)
}
return gitPull(trigger.Path)
}