0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-12-24 00:14:38 +01:00

Replace convert.To with APIFormat calls

This commit is contained in:
Unknwon 2016-08-14 04:17:26 -07:00
parent 3f7f4852ef
commit dccb0c15b9
21 changed files with 79 additions and 225 deletions

View file

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

View file

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

View file

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

View file

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

4
glide.lock generated
View file

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

View file

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

View file

@ -246,7 +246,7 @@ type PushCommit struct {
type PushCommits struct {
Len int
Commits []*PushCommit
CompareUrl string
CompareURL string
avatars map[string]string
}
@ -275,12 +275,12 @@ func (pc *PushCommits) ToApiPayloadCommits(repoLink string) []*api.PayloadCommit
ID: commit.Sha1,
Message: commit.Message,
URL: fmt.Sprintf("%s/commit/%s", repoLink, commit.Sha1),
Author: &api.PayloadAuthor{
Author: &api.PayloadUser{
Name: commit.AuthorName,
Email: commit.AuthorEmail,
UserName: authorUsername,
},
Committer: &api.PayloadCommitter{
Committer: &api.PayloadUser{
Name: commit.CommitterName,
Email: commit.CommitterEmail,
UserName: committerUsername,
@ -475,7 +475,7 @@ func CommitRepoAction(
} else {
// if not the first commit, set the compareUrl
if !strings.HasPrefix(oldCommitID, "0000000") {
commit.CompareUrl = repo.ComposeCompareURL(oldCommitID, newCommitID)
commit.CompareURL = repo.ComposeCompareURL(oldCommitID, newCommitID)
} else {
isNewBranch = true
}
@ -495,7 +495,6 @@ func CommitRepoAction(
}
refName := git.RefEndName(refFullName)
if err = NotifyWatchers(&Action{
ActUserID: u.ID,
ActUserName: userName,
@ -511,35 +510,24 @@ func CommitRepoAction(
return fmt.Errorf("NotifyWatchers: %v", err)
}
payloadRepo := repo.ComposePayload()
var pusherEmail, pusherName string
pusher, err := GetUserByName(userName)
if err == nil {
pusherEmail = pusher.Email
pusherName = pusher.DisplayName()
}
payloadSender := &api.PayloadUser{
UserName: pusher.Name,
ID: pusher.ID,
AvatarUrl: pusher.AvatarLink(),
if err != nil {
return fmt.Errorf("GetUserByName: %v", err)
}
apiPusher := pusher.APIFormat()
apiRepo := repo.APIFormat(nil)
switch opType {
case ACTION_COMMIT_REPO: // Push
if err = PrepareWebhooks(repo, HOOK_EVENT_PUSH, &api.PushPayload{
Ref: refFullName,
Before: oldCommitID,
After: newCommitID,
CompareUrl: setting.AppUrl + commit.CompareUrl,
CompareURL: setting.AppUrl + commit.CompareURL,
Commits: commit.ToApiPayloadCommits(repo.FullLink()),
Repo: payloadRepo,
Pusher: &api.PayloadAuthor{
Name: pusherName,
Email: pusherEmail,
UserName: userName,
},
Sender: payloadSender,
Repo: apiRepo,
Pusher: apiPusher,
Sender: apiPusher,
}); err != nil {
return fmt.Errorf("PrepareWebhooks: %v", err)
}
@ -548,8 +536,8 @@ func CommitRepoAction(
return PrepareWebhooks(repo, HOOK_EVENT_CREATE, &api.CreatePayload{
Ref: refName,
RefType: "branch",
Repo: payloadRepo,
Sender: payloadSender,
Repo: apiRepo,
Sender: apiPusher,
})
}
@ -557,8 +545,8 @@ func CommitRepoAction(
return PrepareWebhooks(repo, HOOK_EVENT_CREATE, &api.CreatePayload{
Ref: refName,
RefType: "tag",
Repo: payloadRepo,
Sender: payloadSender,
Repo: apiRepo,
Sender: apiPusher,
})
}

View file

@ -308,22 +308,14 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error
l.PushFront(mergeCommit)
p := &api.PushPayload{
Ref: "refs/heads/" + pr.BaseBranch,
Ref: git.BRANCH_PREFIX + pr.BaseBranch,
Before: pr.MergeBase,
After: pr.MergedCommitID,
CompareUrl: setting.AppUrl + pr.BaseRepo.ComposeCompareURL(pr.MergeBase, pr.MergedCommitID),
CompareURL: setting.AppUrl + pr.BaseRepo.ComposeCompareURL(pr.MergeBase, pr.MergedCommitID),
Commits: ListToPushCommits(l).ToApiPayloadCommits(pr.BaseRepo.FullLink()),
Repo: pr.BaseRepo.ComposePayload(),
Pusher: &api.PayloadAuthor{
Name: pr.HeadRepo.MustOwner().DisplayName(),
Email: pr.HeadRepo.MustOwner().Email,
UserName: pr.HeadRepo.MustOwner().Name,
},
Sender: &api.PayloadUser{
UserName: doer.Name,
ID: doer.ID,
AvatarUrl: doer.AvatarLink(),
},
Repo: pr.BaseRepo.APIFormat(nil),
Pusher: pr.HeadRepo.MustOwner().APIFormat(),
Sender: doer.APIFormat(),
}
if err = PrepareWebhooks(pr.BaseRepo, HOOK_EVENT_PUSH, p); err != nil {
return fmt.Errorf("PrepareWebhooks: %v", err)

View file

@ -482,28 +482,6 @@ func (repo *Repository) SavePatch(index int64, patch []byte) error {
return nil
}
// ComposePayload composes and returns *api.PayloadRepo corresponding to the repository.
func (repo *Repository) ComposePayload() *api.PayloadRepo {
cl := repo.CloneLink()
return &api.PayloadRepo{
ID: repo.ID,
Name: repo.Name,
URL: repo.FullLink(),
SSHURL: cl.SSH,
CloneURL: cl.HTTPS,
Description: repo.Description,
Website: repo.Website,
Watchers: repo.NumWatches,
Owner: &api.PayloadAuthor{
Name: repo.MustOwner().DisplayName(),
Email: repo.MustOwner().Email,
UserName: repo.MustOwner().Name,
},
Private: repo.IsPrivate,
DefaultBranch: repo.DefaultBranch,
}
}
func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) {
has, err := e.Get(&Repository{
OwnerID: u.ID,

View file

@ -76,8 +76,8 @@ func getSlackCreatePayload(p *api.CreatePayload, slack *SlackMeta) (*SlackPayloa
// created tag/branch
refName := git.RefEndName(p.Ref)
repoLink := SlackLinkFormatter(p.Repo.URL, p.Repo.Name)
refLink := SlackLinkFormatter(p.Repo.URL+"/src/"+refName, refName)
repoLink := SlackLinkFormatter(p.Repo.HTMLURL, p.Repo.Name)
refLink := SlackLinkFormatter(p.Repo.HTMLURL+"/src/"+refName, refName)
text := fmt.Sprintf("[%s:%s] %s created by %s", repoLink, refLink, p.RefType, p.Sender.UserName)
return &SlackPayload{
@ -101,15 +101,15 @@ func getSlackPushPayload(p *api.PushPayload, slack *SlackMeta) (*SlackPayload, e
} else {
commitDesc = fmt.Sprintf("%d new commits", len(p.Commits))
}
if len(p.CompareUrl) > 0 {
commitString = SlackLinkFormatter(p.CompareUrl, commitDesc)
if len(p.CompareURL) > 0 {
commitString = SlackLinkFormatter(p.CompareURL, commitDesc)
} else {
commitString = commitDesc
}
repoLink := SlackLinkFormatter(p.Repo.URL, p.Repo.Name)
branchLink := SlackLinkFormatter(p.Repo.URL+"/src/"+branchName, branchName)
text := fmt.Sprintf("[%s:%s] %s pushed by %s", repoLink, branchLink, commitString, p.Pusher.Name)
repoLink := SlackLinkFormatter(p.Repo.HTMLURL, p.Repo.Name)
branchLink := SlackLinkFormatter(p.Repo.HTMLURL+"/src/"+branchName, branchName)
text := fmt.Sprintf("[%s:%s] %s pushed by %s", repoLink, branchLink, commitString, p.Pusher.UserName)
var attachmentText string
// for each commit, generate attachment text
@ -135,7 +135,7 @@ func getSlackPushPayload(p *api.PushPayload, slack *SlackMeta) (*SlackPayload, e
func getSlackPullRequestPayload(p *api.PullRequestPayload, slack *SlackMeta) (*SlackPayload, error) {
senderLink := SlackLinkFormatter(setting.AppUrl+p.Sender.UserName, p.Sender.UserName)
titleLink := SlackLinkFormatter(fmt.Sprintf("%s/%d", setting.AppUrl+p.Repository.FullName+"/pulls", p.Index),
titleLink := SlackLinkFormatter(fmt.Sprintf("%s/pulls/%d", p.Repository.HTMLURL, p.Index),
fmt.Sprintf("#%d %s", p.Index, p.PullRequest.Title))
var text, title, attachmentText string
switch p.Action {

View file

@ -11,7 +11,6 @@ import (
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/api/v1/convert"
"github.com/gogits/gogs/routers/api/v1/user"
)
@ -69,7 +68,7 @@ func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
models.SendRegisterNotifyMail(ctx.Context.Context, u)
}
ctx.JSON(201, convert.ToUser(u))
ctx.JSON(201, u.APIFormat())
}
// 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) {
}
log.Trace("Account profile updated by admin (%s): %s", ctx.User.Name, u.Name)
ctx.JSON(200, convert.ToUser(u))
ctx.JSON(200, u.APIFormat())
}
// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#delete-a-user

View file

@ -13,23 +13,8 @@ import (
api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/setting"
)
func ToUser(u *models.User) *api.User {
if u == nil {
return nil
}
return &api.User{
ID: u.ID,
UserName: u.Name,
FullName: u.FullName,
Email: u.Email,
AvatarUrl: u.AvatarLink(),
}
}
func ToEmail(email *models.EmailAddress) *api.Email {
return &api.Email{
Email: email.Email,
@ -38,28 +23,6 @@ func ToEmail(email *models.EmailAddress) *api.Email {
}
}
func ToRepository(owner *models.User, repo *models.Repository, permission api.Permission) *api.Repository {
cl := repo.CloneLink()
return &api.Repository{
ID: repo.ID,
Owner: ToUser(owner),
FullName: owner.Name + "/" + repo.Name,
Description: repo.Description,
Private: repo.IsPrivate,
Fork: repo.IsFork,
HTMLURL: setting.AppUrl + owner.Name + "/" + repo.Name,
CloneURL: cl.HTTPS,
SSHURL: cl.SSH,
OpenIssues: repo.NumOpenIssues,
Stars: repo.NumStars,
Forks: repo.NumForks,
Watchers: repo.NumWatches,
Created: repo.Created,
Updated: repo.Updated,
Permissions: &permission,
}
}
func ToBranch(b *models.Branch, c *git.Commit) *api.Branch {
return &api.Branch{
Name: b.Name,
@ -82,12 +45,12 @@ func ToCommit(c *git.Commit) *api.PayloadCommit {
ID: c.ID.String(),
Message: c.Message(),
URL: "Not implemented",
Author: &api.PayloadAuthor{
Author: &api.PayloadUser{
Name: c.Author.Name,
Email: c.Author.Email,
UserName: authorUsername,
},
Committer: &api.PayloadCommitter{
Committer: &api.PayloadUser{
Name: c.Committer.Name,
Email: c.Committer.Email,
UserName: committerUsername,
@ -142,68 +105,6 @@ func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
}
}
func ToLabel(label *models.Label) *api.Label {
return &api.Label{
ID: label.ID,
Name: label.Name,
Color: label.Color,
}
}
func ToMilestone(milestone *models.Milestone) *api.Milestone {
if milestone == nil {
return nil
}
apiMilestone := &api.Milestone{
ID: milestone.ID,
State: milestone.State(),
Title: milestone.Name,
Description: milestone.Content,
OpenIssues: milestone.NumOpenIssues,
ClosedIssues: milestone.NumClosedIssues,
}
if milestone.IsClosed {
apiMilestone.Closed = &milestone.ClosedDate
}
if milestone.Deadline.Year() < 9999 {
apiMilestone.Deadline = &milestone.Deadline
}
return apiMilestone
}
func ToIssue(issue *models.Issue) *api.Issue {
apiLabels := make([]*api.Label, len(issue.Labels))
for i := range issue.Labels {
apiLabels[i] = ToLabel(issue.Labels[i])
}
apiIssue := &api.Issue{
ID: issue.ID,
Index: issue.Index,
State: issue.State(),
Title: issue.Title,
Body: issue.Content,
User: ToUser(issue.Poster),
Labels: apiLabels,
Assignee: ToUser(issue.Assignee),
Milestone: ToMilestone(issue.Milestone),
Comments: issue.NumComments,
Created: issue.Created,
Updated: issue.Updated,
}
if issue.IsPull {
apiIssue.PullRequest = &api.PullRequestMeta{
HasMerged: issue.PullRequest.HasMerged,
}
if issue.PullRequest.HasMerged {
apiIssue.PullRequest.Merged = &issue.PullRequest.Merged
}
}
return apiIssue
}
func ToOrganization(org *models.User) *api.Organization {
return &api.Organization{
ID: org.ID,

View file

@ -13,7 +13,6 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/api/v1/convert"
)
func ListIssues(ctx *context.APIContext) {
@ -28,7 +27,12 @@ func ListIssues(ctx *context.APIContext) {
apiIssues := make([]*api.Issue, len(issues))
for i := range issues {
apiIssues[i] = convert.ToIssue(issues[i])
// FIXME: use IssueList to improve performance.
if err = issues[i].LoadAttributes(); err != nil {
ctx.Error(500, "LoadAttributes", err)
return
}
apiIssues[i] = issues[i].APIFormat()
}
ctx.SetLinkHeader(ctx.Repo.Repository.NumIssues, setting.UI.IssuePagingNum)
@ -46,13 +50,13 @@ func GetIssue(ctx *context.APIContext) {
return
}
ctx.JSON(200, convert.ToIssue(issue))
ctx.JSON(200, issue.APIFormat())
}
func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
issue := &models.Issue{
RepoID: ctx.Repo.Repository.ID,
Title: form.Title,
Title: form.Title,
PosterID: ctx.User.ID,
Poster: ctx.User,
Content: form.Body,
@ -83,7 +87,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
if form.Closed {
if err := issue.ChangeStatus(ctx.User, ctx.Repo.Repository, true); err != nil {
ctx.Error(500, "issue.ChangeStatus", err)
ctx.Error(500, "ChangeStatus", err)
return
}
}
@ -95,7 +99,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
ctx.Error(500, "GetIssueByID", err)
return
}
ctx.JSON(201, convert.ToIssue(issue))
ctx.JSON(201, issue.APIFormat())
}
func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
@ -164,5 +168,5 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
ctx.Error(500, "GetIssueByID", err)
return
}
ctx.JSON(201, convert.ToIssue(issue))
ctx.JSON(201, issue.APIFormat())
}

View file

@ -9,7 +9,6 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/convert"
)
func ListIssueLabels(ctx *context.APIContext) {
@ -25,7 +24,7 @@ func ListIssueLabels(ctx *context.APIContext) {
apiLabels := make([]*api.Label, len(issue.Labels))
for i := range issue.Labels {
apiLabels[i] = convert.ToLabel(issue.Labels[i])
apiLabels[i] = issue.Labels[i].APIFormat()
}
ctx.JSON(200, &apiLabels)
}
@ -65,7 +64,7 @@ func AddIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
apiLabels := make([]*api.Label, len(labels))
for i := range labels {
apiLabels[i] = convert.ToLabel(labels[i])
apiLabels[i] = issue.Labels[i].APIFormat()
}
ctx.JSON(200, &apiLabels)
}
@ -139,7 +138,7 @@ func ReplaceIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
apiLabels := make([]*api.Label, len(labels))
for i := range labels {
apiLabels[i] = convert.ToLabel(labels[i])
apiLabels[i] = issue.Labels[i].APIFormat()
}
ctx.JSON(200, &apiLabels)
}

View file

@ -9,7 +9,6 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/convert"
)
func ListLabels(ctx *context.APIContext) {
@ -21,7 +20,7 @@ func ListLabels(ctx *context.APIContext) {
apiLabels := make([]*api.Label, len(labels))
for i := range labels {
apiLabels[i] = convert.ToLabel(labels[i])
apiLabels[i] = labels[i].APIFormat()
}
ctx.JSON(200, &apiLabels)
}
@ -37,7 +36,7 @@ func GetLabel(ctx *context.APIContext) {
return
}
ctx.JSON(200, convert.ToLabel(label))
ctx.JSON(200, label.APIFormat())
}
func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) {
@ -55,7 +54,7 @@ func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) {
ctx.Error(500, "NewLabel", err)
return
}
ctx.JSON(201, convert.ToLabel(label))
ctx.JSON(201, label.APIFormat())
}
func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
@ -84,7 +83,7 @@ func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
ctx.Handle(500, "UpdateLabel", err)
return
}
ctx.JSON(200, convert.ToLabel(label))
ctx.JSON(200, label.APIFormat())
}
func DeleteLabel(ctx *context.APIContext) {

View file

@ -93,12 +93,12 @@ func ListMyRepos(ctx *context.APIContext) {
repos := make([]*api.Repository, numOwnRepos+len(accessibleRepos))
for i := range ownRepos {
repos[i] = convert.ToRepository(ctx.User, ownRepos[i], api.Permission{true, true, true})
repos[i] = ownRepos[i].APIFormat(&api.Permission{true, true, true})
}
i := numOwnRepos
for repo, access := range accessibleRepos {
repos[i] = convert.ToRepository(repo.Owner, repo, api.Permission{
repos[i] = repo.APIFormat(&api.Permission{
Admin: access >= models.ACCESS_MODE_ADMIN,
Push: access >= models.ACCESS_MODE_WRITE,
Pull: true,
@ -135,7 +135,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateR
return
}
ctx.JSON(201, convert.ToRepository(owner, repo, api.Permission{true, true, true}))
ctx.JSON(201, repo.APIFormat(&api.Permission{true, true, true}))
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories#create
@ -235,7 +235,7 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
}
log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName)
ctx.JSON(201, convert.ToRepository(ctxUser, repo, api.Permission{true, true, true}))
ctx.JSON(201, repo.APIFormat(&api.Permission{true, true, true}))
}
func parseOwnerAndRepo(ctx *context.APIContext) (*models.User, *models.Repository) {
@ -264,12 +264,12 @@ func parseOwnerAndRepo(ctx *context.APIContext) (*models.User, *models.Repositor
// https://github.com/gogits/go-gogs-client/wiki/Repositories#get
func Get(ctx *context.APIContext) {
owner, repo := parseOwnerAndRepo(ctx)
_, repo := parseOwnerAndRepo(ctx)
if ctx.Written() {
return
}
ctx.JSON(200, convert.ToRepository(owner, repo, api.Permission{true, true, true}))
ctx.JSON(200, repo.APIFormat(&api.Permission{true, true, true}))
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories#delete

View file

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

View file

@ -11,7 +11,6 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/convert"
)
func Search(ctx *context.APIContext) {
@ -67,9 +66,9 @@ func GetInfo(ctx *context.APIContext) {
if !ctx.IsSigned {
u.Email = ""
}
ctx.JSON(200, convert.ToUser(u))
ctx.JSON(200, u.APIFormat())
}
func GetAuthenticatedUser(ctx *context.APIContext) {
ctx.JSON(200, convert.ToUser(ctx.User))
ctx.JSON(200, ctx.User.APIFormat())
}

View file

@ -20,6 +20,8 @@ import (
"strings"
"time"
git "github.com/gogits/git-module"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
@ -206,7 +208,7 @@ func HTTP(ctx *context.Context) {
RepoName: reponame,
}); err == nil {
go models.HookQueue.Add(repo.ID)
go models.AddTestPullRequestTask(authUser, repo.ID, strings.TrimPrefix(refName, "refs/heads/"), true)
go models.AddTestPullRequestTask(authUser, repo.ID, strings.TrimPrefix(refName, git.BRANCH_PREFIX), true)
}
}

View file

@ -347,6 +347,7 @@ func SlackHooksEditPost(ctx *context.Context, form auth.NewSlackHookForm) {
}
func TestWebhook(ctx *context.Context) {
apiUser := ctx.User.APIFormat()
p := &api.PushPayload{
Ref: git.BRANCH_PREFIX + ctx.Repo.Repository.DefaultBranch,
Before: ctx.Repo.CommitID,
@ -356,27 +357,19 @@ func TestWebhook(ctx *context.Context) {
ID: ctx.Repo.CommitID,
Message: ctx.Repo.Commit.Message(),
URL: ctx.Repo.Repository.FullLink() + "/commit/" + ctx.Repo.CommitID,
Author: &api.PayloadAuthor{
Author: &api.PayloadUser{
Name: ctx.Repo.Commit.Author.Name,
Email: ctx.Repo.Commit.Author.Email,
},
Committer: &api.PayloadCommitter{
Committer: &api.PayloadUser{
Name: ctx.Repo.Commit.Committer.Name,
Email: ctx.Repo.Commit.Committer.Email,
},
},
},
Repo: ctx.Repo.Repository.ComposePayload(),
Pusher: &api.PayloadAuthor{
Name: ctx.User.Name,
Email: ctx.User.Email,
UserName: ctx.User.Name,
},
Sender: &api.PayloadUser{
UserName: ctx.User.Name,
ID: ctx.User.ID,
AvatarUrl: ctx.User.AvatarLink(),
},
Repo: ctx.Repo.Repository.APIFormat(nil),
Pusher: apiUser,
Sender: apiUser,
}
if err := models.PrepareWebhooks(ctx.Repo.Repository, models.HOOK_EVENT_PUSH, p); err != nil {
ctx.Flash.Error("PrepareWebhooks: " + err.Error())

View file

@ -1 +1 @@
0.9.76.0814
0.9.77.0814