Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add action feed for new release #12324

Merged
merged 17 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const (
ActionApprovePullRequest // 21
ActionRejectPullRequest // 22
ActionCommentPull // 23
ActionPublishRelease // 24
)

// Action represents user operation type and other information to
Expand All @@ -66,6 +67,8 @@ type Action struct {
Comment *Comment `xorm:"-"`
IsDeleted bool `xorm:"INDEX NOT NULL DEFAULT false"`
RefName string
ReleaseID int64
Release *Release `xorm:"-"`
IsPrivate bool `xorm:"INDEX NOT NULL DEFAULT false"`
Content string `xorm:"TEXT"`
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
Expand Down Expand Up @@ -285,6 +288,24 @@ func (a *Action) GetIssueContent() string {
return issue.Content
}

// GetRelease get release info for ActionPublishRelease
func (a *Action) GetRelease() *Release {
var err error
if a.OpType != ActionPublishRelease || a.Release != nil {
return a.Release
}

if a.Release, err = GetReleaseByID(a.ReleaseID); err != nil {
log.Error("GetReleaseByID(%d): %v", a.ReleaseID, err)
return nil
}

a.Release.Repo = a.Repo
a.Release.Publisher = a.ActUser

return a.Release
}

// GetFeedsOptions options for retrieving feeds
type GetFeedsOptions struct {
RequestedUser *User // the user we want activity for
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ var migrations = []Migration{
NewMigration("Ensure Repository.IsArchived is not null", setIsArchivedToFalse),
// v143 -> v144
NewMigration("recalculate Stars number for all user", recalculateStars),
// v144 -> v145
NewMigration("Add ReleaseID to action table", addReleaseIDActionColumn),
}

// GetCurrentDBVersion returns the current db version
Expand Down
22 changes: 22 additions & 0 deletions models/migrations/v144.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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 migrations

import (
"fmt"

"xorm.io/xorm"
)

func addReleaseIDActionColumn(x *xorm.Engine) error {
type Action struct {
ReleaseID int64
}

if err := x.Sync2(new(Action)); err != nil {
return fmt.Errorf("Sync2: %v", err)
}
return nil
}
2 changes: 1 addition & 1 deletion models/repo_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func notifyWatchers(e Engine, actions ...*Action) error {
act.Repo.Units = nil

switch act.OpType {
case ActionCommitRepo, ActionPushTag, ActionDeleteTag, ActionDeleteBranch:
case ActionCommitRepo, ActionPushTag, ActionDeleteTag, ActionPublishRelease, ActionDeleteBranch:
if !permCode[i] {
continue
}
Expand Down
19 changes: 19 additions & 0 deletions modules/notification/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,22 @@ func (a *actionNotifier) NotifySyncDeleteRef(doer *models.User, repo *models.Rep
log.Error("notifyWatchers: %v", err)
}
}

func (a *actionNotifier) NotifyNewRelease(rel *models.Release) {
if err := rel.LoadAttributes(); err != nil {
log.Error("NotifyNewRelease: %v", err)
return
}
if err := models.NotifyWatchers(&models.Action{
ActUserID: rel.PublisherID,
ActUser: rel.Publisher,
OpType: models.ActionPublishRelease,
RepoID: rel.RepoID,
Repo: rel.Repo,
IsPrivate: rel.Repo.IsPrivate,
ReleaseID: rel.ID,
RefName: rel.TagName,
}); err != nil {
log.Error("notifyWatchers: %v", err)
}
}
2 changes: 2 additions & 0 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,8 @@ func ActionIcon(opType models.ActionType) string {
return "check"
case models.ActionRejectPullRequest:
return "diff"
case models.ActionPublishRelease:
return "tag"
default:
return "question"
}
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2331,6 +2331,7 @@ mirror_sync_create = synced new reference <a href="%s/src/%s">%[2]s</a> to <a hr
mirror_sync_delete = synced and deleted reference <code>%[2]s</code> at <a href="%[1]s">%[3]s</a> from mirror
approve_pull_request = `approved <a href="%s/pulls/%s">%s#%[2]s</a>`
reject_pull_request = `suggested changes for <a href="%s/pulls/%s">%s#%[2]s</a>`
publish_release = `published release <a href="%s/releases/tag/%s">%[2]s</a> to <a href="%[1]s">%[3]s</a>`
lafriks marked this conversation as resolved.
Show resolved Hide resolved

[tool]
ago = %s ago
Expand Down
2 changes: 1 addition & 1 deletion routers/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func NewReleasePost(ctx *context.Context, form auth.NewReleaseForm) {
return
}

rel := &models.Release{
rel = &models.Release{
RepoID: ctx.Repo.Repository.ID,
PublisherID: ctx.User.ID,
Title: form.Title,
Expand Down
6 changes: 6 additions & 0 deletions templates/user/dashboard/feeds.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
{{else if eq .GetOpType 23}}
{{ $index := index .GetIssueInfos 0}}
{{$.i18n.Tr "action.comment_pull" .GetRepoLink $index .ShortRepoPath | Str2html}}
{{else if eq .GetOpType 24}}
{{ $branchLink := .GetBranch | EscapePound | Escape}}
{{ $release := .GetRelease }}
{{$.i18n.Tr "action.publish_release" .GetRepoLink $branchLink .ShortRepoPath | Str2html}}
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
{{end}}
</p>
{{if or (eq .GetOpType 5) (eq .GetOpType 18)}}
Expand Down Expand Up @@ -97,6 +101,8 @@
<p class="text light grey">{{index .GetIssueInfos 1}}</p>
{{else if or (eq .GetOpType 12) (eq .GetOpType 13) (eq .GetOpType 14) (eq .GetOpType 15)}}
<span class="text truncate issue title">{{.GetIssueTitle | RenderEmoji}}</span>
{{else if (and (eq .GetOpType 24) .Release)}}
<p class="text light grey">{{.Release.Title | RenderEmoji}}</p>
{{end}}
<p class="text italic light grey">{{TimeSince .GetCreate $.i18n.Lang}}</p>
</div>
Expand Down