Browse Source

dashboard: add delete branch and tag news feeds

pull/4240/head
Unknwon 8 years ago
parent
commit
70072e2842
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 9
      conf/locale/locale_en-US.ini
  2. 34
      models/action.go
  3. 11
      models/repo.go
  4. 4
      modules/bindata/bindata.go
  5. 2
      public/css/gogs.css
  6. 2
      public/less/_dashboard.less
  7. 8
      templates/user/dashboard/feeds.tmpl

9
conf/locale/locale_en-US.ini

@ -1210,17 +1210,20 @@ notices.delete_success = System notices have been deleted successfully.
create_repo = created repository <a href="%s">%s</a>
rename_repo = renamed repository from <code>%[1]s</code> to <a href="%[2]s">%[3]s</a>
commit_repo = pushed to <a href="%[1]s/src/%[2]s">%[3]s</a> at <a href="%[1]s">%[4]s</a>
compare_commits = View comparison for these %d commits
transfer_repo = transfered repository <code>%s</code> to <a href="%s">%s</a>
create_issue = `opened issue <a href="%s/issues/%s">%s#%[2]s</a>`
close_issue = `closed issue <a href="%s/issues/%s">%s#%[2]s</a>`
reopen_issue = `reopened issue <a href="%s/issues/%s">%s#%[2]s</a>`
comment_issue = `commented on issue <a href="%s/issues/%s">%s#%[2]s</a>`
create_pull_request = `created pull request <a href="%s/pulls/%s">%s#%[2]s</a>`
close_pull_request = `closed pull request <a href="%s/pulls/%s">%s#%[2]s</a>`
reopen_pull_request = `reopened pull request <a href="%s/pulls/%s">%s#%[2]s</a>`
comment_issue = `commented on issue <a href="%s/issues/%s">%s#%[2]s</a>`
merge_pull_request = `merged pull request <a href="%s/pulls/%s">%s#%[2]s</a>`
transfer_repo = transfered repository <code>%s</code> to <a href="%s">%s</a>
create_branch = created new branch <a href="%[1]s/src/%[2]s">%[3]s</a> at <a href="%[1]s">%[4]s</a>
delete_branch = deleted branch <code>%[2]s</code> at <a href="%[1]s">%[3]s</a>
push_tag = pushed tag <a href="%s/src/%s">%[2]s</a> to <a href="%[1]s">%[3]s</a>
compare_commits = View comparison for these %d commits
delete_tag = deleted tag <code>%[2]s</code> at <a href="%[1]s">%[3]s</a>
[tool]
ago = ago

34
models/action.go

