From 083c3ee659c6c5542687f3bafae68cbc24dbc90f Mon Sep 17 00:00:00 2001 From: Joe Chen Date: Sat, 25 Jun 2022 18:07:39 +0800 Subject: db: refactor "action" table to use GORM (#7054) Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com> --- internal/db/update.go | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'internal/db/update.go') 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 } -- cgit v1.2.3