qlog.Fatal("Unknown command")
}
- models.SetRepoEnvs(user.Id, user.Name, repoName)
+ models.SetRepoEnvs(user.Id, user.Name, repoName, repoUserName)
gitcmd := exec.Command(verb, repoPath)
gitcmd.Dir = base.RepoRootPath
//updateEnv(args[0], args[1], args[2])
userName := os.Getenv("userName")
- userId := os.Getenv("userId")
- iUserId, _ := strconv.ParseInt(userId, 10, 64)
+ userId, _ := strconv.ParseInt(os.Getenv("userId"), 10, 64)
//repoId := os.Getenv("repoId")
+ repoUserName := os.Getenv("repoUserName")
repoName := os.Getenv("repoName")
- models.Update(args[0], args[1], args[2], userName, repoName, iUserId)
+ models.Update(args[0], args[1], args[2], userName, repoUserName, repoName, userId)
}
// Test that go1.2 tag above is included in builds. main.go refers to this definition.
const go12tag = true
-const APP_VER = "0.3.2.0502 Alpha"
+const APP_VER = "0.3.2.0503 Alpha"
func init() {
base.AppVer = APP_VER
"time"
"github.com/gogits/git"
+ qlog "github.com/qiniu/log"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/log"
// Action represents user operation type and other information to repository.,
// it implemented interface base.Actioner so that can be used in template render.
type Action struct {
- Id int64
- UserId int64 // Receiver user id.
- OpType int // Operations: CREATE DELETE STAR ...
- ActUserId int64 // Action user id.
- ActUserName string // Action user name.
- ActEmail string
- RepoId int64
- RepoName string
- RefName string
- IsPrivate bool `xorm:"NOT NULL DEFAULT false"`
- Content string `xorm:"TEXT"`
- Created time.Time `xorm:"created"`
+ Id int64
+ UserId int64 // Receiver user id.
+ OpType int // Operations: CREATE DELETE STAR ...
+ ActUserId int64 // Action user id.
+ ActUserName string // Action user name.
+ ActEmail string
+ RepoId int64
+ RepoUserName string
+ RepoName string
+ RefName string
+ IsPrivate bool `xorm:"NOT NULL DEFAULT false"`
+ Content string `xorm:"TEXT"`
+ Created time.Time `xorm:"created"`
}
func (a Action) GetOpType() int {
}
// CommitRepoAction adds new action for committing repository.
-func CommitRepoAction(userId int64, userName, actEmail string,
- repoId int64, repoName string, refName string, commit *base.PushCommits) error {
+func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
+ repoId int64, repoUserName, repoName string, refName string, commit *base.PushCommits) error {
// log.Trace("action.CommitRepoAction(start): %d/%s", userId, repoName)
opType := OP_COMMIT_REPO
bs, err := json.Marshal(commit)
if err != nil {
- log.Error("action.CommitRepoAction(json): %d/%s", userId, repoName)
+ qlog.Error("action.CommitRepoAction(json): %d/%s", repoUserId, repoName)
return err
}
// Change repository bare status and update last updated time.
- repo, err := GetRepositoryByName(userId, repoName)
+ repo, err := GetRepositoryByName(repoUserId, repoName)
if err != nil {
- log.Error("action.CommitRepoAction(GetRepositoryByName): %d/%s", userId, repoName)
+ qlog.Error("action.CommitRepoAction(GetRepositoryByName): %d/%s", repoUserId, repoName)
return err
}
repo.IsBare = false
if err = UpdateRepository(repo); err != nil {
- log.Error("action.CommitRepoAction(UpdateRepository): %d/%s", userId, repoName)
+ qlog.Error("action.CommitRepoAction(UpdateRepository): %d/%s", repoUserId, repoName)
return err
}
if err = NotifyWatchers(&Action{ActUserId: userId, ActUserName: userName, ActEmail: actEmail,
- OpType: opType, Content: string(bs), RepoId: repoId, RepoName: repoName, RefName: refName,
+ OpType: opType, Content: string(bs), RepoId: repoId, RepoUserName: repoUserName,
+ RepoName: repoName, RefName: refName,
IsPrivate: repo.IsPrivate}); err != nil {
- log.Error("action.CommitRepoAction(notify watchers): %d/%s", userId, repoName)
+ qlog.Error("action.CommitRepoAction(notify watchers): %d/%s", userId, repoName)
return err
}
- log.Trace("action.CommitRepoAction(end): %d/%s", userId, repoName)
+ qlog.Info("action.CommitRepoAction(end): %d/%s", repoUserId, repoName)
return nil
}
}
// SetRepoEnvs sets environment variables for command update.
-func SetRepoEnvs(userId int64, userName, repoName string) {
+func SetRepoEnvs(userId int64, userName, repoName, repoUserName string) {
os.Setenv("userId", base.ToStr(userId))
os.Setenv("userName", userName)
os.Setenv("repoName", repoName)
+ os.Setenv("repoUserName", repoUserName)
}
// InitRepository initializes README and .gitignore if needed.
return nil
}
- SetRepoEnvs(user.Id, user.Name, repo.Name)
+ SetRepoEnvs(user.Id, user.Name, repo.Name, user.Name)
// Apply changes and commit.
return initRepoCommit(tmpDir, user.NewGitSig())
"github.com/gogits/gogs/modules/base"
)
-func Update(refName, oldCommitId, newCommitId, userName, repoName string, userId int64) {
+func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName string, userId int64) {
isNew := strings.HasPrefix(oldCommitId, "0000000")
if isNew &&
strings.HasPrefix(newCommitId, "0000000") {
qlog.Fatal("old rev and new rev both 000000")
}
- f := RepoPath(userName, repoName)
+ f := RepoPath(repoUserName, repoName)
gitUpdate := exec.Command("git", "update-server-info")
gitUpdate.Dir = f
qlog.Fatalf("runUpdate.Commit repoId: %v", err)
}
- repos, err := GetRepositoryByName(userId, repoName)
+ ru, err := GetUserByName(repoUserName)
+ if err != nil {
+ qlog.Fatalf("runUpdate.GetUserByName: %v", err)
+ }
+
+ repos, err := GetRepositoryByName(ru.Id, repoName)
if err != nil {
qlog.Fatalf("runUpdate.GetRepositoryByName userId: %v", err)
}
}
//commits = append(commits, []string{lastCommit.Id().String(), lastCommit.Message()})
- if err = CommitRepoAction(userId, userName, actEmail,
- repos.Id, repoName, refName, &base.PushCommits{l.Len(), commits}); err != nil {
+ if err = CommitRepoAction(userId, ru.Id, userName, actEmail,
+ repos.Id, repoUserName, repoName, refName, &base.PushCommits{l.Len(), commits}); err != nil {
qlog.Fatalf("runUpdate.models.CommitRepoAction: %v", err)
}
}
// only public pull don't need auth
isPublicPull := !repo.IsPrivate && isPull
var askAuth = !isPublicPull || base.Service.RequireSignInView
-
var authUser *models.User
+ var authUsername, passwd string
// check access
if askAuth {
ctx.Handle(401, "no basic auth and digit auth", nil)
return
}
- authUsername, passwd, err := basicDecode(auths[1])
+ authUsername, passwd, err = basicDecode(auths[1])
if err != nil {
ctx.Handle(401, "no basic auth and digit auth", nil)
return
newCommitId := fields[1]
refName := fields[2]
- models.Update(refName, oldCommitId, newCommitId, username, reponame, authUser.Id)
+ models.Update(refName, oldCommitId, newCommitId, authUsername, username, reponame, authUser.Id)
}
}
}