summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-10-17 06:23:08 +0200
committerGitHub <noreply@github.com>2020-10-17 00:23:08 -0400
commitd453533beb197d25b25530dc5f0e3c3c0742d8d1 (patch)
tree6d66e1163333344d91af63e9ab50a82367470b8f /modules
parent131278ff222f1a8580f20e6bbdff405341403042 (diff)
downloadgitea-d453533beb197d25b25530dc5f0e3c3c0742d8d1.tar.gz
gitea-d453533beb197d25b25530dc5f0e3c3c0742d8d1.zip
[Refactor] Move APIFormat functions into convert package (#12856)
* USER APIFormat -> ToUser * Migrate more and mark APIFormat deprecated * models.Comment APIFormat() -> convert.ToComment * models.Release APIFormat() -> convert.ToRelease * models.Attachments APIFormat() -> convert.ToReleaseAttachments * models.CommitStatus APIFormat() -> convert.ToCommitStatus * finish migration to convert.ToUser * Move Test * Imprufe Test * fix test Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'modules')
-rw-r--r--modules/convert/convert.go21
-rw-r--r--modules/convert/git_commit.go8
-rw-r--r--modules/convert/issue.go6
-rw-r--r--modules/convert/issue_comment.go24
-rw-r--r--modules/convert/pull.go2
-rw-r--r--modules/convert/release.go48
-rw-r--r--modules/convert/user.go3
-rw-r--r--modules/convert/user_test.go28
-rw-r--r--modules/notification/webhook/webhook.go90
9 files changed, 177 insertions, 53 deletions
diff --git a/modules/convert/convert.go b/modules/convert/convert.go
index ec676002b9..e81df0c0c3 100644
--- a/modules/convert/convert.go
+++ b/modules/convert/convert.go
@@ -339,3 +339,24 @@ func ToOAuth2Application(app *models.OAuth2Application) *api.OAuth2Application {
Created: app.CreatedUnix.AsTime(),
}
}
+
+// ToCommitStatus converts models.CommitStatus to api.Status
+func ToCommitStatus(status *models.CommitStatus) *api.Status {
+ apiStatus := &api.Status{
+ Created: status.CreatedUnix.AsTime(),
+ Updated: status.CreatedUnix.AsTime(),
+ State: api.StatusState(status.State),
+ TargetURL: status.TargetURL,
+ Description: status.Description,
+ ID: status.Index,
+ URL: status.APIURL(),
+ Context: status.Context,
+ }
+
+ if status.CreatorID != 0 {
+ creator, _ := models.GetUserByID(status.CreatorID)
+ apiStatus.Creator = ToUser(creator, false, false)
+ }
+
+ return apiStatus
+}
diff --git a/modules/convert/git_commit.go b/modules/convert/git_commit.go
index 86d6dae961..87dfb51e70 100644
--- a/modules/convert/git_commit.go
+++ b/modules/convert/git_commit.go
@@ -86,13 +86,13 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]
}
if ok {
- apiAuthor = cacheAuthor.APIFormat()
+ apiAuthor = ToUser(cacheAuthor, false, false)
} else {
author, err := models.GetUserByEmail(commit.Author.Email)
if err != nil && !models.IsErrUserNotExist(err) {
return nil, err
} else if err == nil {
- apiAuthor = author.APIFormat()
+ apiAuthor = ToUser(author, false, false)
if userCache != nil {
userCache[commit.Author.Email] = author
}
@@ -108,13 +108,13 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]
}
if ok {
- apiCommitter = cacheCommitter.APIFormat()
+ apiCommitter = ToUser(cacheCommitter, false, false)
} else {
committer, err := models.GetUserByEmail(commit.Committer.Email)
if err != nil && !models.IsErrUserNotExist(err) {
return nil, err
} else if err == nil {
- apiCommitter = committer.APIFormat()
+ apiCommitter = ToUser(committer, false, false)
if userCache != nil {
userCache[commit.Committer.Email] = committer
}
diff --git a/modules/convert/issue.go b/modules/convert/issue.go
index 724ec8ffcf..f34656b47c 100644
--- a/modules/convert/issue.go
+++ b/modules/convert/issue.go
@@ -31,7 +31,7 @@ func ToAPIIssue(issue *models.Issue) *api.Issue {
URL: issue.APIURL(),
HTMLURL: issue.HTMLURL(),
Index: issue.Index,
- Poster: issue.Poster.APIFormat(),
+ Poster: ToUser(issue.Poster, false, false),
Title: issue.Title,
Body: issue.Content,
Labels: ToLabelList(issue.Labels),
@@ -65,9 +65,9 @@ func ToAPIIssue(issue *models.Issue) *api.Issue {
}
if len(issue.Assignees) > 0 {
for _, assignee := range issue.Assignees {
- apiIssue.Assignees = append(apiIssue.Assignees, assignee.APIFormat())
+ apiIssue.Assignees = append(apiIssue.Assignees, ToUser(assignee, false, false))
}
- apiIssue.Assignee = issue.Assignees[0].APIFormat() // For compatibility, we're keeping the first assignee as `apiIssue.Assignee`
+ apiIssue.Assignee = ToUser(issue.Assignees[0], false, false) // For compatibility, we're keeping the first assignee as `apiIssue.Assignee`
}
if issue.IsPull {
if err := issue.LoadPullRequest(); err != nil {
diff --git a/modules/convert/issue_comment.go b/modules/convert/issue_comment.go
new file mode 100644
index 0000000000..cf65c876d3
--- /dev/null
+++ b/modules/convert/issue_comment.go
@@ -0,0 +1,24 @@
+// Copyright 2020 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package convert
+
+import (
+ "code.gitea.io/gitea/models"
+ api "code.gitea.io/gitea/modules/structs"
+)
+
+// ToComment converts a models.Comment to the api.Comment format
+func ToComment(c *models.Comment) *api.Comment {
+ return &api.Comment{
+ ID: c.ID,
+ Poster: ToUser(c.Poster, false, false),
+ HTMLURL: c.HTMLURL(),
+ IssueURL: c.IssueURL(),
+ PRURL: c.PRURL(),
+ Body: c.Content,
+ Created: c.CreatedUnix.AsTime(),
+ Updated: c.UpdatedUnix.AsTime(),
+ }
+}
diff --git a/modules/convert/pull.go b/modules/convert/pull.go
index 2fa22efcb3..e522bee787 100644
--- a/modules/convert/pull.go
+++ b/modules/convert/pull.go
@@ -141,7 +141,7 @@ func ToAPIPullRequest(pr *models.PullRequest) *api.PullRequest {
if pr.HasMerged {
apiPullRequest.Merged = pr.MergedUnix.AsTimePtr()
apiPullRequest.MergedCommitID = &pr.MergedCommitID
- apiPullRequest.MergedBy = pr.Merger.APIFormat()
+ apiPullRequest.MergedBy = ToUser(pr.Merger, false, false)
}
return apiPullRequest
diff --git a/modules/convert/release.go b/modules/convert/release.go
new file mode 100644
index 0000000000..d9def89637
--- /dev/null
+++ b/modules/convert/release.go
@@ -0,0 +1,48 @@
+// Copyright 2020 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package convert
+
+import (
+ "code.gitea.io/gitea/models"
+ api "code.gitea.io/gitea/modules/structs"
+)
+
+// ToRelease convert a models.Release to api.Release
+func ToRelease(r *models.Release) *api.Release {
+ assets := make([]*api.Attachment, 0)
+ for _, att := range r.Attachments {
+ assets = append(assets, ToReleaseAttachment(att))
+ }
+ return &api.Release{
+ ID: r.ID,
+ TagName: r.TagName,
+ Target: r.Target,
+ Title: r.Title,
+ Note: r.Note,
+ URL: r.APIURL(),
+ HTMLURL: r.HTMLURL(),
+ TarURL: r.TarURL(),
+ ZipURL: r.ZipURL(),
+ IsDraft: r.IsDraft,
+ IsPrerelease: r.IsPrerelease,
+ CreatedAt: r.CreatedUnix.AsTime(),
+ PublishedAt: r.CreatedUnix.AsTime(),
+ Publisher: ToUser(r.Publisher, false, false),
+ Attachments: assets,
+ }
+}
+
+// ToReleaseAttachment converts models.Attachment to api.Attachment
+func ToReleaseAttachment(a *models.Attachment) *api.Attachment {
+ return &api.Attachment{
+ ID: a.ID,
+ Name: a.Name,
+ Created: a.CreatedUnix.AsTime(),
+ DownloadCount: a.DownloadCount,
+ Size: a.Size,
+ UUID: a.UUID,
+ DownloadURL: a.DownloadURL(),
+ }
+}
diff --git a/modules/convert/user.go b/modules/convert/user.go
index c75a8aac52..010c92b969 100644
--- a/modules/convert/user.go
+++ b/modules/convert/user.go
@@ -13,6 +13,9 @@ import (
// ToUser convert models.User to api.User
// signed shall only be set if requester is logged in. authed shall only be set if user is site admin or user himself
func ToUser(user *models.User, signed, authed bool) *api.User {
+ if user == nil {
+ return nil
+ }
result := &api.User{
ID: user.ID,
UserName: user.Name,
diff --git a/modules/convert/user_test.go b/modules/convert/user_test.go
new file mode 100644
index 0000000000..eff60d5183
--- /dev/null
+++ b/modules/convert/user_test.go
@@ -0,0 +1,28 @@
+// Copyright 2020 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package convert
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/models"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestUser_ToUser(t *testing.T) {
+
+ user1 := models.AssertExistsAndLoadBean(t, &models.User{ID: 1, IsAdmin: true}).(*models.User)
+
+ apiUser := ToUser(user1, true, true)
+ assert.True(t, apiUser.IsAdmin)
+
+ user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2, IsAdmin: false}).(*models.User)
+
+ apiUser = ToUser(user2, true, true)
+ assert.False(t, apiUser.IsAdmin)
+
+ apiUser = ToUser(user1, false, false)
+ assert.False(t, apiUser.IsAdmin)
+}
diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go
index c8b6bae724..231112ec4c 100644
--- a/modules/notification/webhook/webhook.go
+++ b/modules/notification/webhook/webhook.go
@@ -53,7 +53,7 @@ func (m *webhookNotifier) NotifyIssueClearLabels(doer *models.User, issue *model
Index: issue.Index,
PullRequest: convert.ToAPIPullRequest(issue.PullRequest),
Repository: issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
})
} else {
err = webhook_module.PrepareWebhooks(issue.Repo, models.HookEventIssueLabel, &api.IssuePayload{
@@ -61,7 +61,7 @@ func (m *webhookNotifier) NotifyIssueClearLabels(doer *models.User, issue *model
Index: issue.Index,
Issue: convert.ToAPIIssue(issue),
Repository: issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
})
}
if err != nil {
@@ -77,7 +77,7 @@ func (m *webhookNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo
if err := webhook_module.PrepareWebhooks(oldRepo, models.HookEventFork, &api.ForkPayload{
Forkee: oldRepo.APIFormat(oldMode),
Repo: repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
}); err != nil {
log.Error("PrepareWebhooks [repo_id: %d]: %v", oldRepo.ID, err)
}
@@ -89,8 +89,8 @@ func (m *webhookNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo
if err := webhook_module.PrepareWebhooks(repo, models.HookEventRepository, &api.RepositoryPayload{
Action: api.HookRepoCreated,
Repository: repo.APIFormat(models.AccessModeOwner),
- Organization: u.APIFormat(),
- Sender: doer.APIFormat(),
+ Organization: convert.ToUser(u, false, false),
+ Sender: convert.ToUser(doer, false, false),
}); err != nil {
log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
}
@@ -102,8 +102,8 @@ func (m *webhookNotifier) NotifyCreateRepository(doer *models.User, u *models.Us
if err := webhook_module.PrepareWebhooks(repo, models.HookEventRepository, &api.RepositoryPayload{
Action: api.HookRepoCreated,
Repository: repo.APIFormat(models.AccessModeOwner),
- Organization: u.APIFormat(),
- Sender: doer.APIFormat(),
+ Organization: convert.ToUser(u, false, false),
+ Sender: convert.ToUser(doer, false, false),
}); err != nil {
log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
}
@@ -115,8 +115,8 @@ func (m *webhookNotifier) NotifyDeleteRepository(doer *models.User, repo *models
if err := webhook_module.PrepareWebhooks(repo, models.HookEventRepository, &api.RepositoryPayload{
Action: api.HookRepoDeleted,
Repository: repo.APIFormat(models.AccessModeOwner),
- Organization: u.APIFormat(),
- Sender: doer.APIFormat(),
+ Organization: convert.ToUser(u, false, false),
+ Sender: convert.ToUser(doer, false, false),
}); err != nil {
log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
}
@@ -135,7 +135,7 @@ func (m *webhookNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *mo
Index: issue.Index,
PullRequest: convert.ToAPIPullRequest(issue.PullRequest),
Repository: issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
}
if removed {
apiPullRequest.Action = api.HookIssueUnassigned
@@ -153,7 +153,7 @@ func (m *webhookNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *mo
Index: issue.Index,
Issue: convert.ToAPIIssue(issue),
Repository: issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
}
if removed {
apiIssue.Action = api.HookIssueUnassigned
@@ -187,7 +187,7 @@ func (m *webhookNotifier) NotifyIssueChangeTitle(doer *models.User, issue *model
},
PullRequest: convert.ToAPIPullRequest(issue.PullRequest),
Repository: issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
})
} else {
err = webhook_module.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
@@ -200,7 +200,7 @@ func (m *webhookNotifier) NotifyIssueChangeTitle(doer *models.User, issue *model
},
Issue: convert.ToAPIIssue(issue),
Repository: issue.Repo.APIFormat(mode),
- Sender: issue.Poster.APIFormat(),
+ Sender: convert.ToUser(issue.Poster, false, false),
})
}
@@ -222,7 +222,7 @@ func (m *webhookNotifier) NotifyIssueChangeStatus(doer *models.User, issue *mode
Index: issue.Index,
PullRequest: convert.ToAPIPullRequest(issue.PullRequest),
Repository: issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
}
if isClosed {
apiPullRequest.Action = api.HookIssueClosed
@@ -235,7 +235,7 @@ func (m *webhookNotifier) NotifyIssueChangeStatus(doer *models.User, issue *mode
Index: issue.Index,
Issue: convert.ToAPIIssue(issue),
Repository: issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
}
if isClosed {
apiIssue.Action = api.HookIssueClosed
@@ -265,7 +265,7 @@ func (m *webhookNotifier) NotifyNewIssue(issue *models.Issue) {
Index: issue.Index,
Issue: convert.ToAPIIssue(issue),
Repository: issue.Repo.APIFormat(mode),
- Sender: issue.Poster.APIFormat(),
+ Sender: convert.ToUser(issue.Poster, false, false),
}); err != nil {
log.Error("PrepareWebhooks: %v", err)
}
@@ -291,7 +291,7 @@ func (m *webhookNotifier) NotifyNewPullRequest(pull *models.PullRequest) {
Index: pull.Issue.Index,
PullRequest: convert.ToAPIPullRequest(pull),
Repository: pull.Issue.Repo.APIFormat(mode),
- Sender: pull.Issue.Poster.APIFormat(),
+ Sender: convert.ToUser(pull.Issue.Poster, false, false),
}); err != nil {
log.Error("PrepareWebhooks: %v", err)
}
@@ -312,7 +312,7 @@ func (m *webhookNotifier) NotifyIssueChangeContent(doer *models.User, issue *mod
},
PullRequest: convert.ToAPIPullRequest(issue.PullRequest),
Repository: issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
})
} else {
err = webhook_module.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
@@ -325,7 +325,7 @@ func (m *webhookNotifier) NotifyIssueChangeContent(doer *models.User, issue *mod
},
Issue: convert.ToAPIIssue(issue),
Repository: issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
})
}
if err != nil {
@@ -355,28 +355,28 @@ func (m *webhookNotifier) NotifyUpdateComment(doer *models.User, c *models.Comme
err = webhook_module.PrepareWebhooks(c.Issue.Repo, models.HookEventPullRequestComment, &api.IssueCommentPayload{
Action: api.HookIssueCommentEdited,
Issue: convert.ToAPIIssue(c.Issue),
- Comment: c.APIFormat(),
+ Comment: convert.ToComment(c),
Changes: &api.ChangesPayload{
Body: &api.ChangesFromPayload{
From: oldContent,
},
},
Repository: c.Issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
IsPull: true,
})
} else {
err = webhook_module.PrepareWebhooks(c.Issue.Repo, models.HookEventIssueComment, &api.IssueCommentPayload{
Action: api.HookIssueCommentEdited,
Issue: convert.ToAPIIssue(c.Issue),
- Comment: c.APIFormat(),
+ Comment: convert.ToComment(c),
Changes: &api.ChangesPayload{
Body: &api.ChangesFromPayload{
From: oldContent,
},
},
Repository: c.Issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
IsPull: false,
})
}
@@ -395,18 +395,18 @@ func (m *webhookNotifier) NotifyCreateIssueComment(doer *models.User, repo *mode
err = webhook_module.PrepareWebhooks(issue.Repo, models.HookEventPullRequestComment, &api.IssueCommentPayload{
Action: api.HookIssueCommentCreated,
Issue: convert.ToAPIIssue(issue),
- Comment: comment.APIFormat(),
+ Comment: convert.ToComment(comment),
Repository: repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
IsPull: true,
})
} else {
err = webhook_module.PrepareWebhooks(issue.Repo, models.HookEventIssueComment, &api.IssueCommentPayload{
Action: api.HookIssueCommentCreated,
Issue: convert.ToAPIIssue(issue),
- Comment: comment.APIFormat(),
+ Comment: convert.ToComment(comment),
Repository: repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
IsPull: false,
})
}
@@ -439,18 +439,18 @@ func (m *webhookNotifier) NotifyDeleteComment(doer *models.User, comment *models
err = webhook_module.PrepareWebhooks(comment.Issue.Repo, models.HookEventPullRequestComment, &api.IssueCommentPayload{
Action: api.HookIssueCommentDeleted,
Issue: convert.ToAPIIssue(comment.Issue),
- Comment: comment.APIFormat(),
+ Comment: convert.ToComment(comment),
Repository: comment.Issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
IsPull: true,
})
} else {
err = webhook_module.PrepareWebhooks(comment.Issue.Repo, models.HookEventIssueComment, &api.IssueCommentPayload{
Action: api.HookIssueCommentDeleted,
Issue: convert.ToAPIIssue(comment.Issue),
- Comment: comment.APIFormat(),
+ Comment: convert.ToComment(comment),
Repository: comment.Issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
IsPull: false,
})
}
@@ -490,7 +490,7 @@ func (m *webhookNotifier) NotifyIssueChangeLabels(doer *models.User, issue *mode
Index: issue.Index,
PullRequest: convert.ToAPIPullRequest(issue.PullRequest),
Repository: issue.Repo.APIFormat(models.AccessModeNone),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
})
} else {
err = webhook_module.PrepareWebhooks(issue.Repo, models.HookEventIssueLabel, &api.IssuePayload{
@@ -498,7 +498,7 @@ func (m *webhookNotifier) NotifyIssueChangeLabels(doer *models.User, issue *mode
Index: issue.Index,
Issue: convert.ToAPIIssue(issue),
Repository: issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
})
}
if err != nil {
@@ -532,7 +532,7 @@ func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *m
Index: issue.Index,
PullRequest: convert.ToAPIPullRequest(issue.PullRequest),
Repository: issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
})
} else {
err = webhook_module.PrepareWebhooks(issue.Repo, models.HookEventIssueMilestone, &api.IssuePayload{
@@ -540,7 +540,7 @@ func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *m
Index: issue.Index,
Issue: convert.ToAPIIssue(issue),
Repository: issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
})
}
if err != nil {
@@ -549,7 +549,7 @@ func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *m
}
func (m *webhookNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *repository.PushCommits) {
- apiPusher := pusher.APIFormat()
+ apiPusher := convert.ToUser(pusher, false, false)
apiCommits, err := commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL())
if err != nil {
log.Error("commits.ToAPIPayloadCommits failed: %v", err)
@@ -598,7 +598,7 @@ func (*webhookNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *mod
Index: pr.Issue.Index,
PullRequest: convert.ToAPIPullRequest(pr),
Repository: pr.Issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
Action: api.HookIssueClosed,
}
@@ -631,7 +631,7 @@ func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(doer *models.User,
},
PullRequest: convert.ToAPIPullRequest(issue.PullRequest),
Repository: issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
})
if err != nil {
@@ -670,7 +670,7 @@ func (m *webhookNotifier) NotifyPullRequestReview(pr *models.PullRequest, review
Index: review.Issue.Index,
PullRequest: convert.ToAPIPullRequest(pr),
Repository: review.Issue.Repo.APIFormat(mode),
- Sender: review.Reviewer.APIFormat(),
+ Sender: convert.ToUser(review.Reviewer, false, false),
Review: &api.ReviewPayload{
Type: string(reviewHookType),
Content: review.Content,
@@ -681,7 +681,7 @@ func (m *webhookNotifier) NotifyPullRequestReview(pr *models.PullRequest, review
}
func (m *webhookNotifier) NotifyCreateRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
- apiPusher := pusher.APIFormat()
+ apiPusher := convert.ToUser(pusher, false, false)
apiRepo := repo.APIFormat(models.AccessModeNone)
refName := git.RefEndName(refFullName)
@@ -725,14 +725,14 @@ func (m *webhookNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *m
Index: pr.Issue.Index,
PullRequest: convert.ToAPIPullRequest(pr),
Repository: pr.Issue.Repo.APIFormat(models.AccessModeNone),
- Sender: doer.APIFormat(),
+ Sender: convert.ToUser(doer, false, false),
}); err != nil {
log.Error("PrepareWebhooks [pull_id: %v]: %v", pr.ID, err)
}
}
func (m *webhookNotifier) NotifyDeleteRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
- apiPusher := pusher.APIFormat()
+ apiPusher := convert.ToUser(pusher, false, false)
apiRepo := repo.APIFormat(models.AccessModeNone)
refName := git.RefEndName(refFullName)
@@ -756,9 +756,9 @@ func sendReleaseHook(doer *models.User, rel *models.Release, action api.HookRele
mode, _ := models.AccessLevel(rel.Publisher, rel.Repo)
if err := webhook_module.PrepareWebhooks(rel.Repo, models.HookEventRelease, &api.ReleasePayload{
Action: action,
- Release: rel.APIFormat(),
+ Release: convert.ToRelease(rel),
Repository: rel.Repo.APIFormat(mode),
- Sender: rel.Publisher.APIFormat(),
+ Sender: convert.ToUser(rel.Publisher, false, false),
}); err != nil {
log.Error("PrepareWebhooks: %v", err)
}
@@ -777,7 +777,7 @@ func (m *webhookNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Rel
}
func (m *webhookNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *repository.PushCommits) {
- apiPusher := pusher.APIFormat()
+ apiPusher := convert.ToUser(pusher, false, false)
apiCommits, err := commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL())
if err != nil {
log.Error("commits.ToAPIPayloadCommits failed: %v", err)