diff options
author | Unknwon <u@gogs.io> | 2015-10-24 03:36:47 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-10-24 03:36:47 -0400 |
commit | 0fbb8c8826771e92e890fb1c72b356d3e62c7b01 (patch) | |
tree | 2695707e4789a6611fa35393b06631848657469a /models/repo.go | |
parent | e0aab4a7f6c1f1b5cc7fa40e2c09623b635bc4a6 (diff) | |
download | gitea-0fbb8c8826771e92e890fb1c72b356d3e62c7b01.tar.gz gitea-0fbb8c8826771e92e890fb1c72b356d3e62c7b01.zip |
New push to head repo of head branch: regenerate patch and retest apply
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/models/repo.go b/models/repo.go index ae1e9b7497..7d242df22f 100644 --- a/models/repo.go +++ b/models/repo.go @@ -183,9 +183,11 @@ func (repo *Repository) AfterSet(colName string, _ xorm.Cell) { } func (repo *Repository) getOwner(e Engine) (err error) { - if repo.Owner == nil { - repo.Owner, err = getUserByID(e, repo.OwnerID) + if repo.Owner != nil { + return nil } + + repo.Owner, err = getUserByID(e, repo.OwnerID) return err } @@ -326,6 +328,30 @@ func (repo *Repository) UpdateLocalCopy() error { return nil } +// PatchPath returns corresponding patch file path of repository by given issue ID. +func (repo *Repository) PatchPath(index int64) (string, error) { + if err := repo.GetOwner(); err != nil { + return "", err + } + + return filepath.Join(RepoPath(repo.Owner.Name, repo.Name), "pulls", com.ToStr(index)+".patch"), nil +} + +// SavePatch saves patch data to corresponding location by given issue ID. +func (repo *Repository) SavePatch(index int64, patch []byte) error { + patchPath, err := repo.PatchPath(index) + if err != nil { + return fmt.Errorf("PatchPath: %v", err) + } + + os.MkdirAll(path.Dir(patchPath), os.ModePerm) + if err = ioutil.WriteFile(patchPath, patch, 0644); err != nil { + return fmt.Errorf("WriteFile: %v", err) + } + + return nil +} + func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) { has, err := e.Get(&Repository{ OwnerID: u.Id, |