From b2a68d1ab51ade8f4c0c405e80a57dae9d3413fd Mon Sep 17 00:00:00 2001 From: Jonas Kwiedor Date: Wed, 5 Oct 2022 14:37:25 +0200 Subject: [PATCH 1/6] chore: Remove github workflow. --- .github/workflows/greetings.yml | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 .github/workflows/greetings.yml diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml deleted file mode 100644 index 4677434..0000000 --- a/.github/workflows/greetings.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Greetings - -on: [pull_request_target, issues] - -jobs: - greeting: - runs-on: ubuntu-latest - permissions: - issues: write - pull-requests: write - steps: - - uses: actions/first-interaction@v1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - issue-message: "Message that will be displayed on users' first issue" - pr-message: "Message that will be displayed on users' first pull request" From 9ad3a354bb02aa0d9185afbbf4ae83f0806d5755 Mon Sep 17 00:00:00 2001 From: Jonas Kwiedor Date: Wed, 5 Oct 2022 14:38:33 +0200 Subject: [PATCH 2/6] chore: Update github workflow. --- .github/workflows/go.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 6edd5d7..5f9e6e9 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -20,3 +20,6 @@ jobs: - name: Build run: go build -v ./... + + - name: Test + run: go test -v ./.. \ No newline at end of file From 5027a1c28b1143bc6194c2117948077bd8ac387a Mon Sep 17 00:00:00 2001 From: Jonas Kwiedor Date: Wed, 5 Oct 2022 14:38:45 +0200 Subject: [PATCH 3/6] docs: Update readme. --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d399d6e..e5a3386 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ +
+ # notifile +
+ [![GitHub go.mod Go version of a Go module](https://img.shields.io/github/go-mod/go-version/echgo/notifile.svg)](https://golang.org/) [![Go](https://github.com/echgo/notifile/actions/workflows/go.yml/badge.svg)](https://github.com/echgo/notifile/actions/workflows/go.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/echgo/notifile)](https://goreportcard.com/report/github.com/echgo/notifile) [![Go Doc](https://godoc.org/github.com/echgo/notifile?status.svg)](https://pkg.go.dev/github.com/echgo/notifile) [![GitHub issues](https://img.shields.io/github/issues/echgo/notifile)](https://github.com/echgo/notifile/issues) [![GitHub forks](https://img.shields.io/github/forks/echgo/notifile)](https://github.com/echgo/notifile/network) [![GitHub stars](https://img.shields.io/github/stars/echgo/notifile)](https://github.com/echgo/notifile/stargazers) [![GitHub license](https://img.shields.io/github/license/echgo/notifile)](https://github.com/echgo/notifile/blob/master/LICENSE) With this library you can easily create notification files for your Go projects. These must then be stored in the directory you specify so that echGo can read them. @@ -12,7 +16,7 @@ go get github.com/echgo/notifile ## How to use? -You can use the following example to create a file. Please note that there are currently only the following notification channels: **gotify, matrix, telegram, trello, smtp & webhook**. +You can use the following example to create a file. Please note that there are currently only the following notification channels: `gotify`, `pushover`, `matrix`, `telegram`, `discord`, `slack`, `trello`, `zendesk`, `osticket`, `twillo`, `smtp` & `webhook`. ```go data := notifile.Data{ @@ -21,7 +25,7 @@ data := notifile.Data{ Message: "Here you will find your message.", } -err := notifile.Create(data, "/var/lib/echgo/notification") +err := notifile.Create(data, filepath.Join("var", "lib", "echgo", "notification") if err != nil { log.Fatalln(err) } From 6f6c2a05b51f695b456086621f0cc518b3db7eae Mon Sep 17 00:00:00 2001 From: Jonas Kwiedor Date: Wed, 5 Oct 2022 14:39:20 +0200 Subject: [PATCH 4/6] test: Update testing function. --- create_test.go | 52 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/create_test.go b/create_test.go index f4b6b7b..7e38e5b 100644 --- a/create_test.go +++ b/create_test.go @@ -1,22 +1,60 @@ +// Copyright 2022 Jonas Kwiedor. All rights reserved. +// Use of this source code is governed by the MIT +// license that can be found in the LICENSE file. + package notifile_test import ( + "fmt" "github.com/echgo/notifile" + "os" "testing" ) // TestCreate is to test the create function func TestCreate(t *testing.T) { - data := notifile.Data{ - Channels: nil, - Headline: "Testing", - Message: "This is a message about test corners.", + tests := []struct { + path string + channels []string + headline string + message string + }{ + { + path: os.TempDir(), + channels: []string{"gotify", "smtp"}, + headline: "Testing", + message: "This is the fist message about test corners.", + }, + { + path: os.TempDir(), + channels: []string{"smtp"}, + headline: "Testing", + message: "This is the second message about test corners.", + }, + { + path: os.TempDir(), + channels: []string{"trello"}, + headline: "Testing", + message: "This is the third message about test corners.", + }, } - err := notifile.Create(data, "/path/to/your/folder") - if err != nil { - t.Fatal(err) + for _, value := range tests { + + data := notifile.Data{ + Channels: value.channels, + Headline: value.headline, + Message: value.message, + } + + fmt.Println(value.path) + + err := notifile.Create(data, value.path) + if err != nil { + t.Fatal(err) + } + } } From c1307fed0064aa4ebe64d680772ffaade2b6d3b1 Mon Sep 17 00:00:00 2001 From: Jonas Kwiedor Date: Wed, 5 Oct 2022 14:39:35 +0200 Subject: [PATCH 5/6] chore: Add comments to gitignore. --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 35186f5..6a6038c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ - +# First irgnore all unused folders. +# After that we ignore all other files. .idea/ -notifile_test.go From 7c59a9754875d25ae7076a182653665df2dc94b6 Mon Sep 17 00:00:00 2001 From: Jonas Kwiedor Date: Wed, 5 Oct 2022 14:41:17 +0200 Subject: [PATCH 6/6] fix: Add new file name bugfix & remove timestamp. --- create.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/create.go b/create.go index 4bafb4f..7a1a40b 100644 --- a/create.go +++ b/create.go @@ -1,28 +1,36 @@ +// Copyright 2022 Jonas Kwiedor. All rights reserved. +// Use of this source code is governed by the MIT +// license that can be found in the LICENSE file. + +// Package notifile is used to generate a json file that +// is prepared in such a way that it can be read by echgo. package notifile import ( "encoding/json" "errors" + "math/rand" "os" "time" ) -// Set prefix, extension is to build the filename +// Set prefix, extension is to build the filename. const ( prefix = "notifile-" + char = "abcdefghijklmnopqrstuvwxyz1234567890" extension = ".json" ) -// Data is to structure the file data +// Data is to structure the file data. type Data struct { Channels []string `json:"channels"` Headline string `json:"headline"` Message string `json:"message"` } -// Create is to create a new notification file -// first we create a new file with a timestamp -// after that we check the channel & add the data +// Create is to create a new notification file. +// First we create a new file with a timestamp +// after that we check the channel & add the data. func Create(data Data, path string) error { if data.Channels == nil { @@ -33,7 +41,12 @@ func Create(data Data, path string) error { return errors.New("unfortunately the directory does not exist") } - name := prefix + time.Now().Format("20060102150405") + extension + name := prefix + for i := 0; i < 56; i++ { + rand.Seed(time.Now().UnixNano()) + name += string(char[rand.Intn(len(char))]) + } + name += extension content, err := json.MarshalIndent(data, "", " ") if err != nil {