Skip to content

Commit

Permalink
Merge pull request #20 from moneyforward/change-message-ephemeral
Browse files Browse the repository at this point in the history
Change message ephemeral
  • Loading branch information
ichiki-mfw authored Jul 16, 2024
2 parents 0afc4cb + 3d57594 commit 45f6ef2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/validate-goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
with:
go-version: 1.17
- name: Validate .goreleaser.yml
uses: goreleaser/goreleaser-action@v3
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --snapshot --skip-publish --rm-dist --debug
args: release --snapshot --skip=publish --clean --verbose
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22 changes: 10 additions & 12 deletions .goreleaser.yml → .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version: 2
project_name: auriga
before:
hooks:
Expand All @@ -6,22 +7,19 @@ builds:
- main: ./app/cmd
binary: auriga
env:
- CGO_ENABLED=0
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
archives:
- name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
replacements:
darwin: darwin
linux: linux
windows: windows
386: i386
amd64: x86_64
format_overrides:
- goos: windows
format: zip
- format: tar.gz
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
files:
- docs/*
- README.md
Expand Down
12 changes: 6 additions & 6 deletions app/internal/domain/service/slack_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ const (
// postEmailList method posts emailList using slack postMessageAPI.
// The chunkedLines are generated and requested for each chunk,
// because of considering the limit the number of characters of slackAPI.
func (s *slackResponseService) postEmailList(ctx context.Context, channelID string, emails []*model.SlackUserEmail, ts string) error {
func (s *slackResponseService) postEmailList(ctx context.Context, channelID string, emails []*model.SlackUserEmail, ts string, userID string) error {
lines := append(make([]string, 0, len(emails)+1), "参加者一覧")
for _, email := range emails {
lines = append(lines, email.Email)
}
chunkedLines := slice.SplitStringSliceInChunks(lines, lineSizeOfPostEmailList)
for _, chunkedLine := range chunkedLines {
err := s.slackRepository.PostMessage(ctx, channelID, strings.Join(chunkedLine, "\n"), ts)
err := s.slackRepository.PostEphemeral(ctx, channelID, strings.Join(chunkedLine, "\n"), ts, userID)
if err != nil {
return err
}
Expand All @@ -79,10 +79,10 @@ func (s *slackResponseService) ReplyEmailList(ctx context.Context, event *slacke
for _, email := range emails {
b.WriteString("\n" + email.Email)
}
return s.slackRepository.PostMessage(ctx, event.Channel, b.String(), event.ThreadTimeStamp)
return s.slackRepository.PostEphemeral(ctx, event.Channel, b.String(), event.ThreadTimeStamp, event.User)
}

return s.postEmailList(ctx, event.Channel, emails, event.ThreadTimeStamp)
return s.postEmailList(ctx, event.Channel, emails, event.ThreadTimeStamp, event.User)
}

func (s *slackResponseService) ReplyError(ctx context.Context, event *slackevents.AppMentionEvent, err error) error {
Expand All @@ -95,8 +95,8 @@ func (s *slackResponseService) ReplyError(ctx context.Context, event *slackevent
}
if s.errorRepository.ErrUserNotFound(err) {
msg += "参加者はいないようです:neko_namida:"
return s.slackRepository.PostMessage(
ctx, event.Channel, msg, event.ThreadTimeStamp,
return s.slackRepository.PostEphemeral(
ctx, event.Channel, msg, event.ThreadTimeStamp, event.User,
)
}
return err
Expand Down
40 changes: 23 additions & 17 deletions app/internal/domain/service/slack_response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func Test_slackResponseService_postEmailList(t *testing.T) {
emails []*model.SlackUserEmail
cid string
ts string
userID string
}
tests := []struct {
name string
Expand All @@ -75,11 +76,12 @@ func Test_slackResponseService_postEmailList(t *testing.T) {
emails: createEmails(0, 1),
ts: "ts",
cid: "cid",
userID: "sampleUser",
},
prepare: func(msr *mock_repository.MockSlackRepository) {
gomock.InOrder(
msr.EXPECT().PostMessage(
gomock.Any(), "cid", createMessage("参加者一覧", createEmails(0, 1)), "ts").
msr.EXPECT().PostEphemeral(
gomock.Any(), "cid", createMessage("参加者一覧", createEmails(0, 1)), "ts", "sampleUser").
Return(nil),
)
},
Expand All @@ -90,11 +92,12 @@ func Test_slackResponseService_postEmailList(t *testing.T) {
emails: createEmails(0, lineSizeOfPostEmailList-1),
ts: "ts",
cid: "cid",
userID: "sampleUser",
},
prepare: func(msr *mock_repository.MockSlackRepository) {
gomock.InOrder(
msr.EXPECT().PostMessage(
gomock.Any(), "cid", createMessage("参加者一覧", createEmails(0, lineSizeOfPostEmailList-1)), "ts").
msr.EXPECT().PostEphemeral(
gomock.Any(), "cid", createMessage("参加者一覧", createEmails(0, lineSizeOfPostEmailList-1)), "ts", "sampleUser").
Return(nil),
)
},
Expand All @@ -105,14 +108,15 @@ func Test_slackResponseService_postEmailList(t *testing.T) {
emails: createEmails(0, lineSizeOfPostEmailList),
ts: "ts",
cid: "cid",
userID: "sampleUser",
},
prepare: func(msr *mock_repository.MockSlackRepository) {
gomock.InOrder(
msr.EXPECT().PostMessage(
gomock.Any(), "cid", createMessage("参加者一覧", createEmails(0, lineSizeOfPostEmailList-1)), "ts").
msr.EXPECT().PostEphemeral(
gomock.Any(), "cid", createMessage("参加者一覧", createEmails(0, lineSizeOfPostEmailList-1)), "ts", "sampleUser").
Return(nil),
msr.EXPECT().PostMessage(
gomock.Any(), "cid", createMessage("", createEmails(lineSizeOfPostEmailList-1, 1)), "ts").
msr.EXPECT().PostEphemeral(
gomock.Any(), "cid", createMessage("", createEmails(lineSizeOfPostEmailList-1, 1)), "ts", "sampleUser").
Return(nil),
)
},
Expand All @@ -132,7 +136,7 @@ func Test_slackResponseService_postEmailList(t *testing.T) {
slackRepository: msr,
errorRepository: mer,
}
if err := s.postEmailList(ctx, tt.args.cid, tt.args.emails, tt.args.ts); (err != nil) != tt.wantErr {
if err := s.postEmailList(ctx, tt.args.cid, tt.args.emails, tt.args.ts, tt.args.userID); (err != nil) != tt.wantErr {
t.Errorf("postEmailList() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand All @@ -156,16 +160,17 @@ func Test_slackErrorResponseService_ReplyEmailList(t *testing.T) {
event: &slackevents.AppMentionEvent{
Channel: "sampleChannel",
ThreadTimeStamp: "sampleThreadTimeStamp",
User: "sampleUser",
},
emails: []*model.SlackUserEmail{
{Email: "[email protected]"},
{Email: "[email protected]"},
},
},
prepare: func(msr *mock_repository.MockSlackRepository) {
msr.EXPECT().PostMessage(gomock.Any(), "sampleChannel",
msr.EXPECT().PostEphemeral(gomock.Any(), "sampleChannel",
"参加者一覧\n[email protected]\n[email protected]",
"sampleThreadTimeStamp").Return(nil)
"sampleThreadTimeStamp", "sampleUser").Return(nil)
},
},
{
Expand All @@ -174,16 +179,17 @@ func Test_slackErrorResponseService_ReplyEmailList(t *testing.T) {
event: &slackevents.AppMentionEvent{
Channel: "sampleChannel",
ThreadTimeStamp: "sampleThreadTimeStamp",
User: "sampleUser",
},
emails: []*model.SlackUserEmail{
{Email: "[email protected]"},
{Email: "[email protected]"},
},
},
prepare: func(msr *mock_repository.MockSlackRepository) {
msr.EXPECT().PostMessage(gomock.Any(), "sampleChannel",
msr.EXPECT().PostEphemeral(gomock.Any(), "sampleChannel",
"参加者一覧\n[email protected]\n[email protected]",
"sampleThreadTimeStamp").Return(errors.New("sample error"))
"sampleThreadTimeStamp", "sampleUser").Return(errors.New("sample error"))
},
wantErr: true,
},
Expand Down Expand Up @@ -252,9 +258,9 @@ func Test_slackErrorResponseService_ReplyError(t *testing.T) {
gomock.InOrder(
mer.EXPECT().ErrThreadNotFound(errors.New("user_not_found")).Return(false),
mer.EXPECT().ErrUserNotFound(errors.New("user_not_found")).Return(true),
msr.EXPECT().PostMessage(gomock.Any(), "sampleChannel",
msr.EXPECT().PostEphemeral(gomock.Any(), "sampleChannel",
"参加者はいないようです:neko_namida:",
"sampleThreadTimeStamp").Return(nil),
"sampleThreadTimeStamp", "sampleUser").Return(nil),
)
},
},
Expand Down Expand Up @@ -292,9 +298,9 @@ func Test_slackErrorResponseService_ReplyError(t *testing.T) {
gomock.InOrder(
mer.EXPECT().ErrThreadNotFound(errors.New("user_not_found")).Return(false),
mer.EXPECT().ErrUserNotFound(errors.New("user_not_found")).Return(true),
msr.EXPECT().PostMessage(gomock.Any(), "sampleChannel",
msr.EXPECT().PostEphemeral(gomock.Any(), "sampleChannel",
"参加者はいないようです:neko_namida:",
"sampleThreadTimeStamp").Return(errors.New("sample_error")),
"sampleThreadTimeStamp", "sampleUser").Return(errors.New("sample_error")),
)
},
wantErr: true,
Expand Down

0 comments on commit 45f6ef2

Please sign in to comment.