Skip to content

Commit 67a5573

Browse files
authored
[#13004] Add Timestamp to Tag list API (#13026)
* Add Timestamp to Tag list API * Add unit test for ToCommitMeta * Rename timestamp to created * Reformat files
1 parent 48703c3 commit 67a5573

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

modules/convert/git_commit.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ func ToCommitUser(sig *git.Signature) *api.CommitUser {
2828
// ToCommitMeta convert a git.Tag to an api.CommitMeta
2929
func ToCommitMeta(repo *models.Repository, tag *git.Tag) *api.CommitMeta {
3030
return &api.CommitMeta{
31-
SHA: tag.Object.String(),
32-
URL: util.URLJoin(repo.APIURL(), "git/commits", tag.ID.String()),
31+
SHA: tag.Object.String(),
32+
URL: util.URLJoin(repo.APIURL(), "git/commits", tag.ID.String()),
33+
Created: tag.Tagger.When,
3334
}
3435
}
3536

modules/convert/git_commit_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2020 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package convert
6+
7+
import (
8+
"testing"
9+
"time"
10+
11+
"code.gitea.io/gitea/models"
12+
"code.gitea.io/gitea/modules/git"
13+
api "code.gitea.io/gitea/modules/structs"
14+
"code.gitea.io/gitea/modules/util"
15+
16+
"github.com/go-git/go-git/v5/plumbing/object"
17+
"github.com/stretchr/testify/assert"
18+
)
19+
20+
func TestToCommitMeta(t *testing.T) {
21+
assert.NoError(t, models.PrepareTestDatabase())
22+
headRepo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
23+
sha1, _ := git.NewIDFromString("0000000000000000000000000000000000000000")
24+
signature := &object.Signature{Name: "Test Signature", Email: "[email protected]", When: time.Unix(0, 0)}
25+
tag := &git.Tag{
26+
Name: "Test Tag",
27+
ID: sha1,
28+
Object: sha1,
29+
Type: "Test Type",
30+
Tagger: signature,
31+
Message: "Test Message",
32+
}
33+
34+
commitMeta := ToCommitMeta(headRepo, tag)
35+
36+
assert.NotNil(t, commitMeta)
37+
assert.EqualValues(t, &api.CommitMeta{
38+
SHA: "0000000000000000000000000000000000000000",
39+
URL: util.URLJoin(headRepo.APIURL(), "git/commits", "0000000000000000000000000000000000000000"),
40+
Created: time.Unix(0, 0),
41+
}, commitMeta)
42+
}

modules/structs/repo_commit.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ type Identity struct {
2020
type CommitMeta struct {
2121
URL string `json:"url"`
2222
SHA string `json:"sha"`
23+
// swagger:strfmt date-time
24+
Created time.Time `json:"created"`
2325
}
2426

2527
// CommitUser contains information of a user in the context of a commit.

templates/swagger/v1_json.tmpl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11297,6 +11297,11 @@
1129711297
"committer": {
1129811298
"$ref": "#/definitions/User"
1129911299
},
11300+
"created": {
11301+
"type": "string",
11302+
"format": "date-time",
11303+
"x-go-name": "Created"
11304+
},
1130011305
"html_url": {
1130111306
"type": "string",
1130211307
"x-go-name": "HTMLURL"
@@ -11340,6 +11345,11 @@
1134011345
"type": "object",
1134111346
"title": "CommitMeta contains meta information of a commit in terms of API.",
1134211347
"properties": {
11348+
"created": {
11349+
"type": "string",
11350+
"format": "date-time",
11351+
"x-go-name": "Created"
11352+
},
1134311353
"sha": {
1134411354
"type": "string",
1134511355
"x-go-name": "SHA"
@@ -13065,6 +13075,11 @@
1306513075
"committer": {
1306613076
"$ref": "#/definitions/CommitUser"
1306713077
},
13078+
"created": {
13079+
"type": "string",
13080+
"format": "date-time",
13081+
"x-go-name": "Created"
13082+
},
1306813083
"html_url": {
1306913084
"type": "string",
1307013085
"x-go-name": "HTMLURL"

0 commit comments

Comments
 (0)