forked from harness/harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.go
28 lines (25 loc) · 812 Bytes
/
parse.go
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
package bitbucketserver
import (
"encoding/json"
"fmt"
"github.com/drone/drone/model"
"github.com/drone/drone/remote/bitbucketserver/internal"
"net/http"
)
// parseHook parses a Bitbucket hook from an http.Request request and returns
// Repo and Build detail. TODO: find a way to support PR hooks
func parseHook(r *http.Request, baseURL string) (*model.Repo, *model.Build, error) {
hook := new(internal.PostHook)
if err := json.NewDecoder(r.Body).Decode(hook); err != nil {
return nil, nil, err
}
build := convertPushHook(hook, baseURL)
repo := &model.Repo{
Name: hook.Repository.Slug,
Owner: hook.Repository.Project.Key,
FullName: fmt.Sprintf("%s/%s", hook.Repository.Project.Key, hook.Repository.Slug),
Branch: "master",
Kind: model.RepoGit,
}
return repo, build, nil
}