func DeleteNotices(ctx *context.Context) { strs := ctx.QueryStrings("ids[]") ids := make([]int64, 0, len(strs)) for i := range strs { id := com.StrTo(strs[i]).MustInt64() if id > 0 { ids = append(ids, id) } } if err := models.DeleteNoticesByIDs(ids); err != nil { ctx.Flash.Error("DeleteNoticesByIDs: " + err.Error()) ctx.Status(500) } else { ctx.Flash.Success(ctx.Tr("admin.notices.delete_success")) ctx.Status(200) } }
func TestWebhook(ctx *context.Context) { p := &api.PushPayload{ Ref: git.BRANCH_PREFIX + ctx.Repo.Repository.DefaultBranch, Before: ctx.Repo.CommitID, After: ctx.Repo.CommitID, Commits: []*api.PayloadCommit{ { ID: ctx.Repo.CommitID, Message: ctx.Repo.Commit.Message(), URL: ctx.Repo.Repository.FullRepoLink() + "/commit/" + ctx.Repo.CommitID, Author: &api.PayloadAuthor{ Name: ctx.Repo.Commit.Author.Name, Email: ctx.Repo.Commit.Author.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(), }, } if err := models.PrepareWebhooks(ctx.Repo.Repository, models.HOOK_EVENT_PUSH, p); err != nil { ctx.Flash.Error("PrepareWebhooks: " + err.Error()) ctx.Status(500) } else { go models.HookQueue.Add(ctx.Repo.Repository.ID) ctx.Flash.Info(ctx.Tr("repo.settings.webhook.test_delivery_success")) ctx.Status(200) } }
func TriggerTask(ctx *context.Context) { branch := ctx.Query("branch") secret := ctx.Query("secret") if len(branch) == 0 || len(secret) == 0 { ctx.Error(404) log.Trace("TriggerTask: branch or secret is empty") return } owner, repo := parseOwnerAndRepo(ctx) if ctx.Written() { return } if secret != base.EncodeMD5(owner.Salt) { ctx.Error(404) log.Trace("TriggerTask [%s/%s]: invalid secret", owner.Name, repo.Name) return } log.Trace("TriggerTask [%d].(new request): %s", repo.ID, branch) go models.HookQueue.Add(repo.ID) go models.AddTestPullRequestTask(repo.ID, branch) ctx.Status(202) }