diff options
author | Joe Chen <jc@unknwon.io> | 2022-06-25 18:07:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-25 18:07:39 +0800 |
commit | 083c3ee659c6c5542687f3bafae68cbc24dbc90f (patch) | |
tree | 0103bf3b5c5ebfccd368a7cb6a425a521fd669d9 /internal/db/update.go | |
parent | 9df4e3ae3c555a86f691f0d78a43834842e77d8b (diff) |
db: refactor "action" table to use GORM (#7054)
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
Diffstat (limited to 'internal/db/update.go')
-rw-r--r-- | internal/db/update.go | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/internal/db/update.go b/internal/db/update.go index 94fc4ee3..ec538b0b 100644 --- a/internal/db/update.go +++ b/internal/db/update.go @@ -5,11 +5,13 @@ package db import ( + "context" "fmt" "os/exec" "strings" "github.com/gogs/git-module" + "github.com/pkg/errors" ) // CommitToPushCommit transforms a git.Commit to PushCommit type. @@ -50,6 +52,8 @@ type PushUpdateOptions struct { // PushUpdate must be called for any push actions in order to // generates necessary push action history feeds. func PushUpdate(opts PushUpdateOptions) (err error) { + ctx := context.TODO() + isNewRef := strings.HasPrefix(opts.OldCommitID, git.EmptyID) isDelRef := strings.HasPrefix(opts.NewCommitID, git.EmptyID) if isNewRef && isDelRef { @@ -85,16 +89,17 @@ func PushUpdate(opts PushUpdateOptions) (err error) { // Push tags if strings.HasPrefix(opts.FullRefspec, git.RefsTags) { - if err := CommitRepoAction(CommitRepoActionOptions{ - PusherName: opts.PusherName, - RepoOwnerID: owner.ID, - RepoName: repo.Name, - RefFullName: opts.FullRefspec, - OldCommitID: opts.OldCommitID, - NewCommitID: opts.NewCommitID, - Commits: &PushCommits{}, - }); err != nil { - return fmt.Errorf("CommitRepoAction.(tag): %v", err) + err := Actions.PushTag(ctx, + PushTagOptions{ + Owner: owner, + Repo: repo, + PusherName: opts.PusherName, + RefFullName: opts.FullRefspec, + NewCommitID: opts.NewCommitID, + }, + ) + if err != nil { + return errors.Wrap(err, "create action for push tag") } return nil } @@ -122,16 +127,19 @@ func PushUpdate(opts PushUpdateOptions) (err error) { } } - if err := CommitRepoAction(CommitRepoActionOptions{ - PusherName: opts.PusherName, - RepoOwnerID: owner.ID, - RepoName: repo.Name, - RefFullName: opts.FullRefspec, - OldCommitID: opts.OldCommitID, - NewCommitID: opts.NewCommitID, - Commits: CommitsToPushCommits(commits), - }); err != nil { - return fmt.Errorf("CommitRepoAction.(branch): %v", err) + err = Actions.CommitRepo(ctx, + CommitRepoOptions{ + Owner: owner, + Repo: repo, + PusherName: opts.PusherName, + RefFullName: opts.FullRefspec, + OldCommitID: opts.OldCommitID, + NewCommitID: opts.NewCommitID, + Commits: CommitsToPushCommits(commits), + }, + ) + if err != nil { + return errors.Wrap(err, "create action for commit push") } return nil } |