-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathreceive.go
More file actions
54 lines (50 loc) · 1.53 KB
/
receive.go
File metadata and controls
54 lines (50 loc) · 1.53 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
package gitreceive
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
// #!/usr/bin/env bash
// set -eo pipefail
//
// repository=$1
// app=${1%.git}
// sha=$2
// username=$3
// fingerprint=$4
//
// curl \
// -X 'POST' --fail \
// -H 'Content-Type: application/json' \
// -H "X-Deis-Builder-Auth: {{ getv "/deis/controller/builderKey" }}" \
// -d "{\"receive_user\": \"$username\", \"receive_repo\": \"$app\", \"sha\": \"$sha\", \"fingerprint\": \"$fingerprint\", \"ssh_connection\": \"$SSH_CONNECTION\", \"ssh_original_command\": \"$SSH_ORIGINAL_COMMAND\"}" \
// --silent "http://$DEIS_WORKFLOW_SERVICE_HOST:$DEIS_WORKFLOW_SERVICE_PORT/v2/hooks/push" >/dev/null
func receive(conf *Config, newRev string) error {
urlStr := fmt.Sprintf("http://%s:%s/v2/hooks/push", conf.WorkflowHost, conf.WorkflowPort)
bodyMap := map[string]string{
"receive_user": conf.Username,
"receive_repo": conf.App,
"sha": conf.SHA,
"fingerprint": conf.Fingerprint,
"ssh_connection": conf.SSHConnection,
"ssh_original_command": conf.SSHOriginalCommand,
}
var body bytes.Buffer
if err := json.NewEncoder(&body).Encode(bodyMap); err != nil {
return err
}
req, err := http.NewRequest("POST", urlStr, &body)
if err != nil {
return err
}
// TODO: inspect resp for status code
// TODO: use ctxhttp here (https://godoc.org/golang.org/x/net/context/ctxhttp)
// resp, err := http.Do(req)
_, err = http.DefaultClient.Do(req)
if err != nil {
return err
}
// TODO: inspect resp for status code
return nil
}