Skip to content

Commit b718831

Browse files
committed
add: webhook push
1 parent afa65b4 commit b718831

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/app/models/webhooks/push.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,54 @@
11
package webhooks
22

33
import (
4+
"github.com/postgres-ci/app-server/src/app/models/webhooks/common"
5+
"github.com/postgres-ci/app-server/src/env"
46
"github.com/postgres-ci/hooks/git"
7+
8+
"database/sql/driver"
9+
"encoding/json"
10+
"time"
511
)
612

13+
type commit struct {
14+
SHA string `json:"commit_sha"`
15+
Message string `json:"commit_message"`
16+
CommittedAt time.Time `json:"committed_at"`
17+
CommitterName string `json:"committer_name"`
18+
CommitterEmail string `json:"committer_email"`
19+
AuthorName string `json:"author_name"`
20+
AuthorEmail string `json:"author_email"`
21+
}
22+
23+
type commits []commit
24+
25+
func (c commits) Value() (driver.Value, error) {
26+
return json.Marshal(c)
27+
}
28+
729
func Push(token string, push git.Push) error {
830

31+
commits := make(commits, 0, len(push.Commits))
32+
33+
for _, c := range push.Commits {
34+
35+
commits = append(commits, commit{
36+
SHA: c.ID,
37+
Message: c.Message,
38+
CommittedAt: c.CommittedAt,
39+
CommitterName: c.Committer.Name,
40+
CommitterEmail: c.Committer.Email,
41+
AuthorName: c.Author.Name,
42+
AuthorEmail: c.Author.Email,
43+
})
44+
}
45+
46+
_, err := env.Connect().Exec("SELECT hook.push($1, $2, $3)", token, common.RefToBranch(push.Ref), commits)
47+
48+
if err != nil {
49+
50+
return err
51+
}
52+
953
return nil
1054
}

0 commit comments

Comments
 (0)