Merge pull request #26 from kha7iq/refactor-for-testing

Refactor for better integration of new services
pull/28/head
Khaliq 4 years ago committed by GitHub
commit 90b4bf96bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,7 +3,7 @@
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
contributors and maintainers pledge to making participation in our project, and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal

@ -4,19 +4,20 @@ possible.
## Project structure
- `main` - Contains definitions for the underlying notification services.
- `cmd/discord` - Discord notification service.
- `cmd/email` - Email notification service.
- `cmd/msteams` - Microsoft Teams notification service.
- `cmd/rocketchat` - RocketChat notification service.
- `cmd/slack` - Slack notification service.
- `cmd/telegram` - Telegram notification service
- `service` - Contains definitions for the underlying notification services.
- `service/discord` - Discord notification service.
- `service/email` - Email notification service.
- `service/msteams` - Microsoft Teams notification service.
- `service/rocketchat` - RocketChat notification service.
- `service/slack` - Slack notification service.
- `service/telegram` - Telegram notification service.
- `service/pushover` - Pushover Notification service.
- Documentation
`docs` - Contains the documentation in markdown format.
- `services.md` If you are adding a new service please add documentaiton to `services.md`.
`docs` - Contains the documentation in Markdown format.
- `services.md` If you are adding a new service please add documentation to `services.md`.
- `home.md` Is the main page rendered when docs website is loaded.
- `install.md` Contains the install instructions for different packages.
- `install.md` Contains the installation instructions for different packages.
- Checking Locally
- Docsify is used for documentation rendering from markdown, you can download

@ -3,4 +3,5 @@
* [Home](/)
* [Installation](install.md)
* [Services & Usage](services.md)
* [Contribution](contribution.md)

