-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
215 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Slack | ||
|
||
[](https://github.com/nszilard/slack/actions/workflows/ci.yml) | ||
[](https://goreportcard.com/report/github.com/nszilard/slack) | ||
[](https://godoc.org/github.com/nszilard/slack) | ||
|
||
--- | ||
|
||
## About | ||
|
||
`slack` is a simple CLI utility to send Slack messages based on a pre-defined templates, but it can also be used as a library. | ||
Inspired by the [slack-go/slack](https://github.com/slack-go/slack) project, but wanted something simpler for personal use. | ||
|
||
## Installation | ||
|
||
``` shell | ||
go get -u github.com/nszilard/slack | ||
``` | ||
|
||
## Usage | ||
|
||
It supports both environment variables as well as flags to set values, where the latter one takes priority if the values differ. | ||
|
||
### Main command | ||
|
||
| Environment variable | Flag | Description | | ||
| :---------------------|:--------------------- |:----------------------------------------------------------------------------------------------| | ||
| `SLACK_ORG_ID` | `slack-org-id` | Slack Organization ID. From the webhhok token **`Txxxxxx`**`/Bxxxxxx/xxxxxxx` the first group | | ||
| `SLACK_WEBHOOK_ID` | `slack-webhook-id` | Slack Webhhok ID. From the webhhok token `Txxxxxx/`**`Bxxxxxx`**/`xxxxxxx` the second group | | ||
| `SLACK_WEBHOOK_TOKEN` | `slack-webhook-token` | Slack Webhhok token. From the webhhok token `Txxxxxx/Bxxxxxx/`**`xxxxxxx`** the third group | | ||
| `SLACK_CHANNEL` | `slack-channel` | Slack channel name (or personal ID) to send the message to | | ||
| `SLACK_USER` | `slack-user` | To specify the username for the published message. | | ||
| `SLACK_USER_IMAGE` | `slack-user-image` | To specify a URL to an image to use as the profile photo alongside the message | | ||
|
||
### Changelog command | ||
|
||
| Environment variable | Flag | Description | | ||
| :---------------------|:------------------- |:--------------------------------------------------------| | ||
| `CHANGELOG_SERVICE` | `changelog-service` | Name of the Git repositry or preferred service name | | ||
| `CHANGELOG_VERSION` | `changelog-version` | The new version | | ||
| `CHANGELOG_COMMITS` | | Commits which have been released with the given version | | ||
|
||
### See generated docs | ||
|
||
* [slack](docs/slack.md) - CLI to send Slack messages programmatically. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/cobra/doc" | ||
) | ||
|
||
var docsLocation string | ||
|
||
//---------------------------------------- | ||
// Cobra command | ||
//---------------------------------------- | ||
var documentationCmd = &cobra.Command{ | ||
Use: "docs", | ||
Aliases: []string{"doc", "documentation"}, | ||
Short: "Generates markdown documentation", | ||
|
||
Hidden: true, | ||
|
||
Args: cobra.NoArgs, | ||
RunE: generateMarkdown, | ||
} | ||
|
||
func generateMarkdown(cmd *cobra.Command, args []string) error { | ||
return doc.GenMarkdownTree(cmd.Root(), docsLocation) | ||
} | ||
|
||
//---------------------------------------- | ||
// Cobra command init | ||
//---------------------------------------- | ||
func init() { | ||
// Adding documentation command to the root command | ||
mainCmd.AddCommand(documentationCmd) | ||
|
||
docsLocation = "docs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func Test_generateMarkdown(t *testing.T) { | ||
folder := "temp" | ||
err := os.Mkdir(folder, 0755) | ||
if err != nil { | ||
t.Fatalf("failed to create temp folder") | ||
} | ||
docsLocation = folder | ||
defer os.RemoveAll(folder) | ||
|
||
if err := generateMarkdown(&cobra.Command{Use: "test"}, nil); err != nil { | ||
t.Errorf("docs: unexpected error: %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
## slack | ||
|
||
CLI to send Slack messages programmatically. | ||
|
||
### Synopsis | ||
|
||
A simple CLI tool to send Slack messages programmatically using pre-defined templates. | ||
|
||
### Options | ||
|
||
``` | ||
-d, --debug Enables Debug logging. | ||
-h, --help help for slack | ||
-C, --slack-channel string Slack Channel where to send the message. (Optional) | ||
-O, --slack-org-id string Slack Organization ID in the form of: Txxxxxx. (Required) | ||
-U, --slack-user string Name to use when sending the message. (Optional) | ||
-I, --slack-user-image string Link to an image to use as a profile icon when sending the message (Optional) | ||
-W, --slack-webhook-id string Slack Webhook ID in the form of: Bxxxxxx. (Required) | ||
-T, --slack-webhook-token string Slack Webhook token in the form of: xxxxxxx. (Required) | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [slack changelog](slack_changelog.md) - Sends a message using the Changelog template. | ||
* [slack simple](slack_simple.md) - Sends a simple text message. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
## slack changelog | ||
|
||
Sends a message using the Changelog template. | ||
|
||
### Synopsis | ||
|
||
Sends a changelog message using the provided values. | ||
|
||
``` | ||
slack changelog [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-s, --changelog-service string Service name as it is registered in Git. (Required) | ||
-v, --changelog-version string The new tag. (Required) | ||
-h, --help help for changelog | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-d, --debug Enables Debug logging. | ||
-C, --slack-channel string Slack Channel where to send the message. (Optional) | ||
-O, --slack-org-id string Slack Organization ID in the form of: Txxxxxx. (Required) | ||
-U, --slack-user string Name to use when sending the message. (Optional) | ||
-I, --slack-user-image string Link to an image to use as a profile icon when sending the message (Optional) | ||
-W, --slack-webhook-id string Slack Webhook ID in the form of: Bxxxxxx. (Required) | ||
-T, --slack-webhook-token string Slack Webhook token in the form of: xxxxxxx. (Required) | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [slack](slack.md) - CLI to send Slack messages programmatically. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## slack simple | ||
|
||
Sends a simple text message. | ||
|
||
### Synopsis | ||
|
||
Sends a simple text message. | ||
|
||
``` | ||
slack simple [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for simple | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-d, --debug Enables Debug logging. | ||
-C, --slack-channel string Slack Channel where to send the message. (Optional) | ||
-O, --slack-org-id string Slack Organization ID in the form of: Txxxxxx. (Required) | ||
-U, --slack-user string Name to use when sending the message. (Optional) | ||
-I, --slack-user-image string Link to an image to use as a profile icon when sending the message (Optional) | ||
-W, --slack-webhook-id string Slack Webhook ID in the form of: Bxxxxxx. (Required) | ||
-T, --slack-webhook-token string Slack Webhook token in the form of: xxxxxxx. (Required) | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [slack](slack.md) - CLI to send Slack messages programmatically. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters