Преглед на файлове

Replace convert.To with APIFormat calls

tags/v0.9.99
Unknwon преди 7 години
родител
ревизия
dccb0c15b9

+ 2
- 2
.gopmfile Целия файл

github.com/go-xorm/xorm = commit:c6c7056 github.com/go-xorm/xorm = commit:c6c7056
github.com/gogits/chardet = commit:2404f77 github.com/gogits/chardet = commit:2404f77
github.com/gogits/cron = commit:7f3990a 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/issue9/identicon = commit:d36b545
github.com/jaytaylor/html2text = commit:52d9b78 github.com/jaytaylor/html2text = commit:52d9b78
github.com/kardianos/minwinsvc = commit:cad6b2b github.com/kardianos/minwinsvc = commit:cad6b2b

+ 1
- 1
README.md Целия файл



![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) ![](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 | | Web | UI | Preview |
|:-------------:|:-------:|:-------:| |:-------------:|:-------:|:-------:|

+ 2
- 1
cmd/serve.go Целия файл



"github.com/Unknwon/com" "github.com/Unknwon/com"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
git "github.com/gogits/git-module"
gouuid "github.com/satori/go.uuid" gouuid "github.com/satori/go.uuid"


"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"


// Ask for running deliver hook and test pull request tasks. // Ask for running deliver hook and test pull request tasks.
reqURL := setting.LocalURL + repoUser.Name + "/" + reponame + "/tasks/trigger?branch=" + 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) log.GitLogger.Trace("Trigger task: %s", reqURL)


