mirror of https://github.com/go-gitea/gitea.git
Add extra user information when migrating release (#8331)
* add extra user information when migrating release * add migrations * fix tests
This commit is contained in:
parent
fb7c23f911
commit
bd41a04a56
|
@ -250,6 +250,8 @@ var migrations = []Migration{
|
||||||
NewMigration("delete orphaned attachments", deleteOrphanedAttachments),
|
NewMigration("delete orphaned attachments", deleteOrphanedAttachments),
|
||||||
// v97 -> v98
|
// v97 -> v98
|
||||||
NewMigration("add repo_admin_change_team_access to user", addRepoAdminChangeTeamAccessColumnForUser),
|
NewMigration("add repo_admin_change_team_access to user", addRepoAdminChangeTeamAccessColumnForUser),
|
||||||
|
// v98 -> v99
|
||||||
|
NewMigration("add original author name and id on migrated release", addOriginalAuthorOnMigratedReleases),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate database to current version
|
// Migrate database to current version
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
// Copyright 2019 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 migrations
|
||||||
|
|
||||||
|
import "github.com/go-xorm/xorm"
|
||||||
|
|
||||||
|
func addOriginalAuthorOnMigratedReleases(x *xorm.Engine) error {
|
||||||
|
type Release struct {
|
||||||
|
ID int64
|
||||||
|
OriginalAuthor string
|
||||||
|
OriginalAuthorID int64 `xorm:"index"`
|
||||||
|
}
|
||||||
|
|
||||||
|
return x.Sync2(new(Release))
|
||||||
|
}
|
|
@ -26,6 +26,8 @@ type Release struct {
|
||||||
PublisherID int64 `xorm:"INDEX"`
|
PublisherID int64 `xorm:"INDEX"`
|
||||||
Publisher *User `xorm:"-"`
|
Publisher *User `xorm:"-"`
|
||||||
TagName string `xorm:"INDEX UNIQUE(n)"`
|
TagName string `xorm:"INDEX UNIQUE(n)"`
|
||||||
|
OriginalAuthor string
|
||||||
|
OriginalAuthorID int64 `xorm:"index"`
|
||||||
LowerTagName string
|
LowerTagName string
|
||||||
Target string
|
Target string
|
||||||
Title string
|
Title string
|
||||||
|
|
|
@ -25,6 +25,9 @@ type Release struct {
|
||||||
Body string
|
Body string
|
||||||
Draft bool
|
Draft bool
|
||||||
Prerelease bool
|
Prerelease bool
|
||||||
|
PublisherID int64
|
||||||
|
PublisherName string
|
||||||
|
PublisherEmail string
|
||||||
Assets []ReleaseAsset
|
Assets []ReleaseAsset
|
||||||
Created time.Time
|
Created time.Time
|
||||||
Published time.Time
|
Published time.Time
|
||||||
|
|
|
@ -175,18 +175,20 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
|
||||||
var rels = make([]*models.Release, 0, len(releases))
|
var rels = make([]*models.Release, 0, len(releases))
|
||||||
for _, release := range releases {
|
for _, release := range releases {
|
||||||
var rel = models.Release{
|
var rel = models.Release{
|
||||||
RepoID: g.repo.ID,
|
RepoID: g.repo.ID,
|
||||||
PublisherID: g.doer.ID,
|
PublisherID: g.doer.ID,
|
||||||
TagName: release.TagName,
|
TagName: release.TagName,
|
||||||
LowerTagName: strings.ToLower(release.TagName),
|
LowerTagName: strings.ToLower(release.TagName),
|
||||||
Target: release.TargetCommitish,
|
Target: release.TargetCommitish,
|
||||||
Title: release.Name,
|
Title: release.Name,
|
||||||
Sha1: release.TargetCommitish,
|
Sha1: release.TargetCommitish,
|
||||||
Note: release.Body,
|
Note: release.Body,
|
||||||
IsDraft: release.Draft,
|
IsDraft: release.Draft,
|
||||||
IsPrerelease: release.Prerelease,
|
IsPrerelease: release.Prerelease,
|
||||||
IsTag: false,
|
IsTag: false,
|
||||||
CreatedUnix: timeutil.TimeStamp(release.Created.Unix()),
|
CreatedUnix: timeutil.TimeStamp(release.Created.Unix()),
|
||||||
|
OriginalAuthor: release.PublisherName,
|
||||||
|
OriginalAuthorID: release.PublisherID,
|
||||||
}
|
}
|
||||||
|
|
||||||
// calc NumCommits
|
// calc NumCommits
|
||||||
|
|
|
@ -214,6 +214,11 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
|
||||||
name = *rel.Name
|
name = *rel.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var email string
|
||||||
|
if rel.Author.Email != nil {
|
||||||
|
email = *rel.Author.Email
|
||||||
|
}
|
||||||
|
|
||||||
r := &base.Release{
|
r := &base.Release{
|
||||||
TagName: *rel.TagName,
|
TagName: *rel.TagName,
|
||||||
TargetCommitish: *rel.TargetCommitish,
|
TargetCommitish: *rel.TargetCommitish,
|
||||||
|
@ -222,6 +227,9 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
|
||||||
Draft: *rel.Draft,
|
Draft: *rel.Draft,
|
||||||
Prerelease: *rel.Prerelease,
|
Prerelease: *rel.Prerelease,
|
||||||
Created: rel.CreatedAt.Time,
|
Created: rel.CreatedAt.Time,
|
||||||
|
PublisherID: *rel.Author.ID,
|
||||||
|
PublisherName: *rel.Author.Login,
|
||||||
|
PublisherEmail: email,
|
||||||
Published: rel.PublishedAt.Time,
|
Published: rel.PublishedAt.Time,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,6 +167,8 @@ func TestGitHubDownloadRepo(t *testing.T) {
|
||||||
Body: "Forked source from Gogs into Gitea\n",
|
Body: "Forked source from Gogs into Gitea\n",
|
||||||
Created: time.Date(2016, 10, 17, 02, 17, 59, 0, time.UTC),
|
Created: time.Date(2016, 10, 17, 02, 17, 59, 0, time.UTC),
|
||||||
Published: time.Date(2016, 11, 17, 15, 37, 0, 0, time.UTC),
|
Published: time.Date(2016, 11, 17, 15, 37, 0, 0, time.UTC),
|
||||||
|
PublisherID: 4726179,
|
||||||
|
PublisherName: "bkcsoft",
|
||||||
},
|
},
|
||||||
}, releases[len(releases)-1:])
|
}, releases[len(releases)-1:])
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,15 @@
|
||||||
</h3>
|
</h3>
|
||||||
<p class="text grey">
|
<p class="text grey">
|
||||||
<span class="author">
|
<span class="author">
|
||||||
|
{{if .OriginalAuthor}}
|
||||||
|
<i class="fa fa-github" aria-hidden="true"></i>
|
||||||
|
{{.OriginalAuthor}}
|
||||||
|
{{else if .Publisher}}
|
||||||
<img class="img-10" src="{{.Publisher.RelAvatarLink}}">
|
<img class="img-10" src="{{.Publisher.RelAvatarLink}}">
|
||||||
<a href="{{AppSubUrl}}/{{.Publisher.Name}}">{{.Publisher.Name}}</a>
|
<a href="{{AppSubUrl}}/{{.Publisher.Name}}">{{.Publisher.Name}}</a>
|
||||||
|
{{else}}
|
||||||
|
Ghost
|
||||||
|
{{end}}
|
||||||
</span>
|
</span>
|
||||||
{{if .CreatedUnix}}<span class="time">{{TimeSinceUnix .CreatedUnix $.Lang}}</span>{{end}}
|
{{if .CreatedUnix}}<span class="time">{{TimeSinceUnix .CreatedUnix $.Lang}}</span>{{end}}
|
||||||
<span class="ahead">{{$.i18n.Tr "repo.release.ahead" .NumCommitsBehind .Target | Str2html}}</span>
|
<span class="ahead">{{$.i18n.Tr "repo.release.ahead" .NumCommitsBehind .Target | Str2html}}</span>
|
||||||
|
|
Loading…
Reference in New Issue