@ -0,0 +1,73 @@
## Contributing to PingMe
We want to make contributing to this project as easy and transparent as
possible.
## Project structure
- `service` - Contains definitions for the underlying notification services.
- `service/discord` - Discord notification service.
- `service/email` - Email notification service.
- `service/msteams` - Microsoft Teams notification service.
- `service/rocketchat` - RocketChat notification service.
- `service/slack` - Slack notification service.
- `service/telegram` - Telegram notification service.
- `service/pushover` - Pushover Notification service.
- Documentation
`docs` - Contains the documentation in Markdown format.
- `services.md` If you are adding a new service please add documentation to `services.md`.
- `home.md` Is the main page rendered when docs website is loaded.
- `install.md` Contains the installation instructions for different packages.
- Checking Locally
- Docsify is used for documentation rendering from markdown, you can download
the cli and test locally before opening a pull request.
Install
```bash
npm i docsify-cli -g
# yarn global add docsify-cli
```
Serve locally
```bash
docsify serve docs
```
## Commits
Commit messages should be well formatted, and to make that "standardized", we
are using Conventional Commits.
```shell
<type>[<scope>]: <short summary>
│ │ │
│ │ └─> Summary in present tense. Not capitalized. No period at the end.
│ │
│ └─> Scope (optional): eg. common, compiler, authentication, core
└─> Type: chore, docs, feat, fix, refactor, style, or test.
```
You can follow the documentation on
[their website](https://www.conventionalcommits.org).
## Pull Requests
We actively welcome your pull requests.
1. Fork the repo and create your branch from `master`.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes (`make test`).
5. Make sure your code lints (`make lint`).
6. Make sure your code is well formatted (`make fmt`).
## Issues
We use GitHub issues to track public bugs. Please ensure your description is
clear and has sufficient instructions to be able to reproduce the issue.
## License
By contributing to PingMe, you agree that your contributions will be licensed
under the LICENSE file in the root directory of this source tree.

@ -61,7 +61,7 @@ as message, and most of all this serves as a swiss army knife sort of tool which
## Contributing
Contributions, issues and feature requests are welcome!<br />Feel free to check [issues page](https://github.com/kha7iq/pingme/issues). You can also take a look at the [contributing guide](https://github.com/kha7iq/pingme/blob/master/CONTRIBUTING.md).
Contributions, issues and feature requests are welcome!<br />Feel free to check [issues page](https://github.com/kha7iq/pingme/issues). You can also take a look at the [contribution guide](contribution.md).
@ -73,6 +73,6 @@ Give a ⭐️ if you like this project!
## Disclaimer
Any misuse of this utilify is your own liability and responsibility and cannot be attributed to the authors of this library. See [license](LICENSE) for more.
Any misuse of this utility is your own liability and responsibility and cannot be attributed to the authors of this library. See [license](https://github.com/kha7iq/pingme/blob/master/LICENSE.md) for more.
Spamming through the use of this library **may get you permanently banned** on most supported platforms.

@ -4,7 +4,15 @@ import (
"log"
"os"
"github.com/kha7iq/pingme/cmd"
"github.com/kha7iq/pingme/service/discord"
"github.com/kha7iq/pingme/service/email"
"github.com/kha7iq/pingme/service/mattermost"
"github.com/kha7iq/pingme/service/msteams"
"github.com/kha7iq/pingme/service/pushbullet"
"github.com/kha7iq/pingme/service/pushover"
"github.com/kha7iq/pingme/service/rocketchat"
"github.com/kha7iq/pingme/service/slack"
"github.com/kha7iq/pingme/service/telegram"
"github.com/urfave/cli/v2"
)
@ -12,7 +20,7 @@ import (
// Version variable is used for semVer
var Version string
// main with combile all the function into commands
// main with combine all the function into commands
func main() {
app := cli.NewApp()
app.Name = "PingMe"
@ -24,15 +32,15 @@ variables and command line switches.Currently supported platforms include Slack,
RocketChat, Discord, Pushover, Mattermost, Pushbullet, Microsoft Teams and email address.`
// app.Commands contains the subcommands as functions which return []*cli.Command.
app.Commands = []*cli.Command{
cmd.SendToTelegram(),
cmd.SendToRocketChat(),
cmd.SendToSlack(),
cmd.SendToDiscord(),
cmd.SendToTeams(),
cmd.SendToPushOver(),
cmd.SendToEmail(),
cmd.SendToMattermost(),
cmd.SendToPushBullet(),
telegram.Send(),
rocketchat.Send(),
slack.Send(),
discord.Send(),
msteams.Send(),
pushover.Send(),
email.Send(),
mattermost.Send(),
pushbullet.Send(),
}
err := app.Run(os.Args)

@ -1,4 +1,4 @@
package cmd
package discord
import (
"context"
@ -6,6 +6,8 @@ import (
"log"
"strings"
"github.com/kha7iq/pingme/service/helpers"
"github.com/nikoksr/notify"
"github.com/nikoksr/notify/service/discord"
"github.com/urfave/cli/v2"
@ -19,11 +21,11 @@ type discordPingMe struct {
Title string
}
// SendToDiscord parse values from *cli.context and return *cli.Command.
// Send parse values from *cli.context and return *cli.Command.
// Values include discord bot token, userID, channelIDs, Message and Title.
// If multiple channels are provided then the string is split with "," separator and
// each channelID is added to receiver.
func SendToDiscord() *cli.Command {
func Send() *cli.Command {
var discordOpts discordPingMe
return &cli.Command{
Name: "discord",
@ -56,7 +58,7 @@ All configuration options are also available via environment variables.`,
&cli.StringFlag{
Destination: &discordOpts.Title,
Name: "title",
Value: TimeValue,
Value: helpers.TimeValue,
Usage: "Title of the message.",
EnvVars: []string{"DISCORD_MSG_TITLE"},
},
@ -72,7 +74,7 @@ All configuration options are also available via environment variables.`,
chn := strings.Split(discordOpts.Channel, ",")
for _, v := range chn {
if len(v) <= 0 {
return fmt.Errorf(EmptyChannel)
return helpers.ErrChannel
}
discordSvc.AddReceivers(v)

@ -1,11 +1,12 @@
package cmd
package email
import (
"context"
"fmt"
"log"
"strings"
"github.com/kha7iq/pingme/service/helpers"
"github.com/nikoksr/notify"
"github.com/nikoksr/notify/service/mail"
"github.com/urfave/cli/v2"
@ -23,12 +24,12 @@ type email struct {
Identity string
}
// SendToEmail parse values from *cli.context and return *cli.Command.
// Send parses values from *cli.context and return *cli.Command.
// SendAddress is used for authentication with smtp server, host and port is required
// the default value for port is set to "587" and host as "smtp.gmail.com"
// If multiple ReceiverAddress are provided then the string value is split with "," separator and
// each ReceiverAddress is added to receiver.
func SendToEmail() *cli.Command {
func Send() *cli.Command {
var emailOpts email
return &cli.Command{
Name: "email",
@ -98,7 +99,7 @@ All configuration options are also available via environment variables.`,
&cli.StringFlag{
Destination: &emailOpts.Subject,
Name: "sub",
Value: TimeValue,
Value: helpers.TimeValue,
Usage: "Subject of the email",
EnvVars: []string{"EMAIL_SUBJECT"},
},
@ -111,7 +112,7 @@ All configuration options are also available via environment variables.`,
chn := strings.Split(emailOpts.ReceiverAddress, ",")
for _, v := range chn {
if len(v) <= 0 {
return fmt.Errorf(EmptyChannel)
return helpers.ErrChannel
}
emailSvc.AddReceivers(v)

@ -0,0 +1,13 @@
package helpers
import (
"errors"
"time"
)
var (
// ErrChannel variable holds default error message if no channel is provided.
ErrChannel = errors.New("target channel or id can not be empty")
// TimeValue holds current date and time in unix format.
TimeValue = "⏰ " + time.Now().Format(time.UnixDate)
)

@ -1,4 +1,4 @@
package cmd
package mattermost
import (
"bytes"
@ -9,6 +9,8 @@ import (
"strings"
"time"
"github.com/kha7iq/pingme/service/helpers"
"github.com/urfave/cli/v2"
)
@ -47,11 +49,11 @@ type matterMostResponse struct {
Metadata struct{} `json:"metadata"`
}
// SendToMattermost parse values from *cli.context and return *cli.Command
// Send parse values from *cli.context and return *cli.Command
// and send messages to target channels.
// If multiple channel ids are provided then the string is split with "," separator and
// message is sent to each channel.
func SendToMattermost() *cli.Command {
func Send() *cli.Command {
var mattermostOpts matterMost
return &cli.Command{
Name: "mattermost",
@ -87,7 +89,7 @@ You can specify multiple channels by separating the value with ','.`,
&cli.StringFlag{
Destination: &mattermostOpts.Title,
Name: "title",
Value: TimeValue,
Value: helpers.TimeValue,
Usage: "Title of the message.",
EnvVars: []string{"MATTERMOST_TITLE"},
},
@ -126,7 +128,7 @@ You can specify multiple channels by separating the value with ','.`,
ids := strings.Split(mattermostOpts.ChanIDs, ",")
for _, v := range ids {
if len(v) == 0 {
return fmt.Errorf(EmptyChannel)
return helpers.ErrChannel
}
jsonData, err := toJSON(v, fullMessage)

@ -1,11 +1,12 @@
package cmd
package msteams
import (
"context"
"fmt"
"log"
"strings"
"github.com/kha7iq/pingme/service/helpers"
"github.com/nikoksr/notify"
msteams2 "github.com/nikoksr/notify/service/msteams"
"github.com/urfave/cli/v2"
@ -18,11 +19,11 @@ type msTeams struct {
Title string
}
// SendToTeams parse values from *cli.context and return *cli.Command.
// Send parse values from *cli.context and return *cli.Command.
// Values include Ms Teams Webhook, Message and Title.
// If multiple webhooks are provided then the string is split with "," separator and
// each webhook is added to receiver.
func SendToTeams() *cli.Command {
func Send() *cli.Command {
var msTeamOpt msTeams
return &cli.Command{
Name: "teams",
@ -48,7 +49,7 @@ you can add permissions for multiple channels to single webhook.`,
&cli.StringFlag{
Destination: &msTeamOpt.Title,
Name: "title",
Value: TimeValue,
Value: helpers.TimeValue,
Usage: "Title of the message.",
EnvVars: []string{"TEAMS_MSG_TITLE"},
},
@ -60,7 +61,7 @@ you can add permissions for multiple channels to single webhook.`,
chn := strings.Split(msTeamOpt.Webhook, ",")
for _, v := range chn {
if len(v) <= 0 {
return fmt.Errorf(EmptyChannel)
return helpers.ErrChannel
}
teamsSvc.AddReceivers(v)
}

@ -1,11 +1,12 @@
package cmd
package pushbullet
import (
"context"
"fmt"
"log"
"strings"
"github.com/kha7iq/pingme/service/helpers"
"github.com/nikoksr/notify"
"github.com/nikoksr/notify/service/pushbullet"
"github.com/urfave/cli/v2"
@ -21,11 +22,11 @@ type pushBullet struct {
SMS bool
}
// SendToPushBullet parse values from *cli.context and return *cli.Command.
// Send parse values from *cli.context and return *cli.Command.
// Values include pushbullet token, Device, phone number, Message and Title.
// If multiple devices are provided they the string is split with "," separator and
// each device is added to receiver.
func SendToPushBullet() *cli.Command {
func Send() *cli.Command {
var pushBulletOpts pushBullet
return &cli.Command{
Name: "pushbullet",
@ -68,7 +69,7 @@ Multiple device nicknames or numbers can be used separated by comma.`,
&cli.StringFlag{
Destination: &pushBulletOpts.Title,
Name: "title",
Value: TimeValue,
Value: helpers.TimeValue,
Usage: "Title of the message.",
EnvVars: []string{"PUSHBULLET_TITLE"},
},
@ -92,7 +93,7 @@ Multiple device nicknames or numbers can be used separated by comma.`,
devices := strings.Split(pushBulletOpts.PhoneNumber, ",")
for _, v := range devices {
if len(v) <= 0 {
return fmt.Errorf(EmptyChannel)
return helpers.ErrChannel
}
pushBulletSmsSvc.AddReceivers(v)
@ -112,7 +113,7 @@ Multiple device nicknames or numbers can be used separated by comma.`,
devices := strings.Split(pushBulletOpts.Device, ",")
for _, v := range devices {
if len(v) <= 0 {
return fmt.Errorf(EmptyChannel)
return helpers.ErrChannel
}
pushBulletSvc.AddReceivers(v)
}

@ -1,10 +1,11 @@
package cmd
package pushover
import (
"fmt"
"log"
"strings"
"github.com/kha7iq/pingme/service/helpers"
"github.com/gregdel/pushover"
"github.com/urfave/cli/v2"
)
@ -17,11 +18,11 @@ type pushOver struct {
Title string
}
// SendToPushOver parse values from *cli.context and return *cli.Command.
// Send parse values from *cli.context and return *cli.Command.
// Values include token, users, Message and Title.
// If multiple users are provided then the string is split with "," separator and
// each user is added to receiver.
func SendToPushOver() *cli.Command {
func Send() *cli.Command {
var pushOverOpts pushOver
return &cli.Command{
Name: "pushover",
@ -56,7 +57,7 @@ All configuration options are also available via environment variables.`,
&cli.StringFlag{
Destination: &pushOverOpts.Title,
Name: "title",
Value: TimeValue,
Value: helpers.TimeValue,
Usage: "Title of the message.",
EnvVars: []string{"PUSHOVER_TITLE"},
},
@ -68,7 +69,7 @@ All configuration options are also available via environment variables.`,
for _, v := range users {
if len(v) == 0 {
return fmt.Errorf(EmptyChannel)
return helpers.ErrChannel
}
recipient := pushover.NewRecipient(v)
responsePushOver, err := app.SendMessage(message, recipient)

@ -1,11 +1,10 @@
package cmd
package rocketchat
import (
"context"
"fmt"
"strings"
"time"
"github.com/kha7iq/pingme/service/helpers"
"github.com/nikoksr/notify"
"github.com/nikoksr/notify/service/rocketchat"
"github.com/urfave/cli/v2"
@ -21,17 +20,11 @@ type rocketChat struct {
Scheme string
}
var (
// EmptyChannel variable holds default error message if no channel is provided.
EmptyChannel = "channel name or id can not be empty"
TimeValue = "⏰ " + time.Now().Format(time.UnixDate)
)
// SendToRocketChat parse values from *cli.context and return *cli.Command.
// Send parse values from *cli.context and return *cli.Command.
// Values include rocketchat token, , UserId, channelIDs, ServerURL, Scheme, Message and Title.
// If multiple channels are provided then the string is split with "," separator and
// each channelID is added to receiver.
func SendToRocketChat() *cli.Command {
func Send() *cli.Command {
var rocketChatOpts rocketChat
return &cli.Command{
Name: "rocketchat",
@ -90,7 +83,7 @@ All configuration options are also available via environment variables.`,
&cli.StringFlag{
Destination: &rocketChatOpts.Title,
Name: "title",
Value: TimeValue,
Value: helpers.TimeValue,
Usage: "Title of the message",
EnvVars: []string{"ROCKETCHAT_TITLE"},
},
@ -106,7 +99,7 @@ All configuration options are also available via environment variables.`,
chn := strings.Split(rocketChatOpts.Channel, ",")
for _, v := range chn {
if len(v) <= 0 {
return fmt.Errorf(EmptyChannel)
return helpers.ErrChannel
}
rocketChatSvc.AddReceivers(v)

@ -1,11 +1,12 @@
package cmd
package slack
import (
"context"
"fmt"
"log"
"strings"
"github.com/kha7iq/pingme/service/helpers"
"github.com/nikoksr/notify"
"github.com/nikoksr/notify/service/slack"
"github.com/urfave/cli/v2"
@ -19,11 +20,11 @@ type slackPingMe struct {
Title string
}
// SendToSlack parse values from *cli.context and return *cli.Command.
// Send parse values from *cli.context and return *cli.Command.
// Values include slack token, channelIDs, Message and Title.
// If multiple channels are provided then the string is split with "," separator and
// each channelID is added to receiver.
func SendToSlack() *cli.Command {
func Send() *cli.Command {
var slackOpts slackPingMe
return &cli.Command{
Name: "slack",
@ -59,7 +60,7 @@ All configuration options are also available via environment variables.`,
&cli.StringFlag{
Destination: &slackOpts.Title,
Name: "title",
Value: TimeValue,
Value: helpers.TimeValue,
Usage: "Title of the message.",
EnvVars: []string{"SLACK_MSG_TITLE"},
},
@ -70,7 +71,7 @@ All configuration options are also available via environment variables.`,
chn := strings.Split(slackOpts.Channel, ",")
for _, v := range chn {
if len(v) <= 0 {
return fmt.Errorf(EmptyChannel)
return helpers.ErrChannel
}
slackSvc.AddReceivers(v)

@ -1,12 +1,13 @@
package cmd
package telegram
import (
"context"
"fmt"
"log"
"strconv"
"strings"
"github.com/kha7iq/pingme/service/helpers"
"github.com/nikoksr/notify"
"github.com/nikoksr/notify/service/telegram"
"github.com/urfave/cli/v2"
@ -20,11 +21,11 @@ type teleGram struct {
Title string
}
// SendToTelegram parse values from *cli.context and return *cli.Command.
// Send parse values from *cli.context and return *cli.Command.
// Values include telegram token, channelIDs, Message and Title.
// If multiple channels are provided they the string is split with "," separator and
// each channelID is added to receiver.
func SendToTelegram() *cli.Command {
func Send() *cli.Command {
var telegramOpts teleGram
return &cli.Command{
Name: "telegram",
@ -60,7 +61,7 @@ All configuration options are also available via environment variables.`,
&cli.StringFlag{
Destination: &telegramOpts.Title,
Name: "title",
Value: TimeValue,
Value: helpers.TimeValue,
Usage: "Title of the message.",
EnvVars: []string{"TELEGRAM_TITLE"},
},
@ -75,7 +76,7 @@ All configuration options are also available via environment variables.`,
chn := strings.Split(telegramOpts.Channel, ",")
for _, v := range chn {
if len(v) <= 0 {
return fmt.Errorf(EmptyChannel)
return helpers.ErrChannel
}
k, errStr := strconv.Atoi(v)
if errStr != nil {
Loading…
Cancel
Save