mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
fix #864 with migration and update locale
This commit is contained in:
@@ -293,12 +293,12 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
|
||||
repoLink := fmt.Sprintf("%s%s/%s", setting.AppUrl, repoUserName, repoName)
|
||||
// if not the first commit, set the compareUrl
|
||||
if !strings.HasPrefix(oldCommitId, "0000000") {
|
||||
commit.CompareUrl = fmt.Sprintf("%s/compare/%s...%s", repoLink, oldCommitId, newCommitId)
|
||||
commit.CompareUrl = fmt.Sprintf("%s/%s/compare/%s...%s", repoUserName, repoName, oldCommitId, newCommitId)
|
||||
}
|
||||
|
||||
bs, err := json.Marshal(commit)
|
||||
if err != nil {
|
||||
return errors.New("action.CommitRepoAction(json): " + err.Error())
|
||||
return errors.New("json: " + err.Error())
|
||||
}
|
||||
|
||||
refName := git.RefEndName(refFullName)
|
||||
@@ -306,17 +306,17 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
|
||||
// Change repository bare status and update last updated time.
|
||||
repo, err := GetRepositoryByName(repoUserId, repoName)
|
||||
if err != nil {
|
||||
return errors.New("action.CommitRepoAction(GetRepositoryByName): " + err.Error())
|
||||
return errors.New("GetRepositoryByName: " + err.Error())
|
||||
}
|
||||
repo.IsBare = false
|
||||
if err = UpdateRepository(repo, false); err != nil {
|
||||
return errors.New("action.CommitRepoAction(UpdateRepository): " + err.Error())
|
||||
return errors.New("UpdateRepository: " + err.Error())
|
||||
}
|
||||
|
||||
err = updateIssuesCommit(userId, repoId, repoUserName, repoName, commit.Commits)
|
||||
|
||||
if err != nil {
|
||||
log.Debug("action.CommitRepoAction(updateIssuesCommit): ", err)
|
||||
log.Debug("updateIssuesCommit: ", err)
|
||||
}
|
||||
|
||||
if err = NotifyWatchers(&Action{
|
||||
@@ -331,18 +331,18 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
|
||||
RefName: refName,
|
||||
IsPrivate: repo.IsPrivate,
|
||||
}); err != nil {
|
||||
return errors.New("action.CommitRepoAction(NotifyWatchers): " + err.Error())
|
||||
return errors.New("NotifyWatchers: " + err.Error())
|
||||
|
||||
}
|
||||
|
||||
// New push event hook.
|
||||
if err := repo.GetOwner(); err != nil {
|
||||
return errors.New("action.CommitRepoAction(GetOwner): " + err.Error())
|
||||
return errors.New("GetOwner: " + err.Error())
|
||||
}
|
||||
|
||||
ws, err := GetActiveWebhooksByRepoId(repoId)
|
||||
if err != nil {
|
||||
return errors.New("action.CommitRepoAction(GetActiveWebhooksByRepoId): " + err.Error())
|
||||
return errors.New("GetActiveWebhooksByRepoId: " + err.Error())
|
||||
}
|
||||
|
||||
// check if repo belongs to org and append additional webhooks
|
||||
@@ -350,7 +350,7 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
|
||||
// get hooks for org
|
||||
orgws, err := GetActiveWebhooksByOrgId(repo.OwnerId)
|
||||
if err != nil {
|
||||
return errors.New("action.CommitRepoAction(GetActiveWebhooksByOrgId): " + err.Error())
|
||||
return errors.New("GetActiveWebhooksByOrgId: " + err.Error())
|
||||
}
|
||||
ws = append(ws, orgws...)
|
||||
}
|
||||
@@ -408,7 +408,7 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
|
||||
},
|
||||
Before: oldCommitId,
|
||||
After: newCommitId,
|
||||
CompareUrl: commit.CompareUrl,
|
||||
CompareUrl: setting.AppUrl + commit.CompareUrl,
|
||||
}
|
||||
|
||||
for _, w := range ws {
|
||||
|
@@ -5,6 +5,7 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -51,11 +52,12 @@ type Version struct {
|
||||
// If you want to "retire" a migration, remove it from the top of the list and
|
||||
// update _MIN_VER_DB accordingly
|
||||
var migrations = []Migration{
|
||||
NewMigration("generate collaboration from access", accessToCollaboration), // V0 -> V1:v0.5.13
|
||||
NewMigration("make authorize 4 if team is owners", ownerTeamUpdate), // V1 -> V2:v0.5.13
|
||||
NewMigration("refactor access table to use id's", accessRefactor), // V2 -> V3:v0.5.13
|
||||
NewMigration("generate team-repo from team", teamToTeamRepo), // V3 -> V4:v0.5.13
|
||||
NewMigration("fix locale file load panic", fixLocaleFileLoadPanic), // V4 -> V5:v0.6.0
|
||||
NewMigration("generate collaboration from access", accessToCollaboration), // V0 -> V1:v0.5.13
|
||||
NewMigration("make authorize 4 if team is owners", ownerTeamUpdate), // V1 -> V2:v0.5.13
|
||||
NewMigration("refactor access table to use id's", accessRefactor), // V2 -> V3:v0.5.13
|
||||
NewMigration("generate team-repo from team", teamToTeamRepo), // V3 -> V4:v0.5.13
|
||||
NewMigration("fix locale file load panic", fixLocaleFileLoadPanic), // V4 -> V5:v0.6.0
|
||||
NewMigration("trim action compare URL prefix", trimCommitActionAppUrlPrefix), // V5 -> V6:v0.6.3 // V4 -> V5:v0.6.0
|
||||
}
|
||||
|
||||
// Migrate database to current version
|
||||
@@ -389,3 +391,65 @@ func fixLocaleFileLoadPanic(_ *xorm.Engine) error {
|
||||
setting.Langs = strings.Split(strings.Replace(strings.Join(setting.Langs, ","), "fr-CA", "fr-FR", 1), ",")
|
||||
return nil
|
||||
}
|
||||
|
||||
func trimCommitActionAppUrlPrefix(x *xorm.Engine) error {
|
||||
type PushCommit struct {
|
||||
Sha1 string
|
||||
Message string
|
||||
AuthorEmail string
|
||||
AuthorName string
|
||||
}
|
||||
|
||||
type PushCommits struct {
|
||||
Len int
|
||||
Commits []*PushCommit
|
||||
CompareUrl string
|
||||
}
|
||||
|
||||
type Action struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Content string `xorm:"TEXT"`
|
||||
}
|
||||
|
||||
results, err := x.Query("SELECT `id`,`content` FROM `action` WHERE `op_type`=?", 5)
|
||||
if err != nil {
|
||||
return fmt.Errorf("select commit actions: %v", err)
|
||||
}
|
||||
|
||||
sess := x.NewSession()
|
||||
defer sessionRelease(sess)
|
||||
if err = sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var pushCommits *PushCommits
|
||||
for _, action := range results {
|
||||
actID := com.StrTo(string(action["id"])).MustInt64()
|
||||
if actID == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
pushCommits = new(PushCommits)
|
||||
if err = json.Unmarshal(action["content"], pushCommits); err != nil {
|
||||
return fmt.Errorf("unmarshal action content[%s]: %v", actID, err)
|
||||
}
|
||||
|
||||
infos := strings.Split(pushCommits.CompareUrl, "/")
|
||||
if len(infos) <= 4 {
|
||||
continue
|
||||
}
|
||||
pushCommits.CompareUrl = strings.Join(infos[len(infos)-4:], "/")
|
||||
|
||||
p, err := json.Marshal(pushCommits)
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshal action content[%s]: %v", actID, err)
|
||||
}
|
||||
|
||||
if _, err = sess.Id(actID).Update(&Action{
|
||||
Content: string(p),
|
||||
}); err != nil {
|
||||
return fmt.Errorf("update action[%s]: %v", actID, err)
|
||||
}
|
||||
}
|
||||
return sess.Commit()
|
||||
}
|
||||
|
Reference in New Issue
Block a user