aboutsummaryrefslogtreecommitdiffstats
path: root/models/repo.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-08-14 03:32:24 -0700
committerUnknwon <u@gogs.io>2016-08-14 03:32:24 -0700
commit3f7f4852efaaa56a0dada832dc652a1fc8869ae7 (patch)
treee3bb1769b2967dea560b2400abf830dc6cf70067 /models/repo.go
parent0f33b04c876593e592887450302774654fef2787 (diff)
downloadgitea-3f7f4852efaaa56a0dada832dc652a1fc8869ae7.tar.gz
gitea-3f7f4852efaaa56a0dada832dc652a1fc8869ae7.zip
#2246 fully support of webhooks for pull request
Diffstat (limited to 'models/repo.go')
-rw-r--r--models/repo.go54
1 files changed, 42 insertions, 12 deletions
diff --git a/models/repo.go b/models/repo.go
index afa8d23b2b..ef8cd34375 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -216,6 +216,48 @@ func (repo *Repository) AfterSet(colName string, _ xorm.Cell) {
}
}
+// MustOwner always returns a valid *User object to avoid
+// conceptually impossible error handling.
+// It creates a fake object that contains error deftail
+// when error occurs.
+func (repo *Repository) MustOwner() *User {
+ return repo.mustOwner(x)
+}
+
+func (repo *Repository) FullName() string {
+ return repo.MustOwner().Name + "/" + repo.Name
+}
+
+func (repo *Repository) FullLink() string {
+ return setting.AppUrl + repo.FullName()
+}
+
+// Arguments that are allowed to be nil: permission
+func (repo *Repository) APIFormat(permission *api.Permission) *api.Repository {
+ cloneLink := repo.CloneLink()
+ return &api.Repository{
+ ID: repo.ID,
+ Owner: repo.Owner.APIFormat(),
+ Name: repo.Name,
+ FullName: repo.FullName(),
+ Description: repo.Description,
+ Private: repo.IsPrivate,
+ Fork: repo.IsFork,
+ HTMLURL: repo.FullLink(),
+ SSHURL: cloneLink.SSH,
+ CloneURL: cloneLink.HTTPS,
+ Website: repo.Website,
+ Stars: repo.NumStars,
+ Forks: repo.NumForks,
+ Watchers: repo.NumWatches,
+ OpenIssues: repo.NumOpenIssues,
+ DefaultBranch: repo.DefaultBranch,
+ Created: repo.Created,
+ Updated: repo.Updated,
+ Permissions: permission,
+ }
+}
+
func (repo *Repository) getOwner(e Engine) (err error) {
if repo.Owner != nil {
return nil
@@ -240,14 +282,6 @@ func (repo *Repository) mustOwner(e Engine) *User {
return repo.Owner
}
-// MustOwner always returns a valid *User object to avoid
-// conceptually impossible error handling.
-// It creates a fake object that contains error deftail
-// when error occurs.
-func (repo *Repository) MustOwner() *User {
- return repo.mustOwner(x)
-}
-
// ComposeMetas composes a map of metas for rendering external issue tracker URL.
func (repo *Repository) ComposeMetas() map[string]string {
if !repo.EnableExternalTracker {
@@ -357,10 +391,6 @@ func (repo *Repository) ComposeCompareURL(oldCommitID, newCommitID string) strin
return fmt.Sprintf("%s/%s/compare/%s...%s", repo.MustOwner().Name, repo.Name, oldCommitID, newCommitID)
}
-func (repo *Repository) FullLink() string {
- return setting.AppUrl + repo.MustOwner().Name + "/" + repo.Name
-}
-
func (repo *Repository) HasAccess(u *User) bool {
has, _ := HasAccess(u, repo, ACCESS_MODE_READ)
return has