diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-08-21 13:16:22 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-21 13:16:22 +0800 |
commit | 09ca3912301eb77e4f30c80753fbe0f0735dc5f2 (patch) | |
tree | 8cb2f67c86e290d7d14331886523783b8c378f95 /models/action.go | |
parent | 5f7fccaf55b23e207e5874e620a1072e68266d21 (diff) | |
download | gitea-09ca3912301eb77e4f30c80753fbe0f0735dc5f2.tar.gz gitea-09ca3912301eb77e4f30c80753fbe0f0735dc5f2.zip |
Add file status on API (#7671)
* add file status on API
* fix tests
* fix tests
* fix tests
Diffstat (limited to 'models/action.go')
-rw-r--r-- | models/action.go | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/models/action.go b/models/action.go index 4b0a55921b..9bf2905c99 100644 --- a/models/action.go +++ b/models/action.go @@ -17,6 +17,7 @@ import ( "unicode" "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" @@ -385,7 +386,7 @@ func NewPushCommits() *PushCommits { // ToAPIPayloadCommits converts a PushCommits object to // api.PayloadCommit format. -func (pc *PushCommits) ToAPIPayloadCommits(repoLink string) []*api.PayloadCommit { +func (pc *PushCommits) ToAPIPayloadCommits(repoPath, repoLink string) ([]*api.PayloadCommit, error) { commits := make([]*api.PayloadCommit, len(pc.Commits)) if pc.emailUsers == nil { @@ -417,6 +418,12 @@ func (pc *PushCommits) ToAPIPayloadCommits(repoLink string) []*api.PayloadCommit } else { committerUsername = committer.Name } + + fileStatus, err := git.GetCommitFileStatus(repoPath, commit.Sha1) + if err != nil { + return nil, fmt.Errorf("FileStatus [commit_sha1: %s]: %v", commit.Sha1, err) + } + commits[i] = &api.PayloadCommit{ ID: commit.Sha1, Message: commit.Message, @@ -431,10 +438,13 @@ func (pc *PushCommits) ToAPIPayloadCommits(repoLink string) []*api.PayloadCommit Email: commit.CommitterEmail, UserName: committerUsername, }, + Added: fileStatus.Added, + Removed: fileStatus.Removed, + Modified: fileStatus.Modified, Timestamp: commit.Timestamp, } } - return commits + return commits, nil } // AvatarLink tries to match user in database with e-mail @@ -738,7 +748,10 @@ func MirrorSyncPushAction(repo *Repository, opts MirrorSyncPushActionOptions) er opts.Commits.Commits = opts.Commits.Commits[:setting.UI.FeedMaxCommitNum] } - apiCommits := opts.Commits.ToAPIPayloadCommits(repo.HTMLURL()) + apiCommits, err := opts.Commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL()) + if err != nil { + return err + } opts.Commits.CompareURL = repo.ComposeCompareURL(opts.OldCommitID, opts.NewCommitID) apiPusher := repo.MustOwner().APIFormat() |