resp, err := httplib.Head(reqURL).SetTLSClientConfig(&tls.Config{ resp, err := httplib.Head(reqURL).SetTLSClientConfig(&tls.Config{

+ 1
- 1
cmd/web.go Целия файл

{"gopkg.in/ini.v1", ini.Version, "1.8.4"}, {"gopkg.in/ini.v1", ini.Version, "1.8.4"},
{"gopkg.in/macaron.v1", macaron.Version, "1.1.7"}, {"gopkg.in/macaron.v1", macaron.Version, "1.1.7"},
{"github.com/gogits/git-module", git.Version, "0.3.5"}, {"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 { for _, c := range checkers {
if !version.Compare(c.Version(), c.Expected, ">=") { if !version.Compare(c.Version(), c.Expected, ">=") {

+ 2
- 2
glide.lock Целия файл

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

+ 1
- 1
gogs.go Целия файл

"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )


const APP_VER = "0.9.76.0814"
const APP_VER = "0.9.77.0814"


func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

+ 16
- 28
models/action.go Целия файл

type PushCommits struct { type PushCommits struct {
Len int Len int
Commits []*PushCommit Commits []*PushCommit
CompareUrl string
CompareURL string


avatars map[string]string avatars map[string]string
} }
ID: commit.Sha1, ID: commit.Sha1,
Message: commit.Message, Message: commit.Message,
URL: fmt.Sprintf("%s/commit/%s", repoLink, commit.Sha1), URL: fmt.Sprintf("%s/commit/%s", repoLink, commit.Sha1),
Author: &api.PayloadAuthor{
Author: &api.PayloadUser{
Name: commit.AuthorName, Name: commit.AuthorName,
Email: commit.AuthorEmail, Email: commit.AuthorEmail,
UserName: authorUsername, UserName: authorUsername,
}, },
Committer: &api.PayloadCommitter{
Committer: &api.PayloadUser{
Name: commit.CommitterName, Name: commit.CommitterName,
Email: commit.CommitterEmail, Email: commit.CommitterEmail,
UserName: committerUsername, UserName: committerUsername,
} else { } else {
// if not the first commit, set the compareUrl // if not the first commit, set the compareUrl
if !strings.HasPrefix(oldCommitID, "0000000") { if !strings.HasPrefix(oldCommitID, "0000000") {
commit.CompareUrl = repo.ComposeCompareURL(oldCommitID, newCommitID)
commit.CompareURL = repo.ComposeCompareURL(oldCommitID, newCommitID)
} else { } else {
isNewBranch = true isNewBranch = true
} }
} }


refName := git.RefEndName(refFullName) refName := git.RefEndName(refFullName)

if err = NotifyWatchers(&Action{ if err = NotifyWatchers(&Action{
ActUserID: u.ID, ActUserID: u.ID,
ActUserName: userName, ActUserName: userName,
return fmt.Errorf("NotifyWatchers: %v", err) return fmt.Errorf("NotifyWatchers: %v", err)
} }


payloadRepo := repo.ComposePayload()

var pusherEmail, pusherName string
pusher, err := GetUserByName(userName) 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 { switch opType {
case ACTION_COMMIT_REPO: // Push case ACTION_COMMIT_REPO: // Push
if err = PrepareWebhooks(repo, HOOK_EVENT_PUSH, &api.PushPayload{ if err = PrepareWebhooks(repo, HOOK_EVENT_PUSH, &api.PushPayload{
Ref: refFullName, Ref: refFullName,
Before: oldCommitID, Before: oldCommitID,
After: newCommitID, After: newCommitID,
CompareUrl: setting.AppUrl + commit.CompareUrl,
CompareURL: setting.AppUrl + commit.CompareURL,
Commits: commit.ToApiPayloadCommits(repo.FullLink()), 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 { }); err != nil {
return fmt.Errorf("PrepareWebhooks: %v", err) return fmt.Errorf("PrepareWebhooks: %v", err)
} }
return PrepareWebhooks(repo, HOOK_EVENT_CREATE, &api.CreatePayload{ return PrepareWebhooks(repo, HOOK_EVENT_CREATE, &api.CreatePayload{
Ref: refName, Ref: refName,
RefType: "branch", RefType: "branch",
Repo: payloadRepo,
Sender: payloadSender,
Repo: apiRepo,
Sender: apiPusher,
}) })
} }


return PrepareWebhooks(repo, HOOK_EVENT_CREATE, &api.CreatePayload{ return PrepareWebhooks(repo, HOOK_EVENT_CREATE, &api.CreatePayload{
Ref: refName, Ref: refName,
RefType: "tag", RefType: "tag",
Repo: payloadRepo,
Sender: payloadSender,
Repo: apiRepo,
Sender: apiPusher,
}) })
} }



+ 5
- 13
models/pull.go Целия файл

l.PushFront(mergeCommit) l.PushFront(mergeCommit)


p := &api.PushPayload{ p := &api.PushPayload{
Ref: "refs/heads/" + pr.BaseBranch,
Ref: git.BRANCH_PREFIX + pr.BaseBranch,
Before: pr.MergeBase, Before: pr.MergeBase,
After: pr.MergedCommitID, 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()), 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 { if err = PrepareWebhooks(pr.BaseRepo, HOOK_EVENT_PUSH, p); err != nil {
return fmt.Errorf("PrepareWebhooks: %v", err) return fmt.Errorf("PrepareWebhooks: %v", err)

+ 0
- 22
models/repo.go Целия файл

return nil 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) { func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) {
has, err := e.Get(&Repository{ has, err := e.Get(&Repository{
OwnerID: u.ID, OwnerID: u.ID,

+ 8
- 8
models/webhook_slack.go Целия файл

// created tag/branch // created tag/branch
refName := git.RefEndName(p.Ref) 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) text := fmt.Sprintf("[%s:%s] %s created by %s", repoLink, refLink, p.RefType, p.Sender.UserName)


return &SlackPayload{ return &SlackPayload{
} else { } else {
commitDesc = fmt.Sprintf("%d new commits", len(p.Commits)) 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 { } else {
commitString = commitDesc 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 var attachmentText string
// for each commit, generate attachment text // for each commit, generate attachment text


func getSlackPullRequestPayload(p *api.PullRequestPayload, slack *SlackMeta) (*SlackPayload, error) { func getSlackPullRequestPayload(p *api.PullRequestPayload, slack *SlackMeta) (*SlackPayload, error) {
senderLink := SlackLinkFormatter(setting.AppUrl+p.Sender.UserName, p.Sender.UserName) 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)) fmt.Sprintf("#%d %s", p.Index, p.PullRequest.Title))
var text, title, attachmentText string var text, title, attachmentText string
switch p.Action { switch p.Action {

+ 2
- 3
routers/api/v1/admin/user.go Целия файл

"github.com/gogits/gogs/modules/context" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/api/v1/convert"
"github.com/gogits/gogs/routers/api/v1/user" "github.com/gogits/gogs/routers/api/v1/user"
) )


models.SendRegisterNotifyMail(ctx.Context.Context, u) 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 // https://github.com/gogits/go-gogs-client/wiki/Administration-Users#edit-an-existing-user
} }
log.Trace("Account profile updated by admin (%s): %s", ctx.User.Name, u.Name) 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 // https://github.com/gogits/go-gogs-client/wiki/Administration-Users#delete-a-user

+ 2
- 101
routers/api/v1/convert/convert.go Целия файл

api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"


"github.com/gogits/gogs/models" "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 { func ToEmail(email *models.EmailAddress) *api.Email {
return &api.Email{ return &api.Email{
Email: email.Email, Email: email.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 { func ToBranch(b *models.Branch, c *git.Commit) *api.Branch {
return &api.Branch{ return &api.Branch{
Name: b.Name, Name: b.Name,
ID: c.ID.String(), ID: c.ID.String(),
Message: c.Message(), Message: c.Message(),
URL: "Not implemented", URL: "Not implemented",
Author: &api.PayloadAuthor{
Author: &api.PayloadUser{
Name: c.Author.Name, Name: c.Author.Name,
Email: c.Author.Email, Email: c.Author.Email,
UserName: authorUsername, UserName: authorUsername,
}, },
Committer: &api.PayloadCommitter{
Committer: &api.PayloadUser{
Name: c.Committer.Name, Name: c.Committer.Name,
Email: c.Committer.Email, Email: c.Committer.Email,
UserName: committerUsername, UserName: committerUsername,
} }
} }


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 { func ToOrganization(org *models.User) *api.Organization {
return &api.Organization{ return &api.Organization{
ID: org.ID, ID: org.ID,

+ 11
- 7
routers/api/v1/repo/issue.go Целия файл

"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/context" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/api/v1/convert"
) )


func ListIssues(ctx *context.APIContext) { func ListIssues(ctx *context.APIContext) {


apiIssues := make([]*api.Issue, len(issues)) apiIssues := make([]*api.Issue, len(issues))
for i := range 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) ctx.SetLinkHeader(ctx.Repo.Repository.NumIssues, setting.UI.IssuePagingNum)
return return
} }


ctx.JSON(200, convert.ToIssue(issue))
ctx.JSON(200, issue.APIFormat())
} }


func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) { func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
issue := &models.Issue{ issue := &models.Issue{
RepoID: ctx.Repo.Repository.ID, RepoID: ctx.Repo.Repository.ID,
Title: form.Title,
Title: form.Title,
PosterID: ctx.User.ID, PosterID: ctx.User.ID,
Poster: ctx.User, Poster: ctx.User,
Content: form.Body, Content: form.Body,


if form.Closed { if form.Closed {
if err := issue.ChangeStatus(ctx.User, ctx.Repo.Repository, true); err != nil { if err := issue.ChangeStatus(ctx.User, ctx.Repo.Repository, true); err != nil {
ctx.Error(500, "issue.ChangeStatus", err)
ctx.Error(500, "ChangeStatus", err)
return return
} }
} }
ctx.Error(500, "GetIssueByID", err) ctx.Error(500, "GetIssueByID", err)
return return
} }
ctx.JSON(201, convert.ToIssue(issue))
ctx.JSON(201, issue.APIFormat())
} }


func EditIssue(ctx *context.APIContext, form api.EditIssueOption) { func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
ctx.Error(500, "GetIssueByID", err) ctx.Error(500, "GetIssueByID", err)
return return
} }
ctx.JSON(201, convert.ToIssue(issue))
ctx.JSON(201, issue.APIFormat())
} }

+ 3
- 4
routers/api/v1/repo/issue_label.go Целия файл



"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/context" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/convert"
) )


func ListIssueLabels(ctx *context.APIContext) { func ListIssueLabels(ctx *context.APIContext) {


apiLabels := make([]*api.Label, len(issue.Labels)) apiLabels := make([]*api.Label, len(issue.Labels))
for i := range issue.Labels { for i := range issue.Labels {
apiLabels[i] = convert.ToLabel(issue.Labels[i])
apiLabels[i] = issue.Labels[i].APIFormat()
} }
ctx.JSON(200, &apiLabels) ctx.JSON(200, &apiLabels)
} }


apiLabels := make([]*api.Label, len(labels)) apiLabels := make([]*api.Label, len(labels))
for i := range labels { for i := range labels {
apiLabels[i] = convert.ToLabel(labels[i])
apiLabels[i] = issue.Labels[i].APIFormat()
} }
ctx.JSON(200, &apiLabels) ctx.JSON(200, &apiLabels)
} }


apiLabels := make([]*api.Label, len(labels)) apiLabels := make([]*api.Label, len(labels))
for i := range labels { for i := range labels {
apiLabels[i] = convert.ToLabel(labels[i])
apiLabels[i] = issue.Labels[i].APIFormat()
} }
ctx.JSON(200, &apiLabels) ctx.JSON(200, &apiLabels)
} }

+ 4
- 5
routers/api/v1/repo/label.go Целия файл



"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/context" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/convert"
) )


func ListLabels(ctx *context.APIContext) { func ListLabels(ctx *context.APIContext) {


apiLabels := make([]*api.Label, len(labels)) apiLabels := make([]*api.Label, len(labels))
for i := range labels { for i := range labels {
apiLabels[i] = convert.ToLabel(labels[i])
apiLabels[i] = labels[i].APIFormat()
} }
ctx.JSON(200, &apiLabels) ctx.JSON(200, &apiLabels)
} }
return return
} }


ctx.JSON(200, convert.ToLabel(label))
ctx.JSON(200, label.APIFormat())
} }


func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) { func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) {
ctx.Error(500, "NewLabel", err) ctx.Error(500, "NewLabel", err)
return return
} }
ctx.JSON(201, convert.ToLabel(label))
ctx.JSON(201, label.APIFormat())
} }


