|
|
@ -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, |
|
|
|