|
1 | 1 | package webhooks
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "github.com/postgres-ci/app-server/src/app/models/webhooks/common" |
| 5 | + "github.com/postgres-ci/app-server/src/env" |
4 | 6 | "github.com/postgres-ci/hooks/git"
|
| 7 | + |
| 8 | + "database/sql/driver" |
| 9 | + "encoding/json" |
| 10 | + "time" |
5 | 11 | )
|
6 | 12 |
|
| 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 | + |
7 | 29 | func Push(token string, push git.Push) error {
|
8 | 30 |
|
| 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 | + |
9 | 53 | return nil
|
10 | 54 | }
|
0 commit comments