Browse Source

Replace convert.To with APIFormat calls

Unknwon 3 years ago
parent
commit
dccb0c15b9

+ 2 - 2
.gopmfile

@@ -18,8 +18,8 @@ github.com/go-xorm/core = commit:5bf745d
18 18
 github.com/go-xorm/xorm = commit:c6c7056
19 19
 github.com/gogits/chardet = commit:2404f77
20 20
 github.com/gogits/cron = commit:7f3990a
21
-github.com/gogits/git-module = commit:efc90b5
22
-github.com/gogits/go-gogs-client = commit:87e4334
21
+github.com/gogits/git-module = commit:313ce90
22
+github.com/gogits/go-gogs-client = commit:e363d3f
23 23
 github.com/issue9/identicon = commit:d36b545
24 24
 github.com/jaytaylor/html2text = commit:52d9b78
25 25
 github.com/kardianos/minwinsvc = commit:cad6b2b

+ 1 - 1
README.md

@@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
3 3
 
4 4
 ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
5 5
 
6
-##### Current tip version: 0.9.76 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
6
+##### Current tip version: 0.9.77 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
7 7
 
8 8
 | Web | UI  | Preview  |
9 9
 |:-------------:|:-------:|:-------:|

+ 2 - 1
cmd/serve.go

@@ -15,6 +15,7 @@ import (
15 15
 
16 16
 	"github.com/Unknwon/com"
17 17
 	"github.com/codegangsta/cli"
18
+	git "github.com/gogits/git-module"
18 19
 	gouuid "github.com/satori/go.uuid"
19 20
 
20 21
 	"github.com/gogits/gogs/models"
@@ -113,7 +114,7 @@ func handleUpdateTask(uuid string, user, repoUser *models.User, reponame string,
113 114
 
114 115
 	// Ask for running deliver hook and test pull request tasks.
115 116
 	reqURL := setting.LocalURL + repoUser.Name + "/" + reponame + "/tasks/trigger?branch=" +
116
-		strings.TrimPrefix(task.RefName, "refs/heads/") + "&secret=" + base.EncodeMD5(repoUser.Salt) + "&pusher=" + com.ToStr(user.ID)
117
+		strings.TrimPrefix(task.RefName, git.BRANCH_PREFIX) + "&secret=" + base.EncodeMD5(repoUser.Salt) + "&pusher=" + com.ToStr(user.ID)
117 118
 	log.GitLogger.Trace("Trigger task: %s", reqURL)
118 119
 
119 120
 	resp, err := httplib.Head(reqURL).SetTLSClientConfig(&tls.Config{

+ 1 - 1
cmd/web.go

@@ -89,7 +89,7 @@ func checkVersion() {
89 89
 		{"gopkg.in/ini.v1", ini.Version, "1.8.4"},
90 90
 		{"gopkg.in/macaron.v1", macaron.Version, "1.1.7"},
91 91
 		{"github.com/gogits/git-module", git.Version, "0.3.5"},
92
-		{"github.com/gogits/go-gogs-client", gogs.Version, "0.10.4"},
92
+		{"github.com/gogits/go-gogs-client", gogs.Version, "0.12.0"},
93 93
 	}
94 94
 	for _, c := range checkers {
95 95
 		if !version.Compare(c.Version(), c.Expected, ">=") {

+ 2 - 2
glide.lock

@@ -41,9 +41,9 @@ imports:
41 41
 - name: github.com/gogits/cron
42 42
   version: 7f3990acf1833faa5ebd0e86f0a4c72a4b5eba3c
43 43
 - name: github.com/gogits/git-module
44
-  version: efc90b5ea1f7b7e404673dcc19674b2a6856e0d3
44
+  version: 313ce907cc5a5801126c7dfa3a74d21cc3104329
45 45
 - name: github.com/gogits/go-gogs-client
46
-  version: 87e433464c1f5e98e7208123c15b78119776fb83
46
+  version: e363d3ff8f70d0fe813324eedf228684af41c29c
47 47
 - name: github.com/issue9/identicon
48 48
   version: d36b54562f4cf70c83653e13dc95c220c79ef521
49 49
 - name: github.com/jaytaylor/html2text

+ 1 - 1
gogs.go

@@ -17,7 +17,7 @@ import (
17 17
 	"github.com/gogits/gogs/modules/setting"
18 18
 )
19 19
 
20
-const APP_VER = "0.9.76.0814"
20
+const APP_VER = "0.9.77.0814"
21 21
 
22 22
 func init() {
23 23
 	runtime.GOMAXPROCS(runtime.NumCPU())

+ 16 - 28
models/action.go

@@ -246,7 +246,7 @@ type PushCommit struct {
246 246
 type PushCommits struct {
247 247
 	Len        int
248 248
 	Commits    []*PushCommit
249
-	CompareUrl string
249
+	CompareURL string
250 250
 
251 251
 	avatars map[string]string
252 252
 }
@@ -275,12 +275,12 @@ func (pc *PushCommits) ToApiPayloadCommits(repoLink string) []*api.PayloadCommit
275 275
 			ID:      commit.Sha1,
276 276
 			Message: commit.Message,
277 277
 			URL:     fmt.Sprintf("%s/commit/%s", repoLink, commit.Sha1),
278
-			Author: &api.PayloadAuthor{
278
+			Author: &api.PayloadUser{
279 279
 				Name:     commit.AuthorName,
280 280
 				Email:    commit.AuthorEmail,
281 281
 				UserName: authorUsername,
282 282
 			},
283
-			Committer: &api.PayloadCommitter{
283
+			Committer: &api.PayloadUser{
284 284
 				Name:     commit.CommitterName,
285 285
 				Email:    commit.CommitterEmail,
286 286
 				UserName: committerUsername,
@@ -475,7 +475,7 @@ func CommitRepoAction(
475 475
 	} else {
476 476
 		// if not the first commit, set the compareUrl
477 477
 		if !strings.HasPrefix(oldCommitID, "0000000") {
478
-			commit.CompareUrl = repo.ComposeCompareURL(oldCommitID, newCommitID)
478
+			commit.CompareURL = repo.ComposeCompareURL(oldCommitID, newCommitID)
479 479
 		} else {
480 480
 			isNewBranch = true
481 481
 		}
@@ -495,7 +495,6 @@ func CommitRepoAction(
495 495
 	}
496 496
 
497 497
 	refName := git.RefEndName(refFullName)
498
-
499 498
 	if err = NotifyWatchers(&Action{
500 499
 		ActUserID:    u.ID,
501 500
 		ActUserName:  userName,
@@ -511,35 +510,24 @@ func CommitRepoAction(
511 510
 		return fmt.Errorf("NotifyWatchers: %v", err)
512 511
 	}
513 512
 
514
-	payloadRepo := repo.ComposePayload()
515
-
516
-	var pusherEmail, pusherName string
517 513
 	pusher, err := GetUserByName(userName)
518
-	if err == nil {
519
-		pusherEmail = pusher.Email
520
-		pusherName = pusher.DisplayName()
521
-	}
522
-	payloadSender := &api.PayloadUser{
523
-		UserName:  pusher.Name,
524
-		ID:        pusher.ID,
525
-		AvatarUrl: pusher.AvatarLink(),
514
+	if err != nil {
515
+		return fmt.Errorf("GetUserByName: %v", err)
526 516
 	}
517
+	apiPusher := pusher.APIFormat()
527 518
 
519
+	apiRepo := repo.APIFormat(nil)
528 520
 	switch opType {
529 521
 	case ACTION_COMMIT_REPO: // Push
530 522
 		if err = PrepareWebhooks(repo, HOOK_EVENT_PUSH, &api.PushPayload{
531 523
 			Ref:        refFullName,
532 524
 			Before:     oldCommitID,
533 525
 			After:      newCommitID,
534
-			CompareUrl: setting.AppUrl + commit.CompareUrl,
526
+			CompareURL: setting.AppUrl + commit.CompareURL,
535 527
 			Commits:    commit.ToApiPayloadCommits(repo.FullLink()),
536
-			Repo:       payloadRepo,
537
-			Pusher: &api.PayloadAuthor{
538
-				Name:     pusherName,
539
-				Email:    pusherEmail,
540
-				UserName: userName,
541
-			},
542
-			Sender: payloadSender,
528
+			Repo:       apiRepo,
529
+			Pusher:     apiPusher,
530
+			Sender:     apiPusher,
543 531
 		}); err != nil {
544 532
 			return fmt.Errorf("PrepareWebhooks: %v", err)
545 533
 		}
@@ -548,8 +536,8 @@ func CommitRepoAction(
548 536
 			return PrepareWebhooks(repo, HOOK_EVENT_CREATE, &api.CreatePayload{
549 537
 				Ref:     refName,
550 538
 				RefType: "branch",
551
-				Repo:    payloadRepo,
552
-				Sender:  payloadSender,
539
+				Repo:    apiRepo,
540
+				Sender:  apiPusher,
553 541
 			})
554 542
 		}
555 543
 
@@ -557,8 +545,8 @@ func CommitRepoAction(
557 545
 		return PrepareWebhooks(repo, HOOK_EVENT_CREATE, &api.CreatePayload{
558 546
 			Ref:     refName,
559 547
 			RefType: "tag",
560
-			Repo:    payloadRepo,
561
-			Sender:  payloadSender,
548
+			Repo:    apiRepo,
549
+			Sender:  apiPusher,
562 550
 		})
563 551
 	}
564 552
 

+ 5 - 13
models/pull.go

@@ -308,22 +308,14 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error
308 308
 	l.PushFront(mergeCommit)
309 309
 
310 310
 	p := &api.PushPayload{
311
-		Ref:        "refs/heads/" + pr.BaseBranch,
311
+		Ref:        git.BRANCH_PREFIX + pr.BaseBranch,
312 312
 		Before:     pr.MergeBase,
313 313
 		After:      pr.MergedCommitID,
314
-		CompareUrl: setting.AppUrl + pr.BaseRepo.ComposeCompareURL(pr.MergeBase, pr.MergedCommitID),
314
+		CompareURL: setting.AppUrl + pr.BaseRepo.ComposeCompareURL(pr.MergeBase, pr.MergedCommitID),
315 315
 		Commits:    ListToPushCommits(l).ToApiPayloadCommits(pr.BaseRepo.FullLink()),
316
-		Repo:       pr.BaseRepo.ComposePayload(),
317
-		Pusher: &api.PayloadAuthor{
318
-			Name:     pr.HeadRepo.MustOwner().DisplayName(),
319
-			Email:    pr.HeadRepo.MustOwner().Email,
320
-			UserName: pr.HeadRepo.MustOwner().Name,
321
-		},
322
-		Sender: &api.PayloadUser{
323
-			UserName:  doer.Name,
324
-			ID:        doer.ID,
325
-			AvatarUrl: doer.AvatarLink(),
326
-		},
316
+		Repo:       pr.BaseRepo.APIFormat(nil),
317
+		Pusher:     pr.HeadRepo.MustOwner().APIFormat(),
318
+		Sender:     doer.APIFormat(),
327 319
 	}
328 320
 	if err = PrepareWebhooks(pr.BaseRepo, HOOK_EVENT_PUSH, p); err != nil {
329 321
 		return fmt.Errorf("PrepareWebhooks: %v", err)

+ 0 - 22
models/repo.go

@@ -482,28 +482,6 @@ func (repo *Repository) SavePatch(index int64, patch []byte) error {
482 482
 	return nil
483 483
 }
484 484
 
485
-// ComposePayload composes and returns *api.PayloadRepo corresponding to the repository.
486
-func (repo *Repository) ComposePayload() *api.PayloadRepo {
487
-	cl := repo.CloneLink()
488
-	return &api.PayloadRepo{
489
-		ID:          repo.ID,
490
-		Name:        repo.Name,
491
-		URL:         repo.FullLink(),
492
-		SSHURL:      cl.SSH,
493
-		CloneURL:    cl.HTTPS,
494
-		Description: repo.Description,
495
-		Website:     repo.Website,
496
-		Watchers:    repo.NumWatches,
497
-		Owner: &api.PayloadAuthor{
498
-			Name:     repo.MustOwner().DisplayName(),
499
-			Email:    repo.MustOwner().Email,
500
-			UserName: repo.MustOwner().Name,
501
-		},
502
-		Private:       repo.IsPrivate,
503
-		DefaultBranch: repo.DefaultBranch,
504
-	}
505
-}
506
-
507 485
 func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) {
508 486
 	has, err := e.Get(&Repository{
509 487
 		OwnerID:   u.ID,

+ 8 - 8
models/webhook_slack.go

@@ -76,8 +76,8 @@ func getSlackCreatePayload(p *api.CreatePayload, slack *SlackMeta) (*SlackPayloa
76 76
 	// created tag/branch
77 77
 	refName := git.RefEndName(p.Ref)
78 78
 
79
-	repoLink := SlackLinkFormatter(p.Repo.URL, p.Repo.Name)
80
-	refLink := SlackLinkFormatter(p.Repo.URL+"/src/"+refName, refName)
79
+	repoLink := SlackLinkFormatter(p.Repo.HTMLURL, p.Repo.Name)
80
+	refLink := SlackLinkFormatter(p.Repo.HTMLURL+"/src/"+refName, refName)
81 81
 	text := fmt.Sprintf("[%s:%s] %s created by %s", repoLink, refLink, p.RefType, p.Sender.UserName)
82 82
 
83 83
 	return &SlackPayload{
@@ -101,15 +101,15 @@ func getSlackPushPayload(p *api.PushPayload, slack *SlackMeta) (*SlackPayload, e
101 101
 	} else {
102 102
 		commitDesc = fmt.Sprintf("%d new commits", len(p.Commits))
103 103
 	}
104
-	if len(p.CompareUrl) > 0 {
105
-		commitString = SlackLinkFormatter(p.CompareUrl, commitDesc)
104
+	if len(p.CompareURL) > 0 {
105
+		commitString = SlackLinkFormatter(p.CompareURL, commitDesc)
106 106
 	} else {
107 107
 		commitString = commitDesc
108 108
 	}
109 109
 
110
-	repoLink := SlackLinkFormatter(p.Repo.URL, p.Repo.Name)
111
-	branchLink := SlackLinkFormatter(p.Repo.URL+"/src/"+branchName, branchName)
112
-	text := fmt.Sprintf("[%s:%s] %s pushed by %s", repoLink, branchLink, commitString, p.Pusher.Name)
110
+	repoLink := SlackLinkFormatter(p.Repo.HTMLURL, p.Repo.Name)
111
+	branchLink := SlackLinkFormatter(p.Repo.HTMLURL+"/src/"+branchName, branchName)
112
+	text := fmt.Sprintf("[%s:%s] %s pushed by %s", repoLink, branchLink, commitString, p.Pusher.UserName)
113 113
 
114 114
 	var attachmentText string
115 115
 	// for each commit, generate attachment text
@@ -135,7 +135,7 @@ func getSlackPushPayload(p *api.PushPayload, slack *SlackMeta) (*SlackPayload, e
135 135
 
136 136
 func getSlackPullRequestPayload(p *api.PullRequestPayload, slack *SlackMeta) (*SlackPayload, error) {
137 137
 	senderLink := SlackLinkFormatter(setting.AppUrl+p.Sender.UserName, p.Sender.UserName)
138
-	titleLink := SlackLinkFormatter(fmt.Sprintf("%s/%d", setting.AppUrl+p.Repository.FullName+"/pulls", p.Index),
138
+	titleLink := SlackLinkFormatter(fmt.Sprintf("%s/pulls/%d", p.Repository.HTMLURL, p.Index),
139 139
 		fmt.Sprintf("#%d %s", p.Index, p.PullRequest.Title))
140 140
 	var text, title, attachmentText string
141 141
 	switch p.Action {

+ 2 - 3
routers/api/v1/admin/user.go

@@ -11,7 +11,6 @@ import (
11 11
 	"github.com/gogits/gogs/modules/context"
12 12
 	"github.com/gogits/gogs/modules/log"
13 13
 	"github.com/gogits/gogs/modules/setting"
14
-	"github.com/gogits/gogs/routers/api/v1/convert"
15 14
 	"github.com/gogits/gogs/routers/api/v1/user"
16 15
 )
17 16
 
@@ -69,7 +68,7 @@ func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
69 68
 		models.SendRegisterNotifyMail(ctx.Context.Context, u)
70 69
 	}
71 70
 
72
-	ctx.JSON(201, convert.ToUser(u))
71
+	ctx.JSON(201, u.APIFormat())
73 72
 }
74 73
 
75 74
 // https://github.com/gogits/go-gogs-client/wiki/Administration-Users#edit-an-existing-user
@@ -121,7 +120,7 @@ func EditUser(ctx *context.APIContext, form api.EditUserOption) {
121 120
 	}
122 121
 	log.Trace("Account profile updated by admin (%s): %s", ctx.User.Name, u.Name)
123 122
 
124
-	ctx.JSON(200, convert.ToUser(u))
123
+	ctx.JSON(200, u.APIFormat())
125 124
 }
126 125
 
127 126
 // https://github.com/gogits/go-gogs-client/wiki/Administration-Users#delete-a-user

+ 2 - 101
routers/api/v1/convert/convert.go

@@ -13,23 +13,8 @@ import (
13 13
 	api "github.com/gogits/go-gogs-client"
14 14
 
15 15
 	"github.com/gogits/gogs/models"
16
-	"github.com/gogits/gogs/modules/setting"
17 16
 )
18 17
 
19
-func ToUser(u *models.User) *api.User {
20
-	if u == nil {
21
-		return nil
22
-	}
23
-
24
-	return &api.User{
25
-		ID:        u.ID,
26
-		UserName:  u.Name,
27
-		FullName:  u.FullName,
28
-		Email:     u.Email,
29
-		AvatarUrl: u.AvatarLink(),
30
-	}
31
-}
32
-
33 18
 func ToEmail(email *models.EmailAddress) *api.Email {
34 19
 	return &api.Email{
35 20
 		Email:    email.Email,
@@ -38,28 +23,6 @@ func ToEmail(email *models.EmailAddress) *api.Email {
38 23
 	}
39 24
 }
40 25
 
41
-func ToRepository(owner *models.User, repo *models.Repository, permission api.Permission) *api.Repository {
42
-	cl := repo.CloneLink()
43
-	return &api.Repository{
44
-		ID:          repo.ID,
45
-		Owner:       ToUser(owner),
46
-		FullName:    owner.Name + "/" + repo.Name,
47
-		Description: repo.Description,
48
-		Private:     repo.IsPrivate,
49
-		Fork:        repo.IsFork,
50
-		HTMLURL:     setting.AppUrl + owner.Name + "/" + repo.Name,
51
-		CloneURL:    cl.HTTPS,
52
-		SSHURL:      cl.SSH,
53
-		OpenIssues:  repo.NumOpenIssues,
54
-		Stars:       repo.NumStars,
55
-		Forks:       repo.NumForks,
56
-		Watchers:    repo.NumWatches,
57
-		Created:     repo.Created,
58
-		Updated:     repo.Updated,
59
-		Permissions: &permission,
60
-	}
61
-}
62
-
63 26
 func ToBranch(b *models.Branch, c *git.Commit) *api.Branch {
64 27
 	return &api.Branch{
65 28
 		Name:   b.Name,
@@ -82,12 +45,12 @@ func ToCommit(c *git.Commit) *api.PayloadCommit {
82 45
 		ID:      c.ID.String(),
83 46
 		Message: c.Message(),
84 47
 		URL:     "Not implemented",
85
-		Author: &api.PayloadAuthor{
48
+		Author: &api.PayloadUser{
86 49
 			Name:     c.Author.Name,
87 50
 			Email:    c.Author.Email,
88 51
 			UserName: authorUsername,
89 52
 		},
90
-		Committer: &api.PayloadCommitter{
53
+		Committer: &api.PayloadUser{
91 54
 			Name:     c.Committer.Name,
92 55
 			Email:    c.Committer.Email,
93 56
 			UserName: committerUsername,
@@ -142,68 +105,6 @@ func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
142 105
 	}
143 106
 }
144 107
 
145
-func ToLabel(label *models.Label) *api.Label {
146
-	return &api.Label{
147
-		ID:    label.ID,
148
-		Name:  label.Name,
149
-		Color: label.Color,
150
-	}
151
-}
152
-
153
-func ToMilestone(milestone *models.Milestone) *api.Milestone {
154
-	if milestone == nil {
155
-		return nil
156
-	}
157
-
158
-	apiMilestone := &api.Milestone{
159
-		ID:           milestone.ID,
160
-		State:        milestone.State(),
161
-		Title:        milestone.Name,
162
-		Description:  milestone.Content,
163
-		OpenIssues:   milestone.NumOpenIssues,
164
-		ClosedIssues: milestone.NumClosedIssues,
165
-	}
166
-	if milestone.IsClosed {
167
-		apiMilestone.Closed = &milestone.ClosedDate
168
-	}
169
-	if milestone.Deadline.Year() < 9999 {
170
-		apiMilestone.Deadline = &milestone.Deadline
171
-	}
172
-	return apiMilestone
173
-}
174
-
175
-func ToIssue(issue *models.Issue) *api.Issue {
176
-	apiLabels := make([]*api.Label, len(issue.Labels))
177
-	for i := range issue.Labels {
178
-		apiLabels[i] = ToLabel(issue.Labels[i])
179
-	}
180
-
181
-	apiIssue := &api.Issue{
182
-		ID:        issue.ID,
183
-		Index:     issue.Index,
184
-		State:     issue.State(),
185
-		Title:     issue.Title,
186
-		Body:      issue.Content,
187
-		User:      ToUser(issue.Poster),
188
-		Labels:    apiLabels,
189
-		Assignee:  ToUser(issue.Assignee),
190
-		Milestone: ToMilestone(issue.Milestone),
191
-		Comments:  issue.NumComments,
192
-		Created:   issue.Created,
193
-		Updated:   issue.Updated,
194
-	}
195
-	if issue.IsPull {
196
-		apiIssue.PullRequest = &api.PullRequestMeta{
197
-			HasMerged: issue.PullRequest.HasMerged,
198
-		}
199
-		if issue.PullRequest.HasMerged {
200
-			apiIssue.PullRequest.Merged = &issue.PullRequest.Merged
201
-		}
202
-	}
203
-
204
-	return apiIssue
205
-}
206
-
207 108
 func ToOrganization(org *models.User) *api.Organization {
208 109
 	return &api.Organization{
209 110
 		ID:          org.ID,

+ 11 - 7
routers/api/v1/repo/issue.go

@@ -13,7 +13,6 @@ import (
13 13
 	"github.com/gogits/gogs/models"
14 14
 	"github.com/gogits/gogs/modules/context"
15 15
 	"github.com/gogits/gogs/modules/setting"
16
-	"github.com/gogits/gogs/routers/api/v1/convert"
17 16
 )
18 17
 
19 18
 func ListIssues(ctx *context.APIContext) {
@@ -28,7 +27,12 @@ func ListIssues(ctx *context.APIContext) {
28 27
 
29 28
 	apiIssues := make([]*api.Issue, len(issues))
30 29
 	for i := range issues {
31
-		apiIssues[i] = convert.ToIssue(issues[i])
30
+		// FIXME: use IssueList to improve performance.
31
+		if err = issues[i].LoadAttributes(); err != nil {
32
+			ctx.Error(500, "LoadAttributes", err)
33
+			return
34
+		}
35
+		apiIssues[i] = issues[i].APIFormat()
32 36
 	}
33 37
 
34 38
 	ctx.SetLinkHeader(ctx.Repo.Repository.NumIssues, setting.UI.IssuePagingNum)
@@ -46,13 +50,13 @@ func GetIssue(ctx *context.APIContext) {
46 50
 		return
47 51
 	}
48 52
 
49
-	ctx.JSON(200, convert.ToIssue(issue))
53
+	ctx.JSON(200, issue.APIFormat())
50 54
 }
51 55
 
52 56
 func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
53 57
 	issue := &models.Issue{
54 58
 		RepoID:   ctx.Repo.Repository.ID,
55
-		Title:     form.Title,
59
+		Title:    form.Title,
56 60
 		PosterID: ctx.User.ID,
57 61
 		Poster:   ctx.User,
58 62
 		Content:  form.Body,
@@ -83,7 +87,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
83 87
 
84 88
 	if form.Closed {
85 89
 		if err := issue.ChangeStatus(ctx.User, ctx.Repo.Repository, true); err != nil {
86
-			ctx.Error(500, "issue.ChangeStatus", err)
90
+			ctx.Error(500, "ChangeStatus", err)
87 91
 			return
88 92
 		}
89 93
 	}
@@ -95,7 +99,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
95 99
 		ctx.Error(500, "GetIssueByID", err)
96 100
 		return
97 101
 	}
98
-	ctx.JSON(201, convert.ToIssue(issue))
102
+	ctx.JSON(201, issue.APIFormat())
99 103
 }
100 104
 
101 105
 func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
@@ -164,5 +168,5 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
164 168
 		ctx.Error(500, "GetIssueByID", err)
165 169
 		return
166 170
 	}
167
-	ctx.JSON(201, convert.ToIssue(issue))
171
+	ctx.JSON(201, issue.APIFormat())
168 172
 }

+ 3 - 4
routers/api/v1/repo/issue_label.go

@@ -9,7 +9,6 @@ import (
9 9
 
10 10
 	"github.com/gogits/gogs/models"
11 11
 	"github.com/gogits/gogs/modules/context"
12
-	"github.com/gogits/gogs/routers/api/v1/convert"
13 12
 )
14 13
 
15 14
 func ListIssueLabels(ctx *context.APIContext) {
@@ -25,7 +24,7 @@ func ListIssueLabels(ctx *context.APIContext) {
25 24
 
26 25
 	apiLabels := make([]*api.Label, len(issue.Labels))
27 26
 	for i := range issue.Labels {
28
-		apiLabels[i] = convert.ToLabel(issue.Labels[i])
27
+		apiLabels[i] = issue.Labels[i].APIFormat()
29 28
 	}
30 29
 	ctx.JSON(200, &apiLabels)
31 30
 }
@@ -65,7 +64,7 @@ func AddIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
65 64
 
66 65
 	apiLabels := make([]*api.Label, len(labels))
67 66
 	for i := range labels {
68
-		apiLabels[i] = convert.ToLabel(labels[i])
67
+		apiLabels[i] = issue.Labels[i].APIFormat()
69 68
 	}
70 69
 	ctx.JSON(200, &apiLabels)
71 70
 }
@@ -139,7 +138,7 @@ func ReplaceIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
139 138
 
140 139
 	apiLabels := make([]*api.Label, len(labels))
141 140
 	for i := range labels {
142
-		apiLabels[i] = convert.ToLabel(labels[i])
141
+		apiLabels[i] = issue.Labels[i].APIFormat()
143 142
 	}
144 143
 	ctx.JSON(200, &apiLabels)
145 144
 }

+ 4 - 5
routers/api/v1/repo/label.go

@@ -9,7 +9,6 @@ import (
9 9
 
10 10
 	"github.com/gogits/gogs/models"
11 11
 	"github.com/gogits/gogs/modules/context"
12
-	"github.com/gogits/gogs/routers/api/v1/convert"
13 12
 )
14 13
 
15 14
 func ListLabels(ctx *context.APIContext) {
@@ -21,7 +20,7 @@ func ListLabels(ctx *context.APIContext) {
21 20
 
22 21
 	apiLabels := make([]*api.Label, len(labels))
23 22
 	for i := range labels {
24
-		apiLabels[i] = convert.ToLabel(labels[i])
23
+		apiLabels[i] = labels[i].APIFormat()
25 24
 	}
26 25
 	ctx.JSON(200, &apiLabels)
27 26
 }
@@ -37,7 +36,7 @@ func GetLabel(ctx *context.APIContext) {
37 36
 		return
38 37
 	}
39 38
 
40
-	ctx.JSON(200, convert.ToLabel(label))
39
+	ctx.JSON(200, label.APIFormat())
41 40
 }
42 41
 
43 42
 func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) {
@@ -55,7 +54,7 @@ func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) {
55 54
 		ctx.Error(500, "NewLabel", err)
56 55
 		return
57 56
 	}
58
-	ctx.JSON(201, convert.ToLabel(label))
57
+	ctx.JSON(201, label.APIFormat())
59 58
 }
60 59
 
61 60
 func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
@@ -84,7 +83,7 @@ func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
84 83
 		ctx.Handle(500, "UpdateLabel", err)
85 84
 		return
86 85
 	}
87
-	ctx.JSON(200, convert.ToLabel(label))
86
+	ctx.JSON(200, label.APIFormat())
88 87
 }
89 88
 
90 89
 func DeleteLabel(ctx *context.APIContext) {

+ 6 - 6
routers/api/v1/repo/repo.go

@@ -93,12 +93,12 @@ func ListMyRepos(ctx *context.APIContext) {
93 93
 
94 94
 	repos := make([]*api.Repository, numOwnRepos+len(accessibleRepos))
95 95
 	for i := range ownRepos {
96
-		repos[i] = convert.ToRepository(ctx.User, ownRepos[i], api.Permission{true, true, true})
96
+		repos[i] = ownRepos[i].APIFormat(&api.Permission{true, true, true})
97 97
 	}
98 98
 	i := numOwnRepos
99 99
 
100 100
 	for repo, access := range accessibleRepos {
101
-		repos[i] = convert.ToRepository(repo.Owner, repo, api.Permission{
101
+		repos[i] = repo.APIFormat(&api.Permission{
102 102
 			Admin: access >= models.ACCESS_MODE_ADMIN,
103 103
 			Push:  access >= models.ACCESS_MODE_WRITE,
104 104
 			Pull:  true,
@@ -135,7 +135,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateR
135 135
 		return
136 136
 	}
137 137
 
138
-	ctx.JSON(201, convert.ToRepository(owner, repo, api.Permission{true, true, true}))
138
+	ctx.JSON(201, repo.APIFormat(&api.Permission{true, true, true}))
139 139
 }
140 140
 
141 141
 // https://github.com/gogits/go-gogs-client/wiki/Repositories#create
@@ -235,7 +235,7 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
235 235
 	}
236 236
 
237 237
 	log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName)
238
-	ctx.JSON(201, convert.ToRepository(ctxUser, repo, api.Permission{true, true, true}))
238
+	ctx.JSON(201, repo.APIFormat(&api.Permission{true, true, true}))
239 239
 }
240 240
 
241 241
 func parseOwnerAndRepo(ctx *context.APIContext) (*models.User, *models.Repository) {
@@ -264,12 +264,12 @@ func parseOwnerAndRepo(ctx *context.APIContext) (*models.User, *models.Repositor
264 264
 
265 265
 // https://github.com/gogits/go-gogs-client/wiki/Repositories#get
266 266
 func Get(ctx *context.APIContext) {
267
-	owner, repo := parseOwnerAndRepo(ctx)
267
+	_, repo := parseOwnerAndRepo(ctx)
268 268
 	if ctx.Written() {
269 269
 		return
270 270
 	}
271 271
 
272
-	ctx.JSON(200, convert.ToRepository(owner, repo, api.Permission{true, true, true}))
272
+	ctx.JSON(200, repo.APIFormat(&api.Permission{true, true, true}))
273 273
 }
274 274
 
275 275
 // https://github.com/gogits/go-gogs-client/wiki/Repositories#delete

+ 1 - 2
routers/api/v1/user/follower.go

@@ -9,13 +9,12 @@ import (
9 9
 
10 10
 	"github.com/gogits/gogs/models"
11 11
 	"github.com/gogits/gogs/modules/context"
12
-	"github.com/gogits/gogs/routers/api/v1/convert"
13 12
 )
14 13
 
15 14
 func responseApiUsers(ctx *context.APIContext, users []*models.User) {
16 15
 	apiUsers := make([]*api.User, len(users))
17 16
 	for i := range users {
18
-		apiUsers[i] = convert.ToUser(users[i])
17
+		apiUsers[i] = users[i].APIFormat()
19 18
 	}
20 19
 	ctx.JSON(200, &apiUsers)
21 20
 }

+ 2 - 3
routers/api/v1/user/user.go

@@ -11,7 +11,6 @@ import (
11 11
 
12 12
 	"github.com/gogits/gogs/models"
13 13
 	"github.com/gogits/gogs/modules/context"
14
-	"github.com/gogits/gogs/routers/api/v1/convert"
15 14
 )
16 15
 
17 16
 func Search(ctx *context.APIContext) {
@@ -67,9 +66,9 @@ func GetInfo(ctx *context.APIContext) {
67 66
 	if !ctx.IsSigned {
68 67
 		u.Email = ""
69 68
 	}
70
-	ctx.JSON(200, convert.ToUser(u))
69
+	ctx.JSON(200, u.APIFormat())
71 70
 }
72 71
 
73 72
 func GetAuthenticatedUser(ctx *context.APIContext) {
74
-	ctx.JSON(200, convert.ToUser(ctx.User))
73
+	ctx.JSON(200, ctx.User.APIFormat())
75 74
 }

+ 3 - 1
routers/repo/http.go

@@ -20,6 +20,8 @@ import (
20 20
 	"strings"
21 21
 	"time"
22 22
 
23
+	git "github.com/gogits/git-module"
24
+
23 25
 	"github.com/gogits/gogs/models"
24 26
 	"github.com/gogits/gogs/modules/base"
25 27
 	"github.com/gogits/gogs/modules/context"
@@ -206,7 +208,7 @@ func HTTP(ctx *context.Context) {
206 208
 						RepoName:     reponame,
207 209
 					}); err == nil {
208 210
 						go models.HookQueue.Add(repo.ID)
209
-						go models.AddTestPullRequestTask(authUser, repo.ID, strings.TrimPrefix(refName, "refs/heads/"), true)
211
+						go models.AddTestPullRequestTask(authUser, repo.ID, strings.TrimPrefix(refName, git.BRANCH_PREFIX), true)
210 212
 					}
211 213
 
212 214
 				}

+ 6 - 13
routers/repo/webhook.go

@@ -347,6 +347,7 @@ func SlackHooksEditPost(ctx *context.Context, form auth.NewSlackHookForm) {
347 347
 }
348 348
 
349 349
 func TestWebhook(ctx *context.Context) {
350
+	apiUser := ctx.User.APIFormat()
350 351
 	p := &api.PushPayload{
351 352
 		Ref:    git.BRANCH_PREFIX + ctx.Repo.Repository.DefaultBranch,
352 353
 		Before: ctx.Repo.CommitID,
@@ -356,27 +357,19 @@ func TestWebhook(ctx *context.Context) {
356 357
 				ID:      ctx.Repo.CommitID,
357 358
 				Message: ctx.Repo.Commit.Message(),
358 359
 				URL:     ctx.Repo.Repository.FullLink() + "/commit/" + ctx.Repo.CommitID,
359
-				Author: &api.PayloadAuthor{
360
+				Author: &api.PayloadUser{
360 361
 					Name:  ctx.Repo.Commit.Author.Name,
361 362
 					Email: ctx.Repo.Commit.Author.Email,
362 363
 				},
363
-				Committer: &api.PayloadCommitter{
364
+				Committer: &api.PayloadUser{
364 365
 					Name:  ctx.Repo.Commit.Committer.Name,
365 366
 					Email: ctx.Repo.Commit.Committer.Email,
366 367
 				},
367 368
 			},
368 369
 		},
369
-		Repo: ctx.Repo.Repository.ComposePayload(),
370
-		Pusher: &api.PayloadAuthor{
371
-			Name:     ctx.User.Name,
372
-			Email:    ctx.User.Email,
373
-			UserName: ctx.User.Name,
374
-		},
375
-		Sender: &api.PayloadUser{
376
-			UserName:  ctx.User.Name,
377
-			ID:        ctx.User.ID,
378
-			AvatarUrl: ctx.User.AvatarLink(),
379
-		},
370
+		Repo:   ctx.Repo.Repository.APIFormat(nil),
371
+		Pusher: apiUser,
372
+		Sender: apiUser,
380 373
 	}
381 374
 	if err := models.PrepareWebhooks(ctx.Repo.Repository, models.HOOK_EVENT_PUSH, p); err != nil {
382 375
 		ctx.Flash.Error("PrepareWebhooks: " + err.Error())

+ 1 - 1
templates/.VERSION

@@ -1 +1 @@
1
-0.9.76.0814
1
+0.9.77.0814