4 Commits

Author SHA1 Message Date
Johannes Zottele 850a48c535 Fix out of range on invalid path 2024-04-24 15:39:50 +02:00
Johannes Zottele 3bd882eccc Remove title parameter 2024-04-18 14:24:04 +02:00
Johannes Zottele 6dde9c117a Update README.md 2024-04-18 12:25:38 +02:00
Johannes Zottele 260a6f55da Write README.md 2024-04-18 12:20:33 +02:00
5 changed files with 73 additions and 19 deletions
-8
View File
@@ -1,11 +1,3 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.
name: Publish Docker image
+69 -1
View File
@@ -1 +1,69 @@
# drone-gitea-messenger
# drone-gitea-message
[![Docker Pulls](https://img.shields.io/docker/pulls/jozott/drone-gitea-message)](https://hub.docker.com/r/jozott/drone-gitea-message)
Drone plugin to send message as comments to Gitea pull requests.
All releases are available on [Docker Hub](https://hub.docker.com/r/jozott/drone-gitea-message).
## Drone YAML Usage
The plugin support sending text as well as some file's content.
By setting the `delete_identifier`, all older comments with the same identifier will be
deleted before sending the message.
### Example of sending a text
```yaml
steps:
- name: send text to pr
image: jozott/drone-gitea-message:v0.2.0
settings:
api_key:
from_secret: gitea_token
base_url: http://gitea.example.com
message_text: "Hello world"
```
### Example of sending content of file
```yaml
steps:
- name: send file content to pr
image: jozott/drone-gitea-message:v0.2.0
settings:
api_key:
from_secret: gitea_token
base_url: http://gitea.example.com
message_file: path/to/hello_world.md
```
### Example with `delete_identifier`
If the `delete_identifier` is set, the plugin will delete all existing PR comments
that contain the delete identifier. This is handy if sending status updates that make
older status updates obsolete.
```yaml
steps:
- name: send test report to pr
image: jozott/drone-gitea-message:v0.2.0
settings:
api_key:
from_secret: gitea_token
base_url: http://gitea.example.com
message_file: build/test/report.md
delete_identifier: test-report-delete-id
```
## Build
To build the binary execute the following commands
```bash
export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=0
export GO111MODULE=on
go build -v -a -tags netgo -o release/linux/amd64/drone-gitea-message
```
## Run
To get all available commands run
```
./drone-gitea-message --help
```
-7
View File
@@ -39,12 +39,6 @@ func main() {
Usage: "url of the gitea instance",
EnvVar: "PLUGIN_BASE_URL,GITEA_MESSAGE_BASE_URL",
},
cli.StringFlag{
Name: "title",
Value: "",
Usage: "string for the title shown in the gitea pr comment",
EnvVar: "PLUGIN_TITLE,GITEA_MESSAGE_TITLE",
},
cli.StringFlag{
Name: "delete-identifier",
Value: "",
@@ -105,7 +99,6 @@ func run(c *cli.Context) error {
MessageText: c.String("message-text"),
MessageFile: c.String("message-file"),
BaseURl: c.String("base-url"),
Title: c.String("title"),
DeleteIdentifier: c.String("delete-identifier"),
},
}
-1
View File
@@ -12,7 +12,6 @@ type messageClient struct {
Owner string
Repo string
Index int64
Title string
Message string
DeleteIdentifier string
}
+4 -2
View File
@@ -26,7 +26,6 @@ type (
MessageText string
MessageFile string
BaseURl string
Title string
DeleteIdentifier string
}
Plugin struct {
@@ -70,6 +69,10 @@ func (p Plugin) Exec() error {
return fmt.Errorf("failed to glob %s. %s", p.Config.MessageFile, err)
}
if len(glob) == 0 {
return fmt.Errorf("no file found matching %s", p.Config.MessageFile)
}
content, err = os.ReadFile(glob[0])
if err != nil {
return fmt.Errorf("failed to read the file %s. %s", glob[0], err)
@@ -97,7 +100,6 @@ func (p Plugin) Exec() error {
Owner: p.Repo.Owner,
Repo: p.Repo.Name,
Index: p.Pr.Index,
Title: p.Config.Title,
Message: string(content),
DeleteIdentifier: p.Config.DeleteIdentifier,
}