@ -26,6 +26,7 @@ import (
type ActionType int
// To maintain backward compatibility only append to the end of list
const (
ACTION_CREATE_REPO ActionType = iota + 1 // 1
ACTION_RENAME_REPO // 2
@ -42,6 +43,9 @@ const (
ACTION_REOPEN_ISSUE // 13
ACTION_CLOSE_PULL_REQUEST // 14
ACTION_REOPEN_PULL_REQUEST // 15
ACTION_CREATE_BRANCH // 16
ACTION_DELETE_BRANCH // 17
ACTION_DELETE_TAG // 18
)
var (
@ -66,7 +70,7 @@ func init() {
// Action represents user operation type and other information to repository,
// it implemented interface base.Actioner so that can be used in template render.
type Action struct {
ID int64 `xorm:"pk autoincr"`
ID int64
UserID int64 // Receiver user id.
OpType ActionType
ActUserID int64 // Action user id.
@ -485,30 +489,32 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
return fmt.Errorf("Marshal: %v", err)
}
defer func() {
// It's safe to fail when the whole function is called during hook execution
// because resource released after exit.
go HookQueue.Add(repo.ID)
}()
refName := git.RefEndName(opts.RefFullName)
if err = NotifyWatchers(&Action{
action := &Action{
ActUserID: pusher.ID,
ActUserName: pusher.Name,
OpType: opType,
Content: string(data),
RepoID: repo.ID,
RepoUserName: repo.MustOwner().Name,
RepoName: repo.Name,
RefName: refName,
IsPrivate: repo.IsPrivate,
}); err != nil {
return fmt.Errorf("NotifyWatchers: %v", err)
}
defer func() {
go HookQueue.Add(repo.ID)
}()
apiRepo := repo.APIFormat(nil)
apiPusher := pusher.APIFormat()
switch opType {
case ACTION_COMMIT_REPO: // Push
if isDelRef {
action.OpType = ACTION_DELETE_BRANCH
MustNotifyWatchers(action)
if err = PrepareWebhooks(repo, HOOK_EVENT_DELETE, &api.DeletePayload{
Ref: refName,
RefType: "branch",
@ -525,6 +531,9 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
compareURL := setting.AppUrl + opts.Commits.CompareURL
if isNewRef {
action.OpType = ACTION_CREATE_BRANCH
MustNotifyWatchers(action)
compareURL = ""
if err = PrepareWebhooks(repo, HOOK_EVENT_CREATE, &api.CreatePayload{
Ref: refName,
@ -537,6 +546,8 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
}
}
action.OpType = ACTION_COMMIT_REPO
MustNotifyWatchers(action)
if err = PrepareWebhooks(repo, HOOK_EVENT_PUSH, &api.PushPayload{
Ref: opts.RefFullName,
Before: opts.OldCommitID,
@ -552,6 +563,9 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
case ACTION_PUSH_TAG: // Tag
if isDelRef {
action.OpType = ACTION_DELETE_TAG
MustNotifyWatchers(action)
if err = PrepareWebhooks(repo, HOOK_EVENT_DELETE, &api.DeletePayload{
Ref: refName,
RefType: "tag",
@ -564,6 +578,8 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
return nil
}
action.OpType = ACTION_PUSH_TAG
MustNotifyWatchers(action)
if err = PrepareWebhooks(repo, HOOK_EVENT_CREATE, &api.CreatePayload{
Ref: refName,
RefType: "tag",

11
models/repo.go

@ -2075,7 +2075,7 @@ func notifyWatchers(e Engine, act *Action) error {
// Add feed for actioner.
act.UserID = act.ActUserID
if _, err = e.InsertOne(act); err != nil {
if _, err = e.Insert(act); err != nil {
return fmt.Errorf("insert new actioner: %v", err)
}
@ -2086,7 +2086,7 @@ func notifyWatchers(e Engine, act *Action) error {
act.ID = 0
act.UserID = watches[i].UserID
if _, err = e.InsertOne(act); err != nil {
if _, err = e.Insert(act); err != nil {
return fmt.Errorf("insert new action: %v", err)
}
}
@ -2098,6 +2098,13 @@ func NotifyWatchers(act *Action) error {
return notifyWatchers(x, act)
}
func MustNotifyWatchers(act *Action) {
act.ID = 0 // Reset ID to reuse Action object
if err := NotifyWatchers(act); err != nil {
log.Error(2, "NotifyWatchers: %v", err)
}
}
// _________ __
// / _____// |______ _______
// \_____ \\ __\__ \\_ __ \

4
modules/bindata/bindata.go

File diff suppressed because one or more lines are too long

2
public/css/gogs.css

@ -2921,7 +2921,7 @@ footer .ui.language .menu {
font-family: Consolas, monospace;
}
.feeds .news code {
padding: 1px;
padding: 3px;
font-size: 85%;
background-color: rgba(0, 0, 0, 0.04);
border-radius: 3px;

2
public/less/_dashboard.less

@ -86,7 +86,7 @@
font-family: Consolas, monospace;
}
code {
padding: 1px;
padding: 3px;
font-size: 85%;
background-color: rgba(0, 0, 0, 0.04);
border-radius: 3px;

8
templates/user/dashboard/feeds.tmpl

@ -8,6 +8,7 @@
<div class="{{if eq .GetOpType 5}}push news{{end}}">
<p>
<a href="{{AppSubUrl}}/{{.GetActUserName}}">{{.ShortActUserName}}</a>
<!-- Reference types to models/action.go -->
{{if eq .GetOpType 1}}
{{$.i18n.Tr "action.create_repo" .GetRepoLink .ShortRepoPath | Str2html}}
{{else if eq .GetOpType 2}}
@ -43,6 +44,13 @@
{{else if eq .GetOpType 15}}
{{ $index := index .GetIssueInfos 0}}
{{$.i18n.Tr "action.reopen_pull_request" .GetRepoLink $index .ShortRepoPath | Str2html}}
{{else if eq .GetOpType 16}}
{{ $branchLink := .GetBranch | EscapePound}}
{{$.i18n.Tr "action.create_branch" .GetRepoLink $branchLink .GetBranch .ShortRepoPath | Str2html}}
{{else if eq .GetOpType 17}}
{{$.i18n.Tr "action.delete_branch" .GetRepoLink .GetBranch .ShortRepoPath | Str2html}}
{{else if eq .GetOpType 18}}
{{$.i18n.Tr "action.delete_tag" .GetRepoLink .GetBranch .ShortRepoPath | Str2html}}
{{end}}
</p>
{{if eq .GetOpType 5}}

Loading…
Cancel
Save