-
Notifications
You must be signed in to change notification settings - Fork 0
/
push.go
43 lines (31 loc) · 965 Bytes
/
push.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package webhooks
import (
log "github.com/Sirupsen/logrus"
"github.com/postgres-ci/app-server/src/app/models/webhooks/common"
"github.com/postgres-ci/app-server/src/common/errors"
"github.com/postgres-ci/app-server/src/env"
"github.com/postgres-ci/hooks/git"
)
func Push(token string, push git.Push) error {
commits := make(common.Commits, 0, len(push.Commits))
for _, c := range push.Commits {
commits = append(commits, common.Commit{
SHA: c.ID,
Message: c.Message,
CommittedAt: c.CommittedAt,
CommitterName: c.Committer.Name,
CommitterEmail: c.Committer.Email,
AuthorName: c.Author.Name,
AuthorEmail: c.Author.Email,
})
}
_, err := env.Connect().Exec("SELECT hook.push($1, $2, $3)", token, common.RefToBranch(push.Ref), commits)
if err != nil {
err := errors.Wrap(err)
if err.(*errors.Error).IsFatal() {
log.Errorf("Could not add push: %v", err)
}
return err
}
return nil
}