func EditLabel(ctx *context.APIContext, form api.EditLabelOption) { func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
ctx.Handle(500, "UpdateLabel", err) ctx.Handle(500, "UpdateLabel", err)
return return
} }
ctx.JSON(200, convert.ToLabel(label))
ctx.JSON(200, label.APIFormat())
} }


func DeleteLabel(ctx *context.APIContext) { func DeleteLabel(ctx *context.APIContext) {

+ 6
- 6
routers/api/v1/repo/repo.go Целия файл



repos := make([]*api.Repository, numOwnRepos+len(accessibleRepos)) repos := make([]*api.Repository, numOwnRepos+len(accessibleRepos))
for i := range ownRepos { 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 i := numOwnRepos


for repo, access := range accessibleRepos { 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, Admin: access >= models.ACCESS_MODE_ADMIN,
Push: access >= models.ACCESS_MODE_WRITE, Push: access >= models.ACCESS_MODE_WRITE,
Pull: true, Pull: true,
return 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 // https://github.com/gogits/go-gogs-client/wiki/Repositories#create
} }


log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName) 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) { func parseOwnerAndRepo(ctx *context.APIContext) (*models.User, *models.Repository) {


// https://github.com/gogits/go-gogs-client/wiki/Repositories#get // https://github.com/gogits/go-gogs-client/wiki/Repositories#get
func Get(ctx *context.APIContext) { func Get(ctx *context.APIContext) {
owner, repo := parseOwnerAndRepo(ctx)
_, repo := parseOwnerAndRepo(ctx)
if ctx.Written() { if ctx.Written() {
return 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 // https://github.com/gogits/go-gogs-client/wiki/Repositories#delete

+ 1
- 2
routers/api/v1/user/follower.go Целия файл



"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/context" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/convert"
) )


func responseApiUsers(ctx *context.APIContext, users []*models.User) { func responseApiUsers(ctx *context.APIContext, users []*models.User) {
apiUsers := make([]*api.User, len(users)) apiUsers := make([]*api.User, len(users))
for i := range users { for i := range users {
apiUsers[i] = convert.ToUser(users[i])
apiUsers[i] = users[i].APIFormat()
} }
ctx.JSON(200, &apiUsers) ctx.JSON(200, &apiUsers)
} }

+ 2
- 3
routers/api/v1/user/user.go Целия файл



"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/context" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/convert"
) )


func Search(ctx *context.APIContext) { func Search(ctx *context.APIContext) {
if !ctx.IsSigned { if !ctx.IsSigned {
u.Email = "" u.Email = ""
} }
ctx.JSON(200, convert.ToUser(u))
ctx.JSON(200, u.APIFormat())
} }


func GetAuthenticatedUser(ctx *context.APIContext) { func GetAuthenticatedUser(ctx *context.APIContext) {
ctx.JSON(200, convert.ToUser(ctx.User))
ctx.JSON(200, ctx.User.APIFormat())
} }

+ 3
- 1
routers/repo/http.go Целия файл

"strings" "strings"
"time" "time"


git "github.com/gogits/git-module"

"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context" "github.com/gogits/gogs/modules/context"
RepoName: reponame, RepoName: reponame,
}); err == nil { }); err == nil {
go models.HookQueue.Add(repo.ID) 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)
} }


} }

