* Add Timestamp to Tag list API * Add unit test for ToCommitMeta * Rename timestamp to created * Reformat files
This commit is contained in:
parent
48703c3c68
commit
67a5573310
@ -28,8 +28,9 @@ func ToCommitUser(sig *git.Signature) *api.CommitUser {
|
||||
// ToCommitMeta convert a git.Tag to an api.CommitMeta
|
||||
func ToCommitMeta(repo *models.Repository, tag *git.Tag) *api.CommitMeta {
|
||||
return &api.CommitMeta{
|
||||
SHA: tag.Object.String(),
|
||||
URL: util.URLJoin(repo.APIURL(), "git/commits", tag.ID.String()),
|
||||
SHA: tag.Object.String(),
|
||||
URL: util.URLJoin(repo.APIURL(), "git/commits", tag.ID.String()),
|
||||
Created: tag.Tagger.When,
|
||||
}
|
||||
}
|
||||
|
||||
|
42
modules/convert/git_commit_test.go
Normal file
42
modules/convert/git_commit_test.go
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package convert
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestToCommitMeta(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
headRepo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
||||
sha1, _ := git.NewIDFromString("0000000000000000000000000000000000000000")
|
||||
signature := &object.Signature{Name: "Test Signature", Email: "test@email.com", When: time.Unix(0, 0)}
|
||||
tag := &git.Tag{
|
||||
Name: "Test Tag",
|
||||
ID: sha1,
|
||||
Object: sha1,
|
||||
Type: "Test Type",
|
||||
Tagger: signature,
|
||||
Message: "Test Message",
|
||||
}
|
||||
|
||||
commitMeta := ToCommitMeta(headRepo, tag)
|
||||
|
||||
assert.NotNil(t, commitMeta)
|
||||
assert.EqualValues(t, &api.CommitMeta{
|
||||
SHA: "0000000000000000000000000000000000000000",
|
||||
URL: util.URLJoin(headRepo.APIURL(), "git/commits", "0000000000000000000000000000000000000000"),
|
||||
Created: time.Unix(0, 0),
|
||||
}, commitMeta)
|
||||
}
|
@ -20,6 +20,8 @@ type Identity struct {
|
||||
type CommitMeta struct {
|
||||
URL string `json:"url"`
|
||||
SHA string `json:"sha"`
|
||||
// swagger:strfmt date-time
|
||||
Created time.Time `json:"created"`
|
||||
}
|
||||
|
||||
// CommitUser contains information of a user in the context of a commit.
|
||||
|
@ -11297,6 +11297,11 @@
|
||||
"committer": {
|
||||
"$ref": "#/definitions/User"
|
||||
},
|
||||
"created": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
"x-go-name": "Created"
|
||||
},
|
||||
"html_url": {
|
||||
"type": "string",
|
||||
"x-go-name": "HTMLURL"
|
||||
@ -11340,6 +11345,11 @@
|
||||
"type": "object",
|
||||
"title": "CommitMeta contains meta information of a commit in terms of API.",
|
||||
"properties": {
|
||||
"created": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
"x-go-name": "Created"
|
||||
},
|
||||
"sha": {
|
||||
"type": "string",
|
||||
"x-go-name": "SHA"
|
||||
@ -13065,6 +13075,11 @@
|
||||
"committer": {
|
||||
"$ref": "#/definitions/CommitUser"
|
||||
},
|
||||
"created": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
"x-go-name": "Created"
|
||||
},
|
||||
"html_url": {
|
||||
"type": "string",
|
||||
"x-go-name": "HTMLURL"
|
||||
|
Loading…
Reference in New Issue
Block a user