Skip to content

Commit

Permalink
Fix issue event create request, template default locale. (#5134) (#5139)
Browse files Browse the repository at this point in the history
Co-authored-by: shuofan <fanshuo2015@gmail.com>
  • Loading branch information
erda-bot and shuofan authored Jun 28, 2022
1 parent 1cf7e19 commit b0d59c0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
8 changes: 4 additions & 4 deletions internal/apps/dop/providers/issue/stream/core/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ func (p *provider) CreateIssueEvent(req *common.IssueStreamCreateRequest) error
},
Sender: bundle.SenderDOP,
Content: common.IssueEventData{
Title: issue.Title,
Content: content,
AtUserIDs: issue.Assignee,
// IssueType: issue.Type,
Title: issue.Title,
Content: content,
AtUserIDs: issue.Assignee,
IssueType: issue.Type,
StreamType: req.StreamType,
StreamTypes: req.StreamTypes,
StreamParams: req.StreamParams,
Expand Down
14 changes: 14 additions & 0 deletions internal/apps/dop/providers/issue/stream/core/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"bou.ke/monkey"
"github.com/alecthomas/assert"

"github.com/erda-project/erda-infra/providers/i18n"
"github.com/erda-project/erda/apistructs"
"github.com/erda-project/erda/bundle"
"github.com/erda-project/erda/internal/apps/dop/providers/issue/dao"
Expand Down Expand Up @@ -69,6 +70,7 @@ func Test_provider_CreateIssueEvent(t *testing.T) {
BaseModel: dbengine.BaseModel{
ID: 1,
},
Type: "TASK",
}, nil
},
)
Expand Down Expand Up @@ -116,9 +118,21 @@ func Test_provider_CreateIssueEvent(t *testing.T) {
)
defer p6.Unpatch()

p7 := monkey.Patch(getDefaultContentForMsgSending,
func(ist string, param common.ISTParam, tran i18n.Translator, locale string) (string, error) {
return "1", nil
},
)
defer p7.Unpatch()

p := &provider{db: db, bdl: bdl}
err := p.CreateIssueEvent(&common.IssueStreamCreateRequest{
IssueID: 1,
})
assert.NoError(t, err)
err = p.CreateIssueEvent(&common.IssueStreamCreateRequest{
IssueID: 1,
StreamType: common.ISTChangeContent,
})
assert.NoError(t, err)
}
2 changes: 1 addition & 1 deletion internal/apps/dop/providers/issue/stream/core/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func getIssueStreamTemplateForMsgSending(locale string, ist string) (string, err
// getDefaultContent get rendered msg
func (p *provider) GetDefaultContent(req StreamTemplateRequest) (string, error) {
locale := req.Locale
if strings.Contains(locale, "zh") {
if locale == "" || strings.Contains(locale, "zh") {
locale = "zh"
}
if strings.Contains(locale, "en") {
Expand Down
14 changes: 14 additions & 0 deletions internal/apps/dop/providers/issue/stream/core/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ func TestGetDefaultContent(t *testing.T) {
want: `状态自 "old" 迁移至 "new" mrCreated`,
wantErr: false,
},
{
args: args{
req: StreamTemplateRequest{
StreamType: common.ISTTransferState,
StreamParams: common.ISTParam{
CurrentState: "old",
NewState: "new",
ReasonDetail: "mrCreated",
},
},
},
want: `状态自 "old" 迁移至 "new" mrCreated`,
wantErr: false,
},
}

p := &provider{commonTran: &mockTranslator{}, I18n: &mockTranslator{}}
Expand Down

0 comments on commit b0d59c0

Please sign in to comment.