+ 6
- 13
routers/repo/webhook.go Целия файл

} }


func TestWebhook(ctx *context.Context) { func TestWebhook(ctx *context.Context) {
apiUser := ctx.User.APIFormat()
p := &api.PushPayload{ p := &api.PushPayload{
Ref: git.BRANCH_PREFIX + ctx.Repo.Repository.DefaultBranch, Ref: git.BRANCH_PREFIX + ctx.Repo.Repository.DefaultBranch,
Before: ctx.Repo.CommitID, Before: ctx.Repo.CommitID,
ID: ctx.Repo.CommitID, ID: ctx.Repo.CommitID,
Message: ctx.Repo.Commit.Message(), Message: ctx.Repo.Commit.Message(),
URL: ctx.Repo.Repository.FullLink() + "/commit/" + ctx.Repo.CommitID, URL: ctx.Repo.Repository.FullLink() + "/commit/" + ctx.Repo.CommitID,
Author: &api.PayloadAuthor{
Author: &api.PayloadUser{
Name: ctx.Repo.Commit.Author.Name, Name: ctx.Repo.Commit.Author.Name,
Email: ctx.Repo.Commit.Author.Email, Email: ctx.Repo.Commit.Author.Email,
}, },
Committer: &api.PayloadCommitter{
Committer: &api.PayloadUser{
Name: ctx.Repo.Commit.Committer.Name, Name: ctx.Repo.Commit.Committer.Name,
Email: ctx.Repo.Commit.Committer.Email, 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 { if err := models.PrepareWebhooks(ctx.Repo.Repository, models.HOOK_EVENT_PUSH, p); err != nil {
ctx.Flash.Error("PrepareWebhooks: " + err.Error()) ctx.Flash.Error("PrepareWebhooks: " + err.Error())

+ 1
- 1
templates/.VERSION Целия файл

0.9.76.0814
0.9.77.0814

Loading…
Отказ
Запис