diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 9e22b7125..000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,63 +0,0 @@ -version: 2.1 - -orbs: - plugin-ci: mattermost/plugin-ci@volatile - -workflows: - version: 2 - nightly: - triggers: - - schedule: - cron: "0 0 * * *" - filters: - branches: - only: - - master - jobs: - - plugin-ci/lint - - plugin-ci/test - - plugin-ci/build - ci: - jobs: - - plugin-ci/lint: - filters: - tags: - only: /^v.*/ - - plugin-ci/test: - filters: - tags: - only: /^v.*/ - - plugin-ci/coverage: - filters: - tags: - only: /^v.*/ - requires: - - plugin-ci/test - - plugin-ci/build: - filters: - tags: - only: /^v.*/ - requires: - - plugin-ci/test - - plugin-ci/deploy-ci: - filters: - branches: - only: master - context: plugin-ci - requires: - - plugin-ci/lint - - plugin-ci/coverage - - plugin-ci/build - - plugin-ci/test - - plugin-ci/deploy-release-github: - filters: - tags: - only: /^v.*/ - branches: - ignore: /.*/ - context: matterbuild-github-token - requires: - - plugin-ci/lint - - plugin-ci/coverage - - plugin-ci/build - - plugin-ci/test diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 000000000..c929fd9ba --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,18 @@ +name: cd +on: + workflow_run: + workflows: ["ci"] + branches-ignore: ["*"] + types: + - completed + push: + tags: + - "v*" + +permissions: + contents: read + +jobs: + plugin-cd: + uses: mattermost/actions-workflows/.github/workflows/plugin-cd.yml@main + secrets: inherit diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..3c05ae631 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ +name: ci +on: + schedule: + - cron: "0 0 * * *" + push: + branches: + - master + tags: + - "v*" + pull_request: + +permissions: + contents: read + +jobs: + plugin-ci: + uses: mattermost/actions-workflows/.github/workflows/plugin-ci.yml@main + secrets: inherit diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 000000000..049c407af --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +14.21.1 diff --git a/CODEOWNERS b/CODEOWNERS index c1a612444..c11eb6ad4 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1 +1 @@ -* @jfrerich +* @mickmister diff --git a/README.md b/README.md index 79eb20d6b..f3c8a0a38 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,7 @@ [![Release](https://img.shields.io/github/v/release/mattermost/mattermost-plugin-welcomebot)](https://github.com/mattermost/mattermost-plugin-welcomebot/releases/latest) [![HW](https://img.shields.io/github/issues/mattermost/mattermost-plugin-welcomebot/Up%20For%20Grabs?color=dark%20green&label=Help%20Wanted)](https://github.com/mattermost/mattermost-plugin-welcomebot/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22Up+For+Grabs%22+label%3A%22Help+Wanted%22) -**Maintainer:** [@jfrerich](https://github.com/jfrerich) -**Co-Maintainer:** [@iomodo](https://github.com/iomodo) +**Maintainer:** [@mickmister](https://github.com/mickmister) Use this plugin to improve onboarding and HR processes. It adds a Welcome Bot that helps welcome users to teams and/or channels as well as easily join channels based on selections. @@ -36,8 +35,9 @@ Edit your `config.json` file with a message you want to send to a user in the fo "com.mattermost.welcomebot": { "WelcomeMessages": [ { - "TeamName": "your-team-name, your-second-team-name", + "TeamName": "your-team-name", "DelayInSeconds": 3, + "IncludeGuests": false, "Message": [ "Your welcome message here. Each list item specifies one line in the message text." ], @@ -105,7 +105,7 @@ If you see `[Object object]` in the text field, that's because the configuration ### Reference -- **TeamName**: The teams for which the Welcome Bot sends a message. Must be the team handle used in the URL, in lowercase. For example, in the following URL, the **TeamName** value is `my-team`: https://example.com/my-team/channels/my-channel . In the case of multiple teams, use comma separated fields. For example `"my-team, my-team-2"` to display the same messages for both `my-team` and `my-team-2` +- **TeamName**: The team for which the Welcome Bot sends a message for. Must be the team handle used in the URL, in lowercase. For example, in the following URL the **TeamName** value is `my-team`: https://example.com/my-team/channels/my-channel - **DelayInSeconds**: The number of seconds after joining a team that the user receives a welcome message. - **Message**: The message posted to the user. - (Optional) **IncludeGuests**: Whether or not to include guest users. @@ -143,7 +143,7 @@ To accomplish the above, you can specify the following configuration in your `co "com.mattermost.welcomebot": { "WelcomeMessages": [ { - "TeamName": "staff, management", + "TeamName": "staff", "DelayInSeconds": 5, "Message": [ "### Welcome {{.UserDisplayName}} to the Staff {{.Team.DisplayName}} team!", diff --git a/plugin.json b/plugin.json index 0360346bf..6d0aa612c 100644 --- a/plugin.json +++ b/plugin.json @@ -4,8 +4,8 @@ "description": "This plugin adds a WelcomeBot that helps add new users to channels.", "homepage_url": "https://github.com/mattermost/mattermost-plugin-welcomebot", "support_url": "https://github.com/mattermost/mattermost-plugin-welcomebot/issues", - "release_notes_url": "https://github.com/mattermost/mattermost-plugin-welcomebot/releases/tag/v1.2.0", - "version": "1.2.0", + "release_notes_url": "https://github.com/mattermost/mattermost-plugin-welcomebot/releases/tag/v1.3.0", + "version": "1.3.0", "min_server_version": "5.37.0", "server": { "executables": { diff --git a/server/command.go b/server/command.go index 9ce161756..281fce0e0 100644 --- a/server/command.go +++ b/server/command.go @@ -86,17 +86,13 @@ func (p *Plugin) validateCommand(action string, parameters []string) string { func (p *Plugin) executeCommandPreview(teamName string, args *model.CommandArgs) { found := false for _, message := range p.getWelcomeMessages() { - var teamNamesArr = strings.Split(message.TeamName, ",") - for _, name := range teamNamesArr { - tn := strings.TrimSpace(name) - if tn == teamName { - p.postCommandResponse(args, "%s", teamName) - if err := p.previewWelcomeMessage(teamName, args, *message); err != nil { - p.postCommandResponse(args, "error occurred while processing greeting for team `%s`: `%s`", teamName, err) - return - } - found = true + if message.TeamName == teamName { + if err := p.previewWelcomeMessage(teamName, args, *message); err != nil { + p.postCommandResponse(args, "error occurred while processing greeting for team `%s`: `%s`", teamName, err) + return } + + found = true } } @@ -134,7 +130,7 @@ func (p *Plugin) executeCommandSetWelcome(args *model.CommandArgs) { return } - if channelInfo.Type == model.ChannelTypeDirect { + if channelInfo.Type == model.ChannelTypePrivate { p.postCommandResponse(args, "welcome messages are not supported for direct channels") return } diff --git a/server/hooks.go b/server/hooks.go index e1f7efe1c..25b1b744e 100644 --- a/server/hooks.go +++ b/server/hooks.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "strings" "time" "github.com/mattermost/mattermost-server/v6/model" @@ -19,15 +18,12 @@ func (p *Plugin) UserHasJoinedTeam(c *plugin.Context, teamMember *model.TeamMemb } for _, message := range p.getWelcomeMessages() { - var teamNamesArr = strings.Split(message.TeamName, ",") - for _, name := range teamNamesArr { - tn := strings.TrimSpace(name) - if tn == data.Team.Name { - if data.User.IsGuest() && !message.IncludeGuests { - continue - } - go p.processWelcomeMessage(*data, *message) - } + if data.User.IsGuest() && !message.IncludeGuests { + continue + } + + if message.TeamName == data.Team.Name { + go p.processWelcomeMessage(*data, *message) } } } diff --git a/server/http_hooks.go b/server/http_hooks.go index 810ce08e9..6c632a7e2 100644 --- a/server/http_hooks.go +++ b/server/http_hooks.go @@ -13,6 +13,7 @@ import ( func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) { var action *Action if err := json.NewDecoder(r.Body).Decode(&action); err != nil || action == nil { + p.API.LogDebug("failed to decode action from request body", "error", err.Error()) p.encodeEphemeralMessage(w, "WelcomeBot Error: We could not decode the action") return } @@ -28,19 +29,19 @@ func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Req var err *model.AppError if data.User, err = p.API.GetUser(action.Context.UserID); err != nil { - p.API.LogError("failed to query user", "user_id", action.Context.UserID) + p.API.LogError("failed to query user", "user_id", action.Context.UserID, "error", err.Error()) p.encodeEphemeralMessage(w, "WelcomeBot Error: We could not find the supplied user") return } if data.Team, err = p.API.GetTeam(action.Context.TeamID); err != nil { - p.API.LogError("failed to query team", "team_id", action.Context.TeamID) + p.API.LogError("failed to query team", "team_id", action.Context.TeamID, "error", err.Error()) p.encodeEphemeralMessage(w, "WelcomeBot Error: We could not find the supplied team") return } if data.DirectMessage, err = p.API.GetDirectChannel(action.Context.UserID, p.botUserID); err != nil { - p.API.LogError("failed to query direct message channel", "user_id", action.Context.UserID) + p.API.LogError("failed to query direct message channel", "user_id", action.Context.UserID, "error", err.Error()) p.encodeEphemeralMessage(w, "WelcomeBot Error: We could not find the welcome bot direct message channel") return } @@ -49,7 +50,7 @@ func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Req // Check to make sure you're still in the team if teamMember, err := p.API.GetTeamMember(action.Context.TeamID, action.Context.UserID); err != nil || teamMember == nil || teamMember.DeleteAt > 0 { - p.API.LogError("Didn't have access to team", "user_id", action.Context.UserID, "team_id", action.Context.TeamID) + p.API.LogError("Didn't have access to team", "user_id", action.Context.UserID, "team_id", action.Context.TeamID, "error", err.Error()) p.encodeEphemeralMessage(w, "WelcomeBot Error: You do not appear to have access to this team") return } diff --git a/server/manifest.go b/server/manifest.go index 38e43ab9c..99642bdb0 100644 --- a/server/manifest.go +++ b/server/manifest.go @@ -7,5 +7,5 @@ var manifest = struct { Version string }{ ID: "com.mattermost.welcomebot", - Version: "1.2.0", + Version: "1.3.0", }