mirror of
https://github.com/gogs/gogs.git
synced 2025-05-31 11:42:13 +00:00
webhook: match email with real user in database for test delivery (#3652)
This commit is contained in:
parent
f4aedda13a
commit
279e475b89
@ -347,6 +347,8 @@ func SlackHooksEditPost(ctx *context.Context, form auth.NewSlackHookForm) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWebhook(ctx *context.Context) {
|
func TestWebhook(ctx *context.Context) {
|
||||||
|
var authorUsername, committerUsername string
|
||||||
|
|
||||||
// Grab latest commit or fake one if it's empty repository.
|
// Grab latest commit or fake one if it's empty repository.
|
||||||
commit := ctx.Repo.Commit
|
commit := ctx.Repo.Commit
|
||||||
if commit == nil {
|
if commit == nil {
|
||||||
@ -357,6 +359,27 @@ func TestWebhook(ctx *context.Context) {
|
|||||||
Committer: ghost.NewGitSig(),
|
Committer: ghost.NewGitSig(),
|
||||||
CommitMessage: "This is a fake commit",
|
CommitMessage: "This is a fake commit",
|
||||||
}
|
}
|
||||||
|
authorUsername = ghost.Name
|
||||||
|
committerUsername = ghost.Name
|
||||||
|
} else {
|
||||||
|
// Try to match email with a real user.
|
||||||
|
author, err := models.GetUserByEmail(commit.Author.Email)
|
||||||
|
if err == nil {
|
||||||
|
authorUsername = author.Name
|
||||||
|
} else if !models.IsErrUserNotExist(err) {
|
||||||
|
ctx.Flash.Error(fmt.Sprintf("GetUserByEmail.(author) [%s]: %v", commit.Author.Email, err))
|
||||||
|
ctx.Status(500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
committer, err := models.GetUserByEmail(commit.Committer.Email)
|
||||||
|
if err == nil {
|
||||||
|
committerUsername = committer.Name
|
||||||
|
} else if !models.IsErrUserNotExist(err) {
|
||||||
|
ctx.Flash.Error(fmt.Sprintf("GetUserByEmail.(committer) [%s]: %v", commit.Committer.Email, err))
|
||||||
|
ctx.Status(500)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
apiUser := ctx.User.APIFormat()
|
apiUser := ctx.User.APIFormat()
|
||||||
@ -372,10 +395,12 @@ func TestWebhook(ctx *context.Context) {
|
|||||||
Author: &api.PayloadUser{
|
Author: &api.PayloadUser{
|
||||||
Name: commit.Author.Name,
|
Name: commit.Author.Name,
|
||||||
Email: commit.Author.Email,
|
Email: commit.Author.Email,
|
||||||
|
UserName: authorUsername,
|
||||||
},
|
},
|
||||||
Committer: &api.PayloadUser{
|
Committer: &api.PayloadUser{
|
||||||
Name: commit.Committer.Name,
|
Name: commit.Committer.Name,
|
||||||
Email: commit.Committer.Email,
|
Email: commit.Committer.Email,
|
||||||
|
UserName: committerUsername,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user