55 Commits

Author SHA1 Message Date
appleboy b2b10008a5 refactor: refactor file handling for improved readability and performance
- Clean path and check accessibility before reading file
- Replace file reading with `os.ReadFile` for simpler code
- Remove deferred file closing as file is read into `content`
- Write file content directly to multipart form
- Add comments for clearer code sections

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-04-11 23:40:58 +08:00
appleboy b291372e68 refactor: refactor and streamline status color handling
- Handle custom color by trimming the prefix '#'
- Refactor predefined status colors into a map
- Simplify status color handling code

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-04-11 23:38:09 +08:00
appleboy 2173b97920 feat: filter out empty messages in configuration processing
- Add a check for empty messages in the configuration
- Replace the original message handling with a filtered list of non-empty messages
- Update the logic to process messages only if the filtered list is not empty

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-03-08 22:45:36 +08:00
appleboy d661b29efe feat: add debug mode for plugin configuration dumping
- Add a new dependency for godump in go.mod
- Import godump in main.go
- Introduce a debug flag in the CLI options
- Update the run function to include the debug flag
- Add logic to dump the plugin configuration if debug mode is enabled
- Extend the plugin struct to include a debug field

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-03-08 22:37:30 +08:00
appleboy 3e0f7cf5df fix: enhance error handling and reporting for API responses
- Replace direct reading of response body with error handling for reading
- Add JSON unmarshalling of the response body for better error reporting
- Improve error message format to include details from the JSON response

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-03-08 20:57:02 +08:00
appleboy 464bf4772f fix: improve error reporting for message sending failures
- Enhance error reporting by including the response body in the error message when message sending fails.
- Remove the previous error message that only included the status code.

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-03-08 17:42:58 +08:00
appleboy 8533df8e0b refactor: enhance file upload functionality with context and error handling
- Rename the function `newfileUploadRequest` to `fileUploadRequest`
- Add context parameter to the `fileUploadRequest` function
- Improve error handling by wrapping errors with descriptive messages
- Update the `Exec` method to pass context when calling `SendFile`
- Rename the `SendFile` method to accept context as a parameter

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-03-08 17:10:53 +08:00
appleboy a58131af2a feat: add support for Discord webhook URL configuration and validation
- Add a new command-line flag for the Discord webhook URL
- Update the configuration structure to include the webhook URL
- Implement validation for the webhook URL format
- Introduce a method to retrieve the webhook URL from the configuration
- Refactor the code to use the new method for generating the webhook URL in multiple places

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-03-08 17:03:50 +08:00
appleboy 3721fc313d feat: validate configuration fields in Exec method
- Remove the import of the errors package
- Add a validate method to the Config type to check for missing fields
- Update the Exec method to use the new validate method for configuration validation

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-03-08 16:56:57 +08:00
appleboy cea35a9ac9 fix: fix error handling for empty HTTP responses
- Change the condition to check for `http.StatusNoContent` instead of `http.StatusOK` before returning an error.

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-03-08 16:53:12 +08:00
appleboy 6c782afaae feat: add context support to Exec and SendMessage functions
- Update the `Exec` function to accept a context parameter.
- Modify the `SendMessage` function to also accept a context parameter.
- Add context import to the necessary files.
- Update test cases to pass a context when calling `Exec`.

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-03-08 16:43:06 +08:00
appleboy f2bd7836ef refactor: refactor HTTP request handling and improve linter settings
- Remove the `exportloopref` linter from the golangci configuration
- Add the `strconv` package import in `main.go`
- Replace the `fmt.Sprintf` for the year with `strconv.Itoa` to convert the year to a string
- Update the HTTP request method to use `http.MethodPost` instead of a string literal in `plugin.go`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-03-08 16:36:43 +08:00
appleboy 91c0d241df refactor: refactor GitHub event handling in Template function
- Refactor the handling of GitHub events in the Template function
- Replace the message construction with a switch statement for better clarity
- Simplify the logic for determining the branch in pull requests
- Update the case structure for handling different build events

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2025-03-08 16:29:54 +08:00
appleboy 692f7ff6dd feat: add support for specifying source branch in build configuration
- Add a new flag `source.branch` with default value `develop` and usage description "git source branch"
- Add a new struct `Source` with a `Branch` field
- Add a new field `Source` to the existing struct `Build`
- Add a new test case with `Source.Branch` set to "feature/awesome-feature"

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2023-12-24 19:09:34 +08:00
appleboy 242a4e9588 chore: discordapp.com is deprecated
fix https://github.com/appleboy/drone-discord/issues/41

ref: https://github.com/discordjs/discord.js/pull/4160

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2023-09-24 19:48:11 +08:00
appleboy 26bd0641dc chore(CI): update lint
Signed-off-by: appleboy <appleboy.tw@gmail.com>
2023-09-24 19:29:59 +08:00
Nils 7ac022b650 allow not setting a username for messages (closes #38) (#39) 2023-05-13 23:04:59 +08:00
Bo-Yi Wu d4b1c86367 chore: update drone-template-lib module
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-07-04 15:06:56 +08:00
Bo-Yi Wu 30be2b99d7 update build time format
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-07-23 12:16:10 +08:00
Bo-Yi Wu 11c87968e4 chore: update int64 to float64 2019-10-24 00:04:26 +08:00
Bo-Yi Wu 82e100bf9a update time format
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-10-13 01:47:31 +08:00
Bo-Yi Wu 747ffca8cc chore: remove debug message 2019-10-13 01:23:48 +08:00
Bo-Yi Wu 83561d842b remove file if empty
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-10-13 01:15:17 +08:00
Bo-Yi Wu 5eb8b48ec3 debug
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-10-13 00:39:54 +08:00
Bo-Yi Wu 1ab023c10d chore: update drone env 2019-10-12 23:33:06 +08:00
Bo-Yi Wu cfd3725c9a chore: replace template library 2019-10-11 20:42:10 +08:00
Bo-Yi Wu 11fec702d5 docs: ci skip: add ref for upload file 2019-02-27 14:40:03 +08:00
Bo-Yi Wu cf98432068 refactor: SendFile 2019-02-25 19:34:13 +08:00
Bo-Yi Wu f7ade7c458 feat(api): support upload file (#18)
fix #17
2019-02-25 17:18:39 +08:00
Bo-Yi Wu 4c4578cf55 fix: remove check ci if drone 2019-02-24 13:14:13 +08:00
Bo-Yi Wu 28fc4d6511 feat: support default message for GitHub Action 2019-02-24 13:07:12 +08:00
Bo-Yi Wu 8fbae76b71 feat: support arm platform 2019-02-24 10:32:07 +08:00
Bo-Yi Wu ebaf1ce91f refactor: color 2019-02-24 09:24:49 +08:00
Bo-Yi Wu 9815f76352 add github env
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-02-19 09:14:30 +08:00
Bo-Yi Wu bf2a768f52 fix(lint): check return error. (#9) 2018-05-28 22:28:58 +08:00
Bo-Yi Wu 07bd85b217 update drone icon and desc (#2)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-17 03:20:32 -05:00
Bo-Yi Wu cad7d92b58 add commit ref (#1)
* add commit ref

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* update to RefSpec

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-17 02:42:05 -05:00
Bo-Yi Wu a1ccf186fd refactor plugin
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-17 14:20:00 +08:00
Bo-Yi Wu 9cc7367a7c update
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-17 13:10:11 +08:00
Bo-Yi Wu 59a4e31bde add drone default template.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-17 11:31:23 +08:00
Bo-Yi Wu 1a5b8eaa1f update discord default template.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-17 00:37:22 +08:00
Bo-Yi Wu 4f39a3365e update footer text
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-17 00:03:05 +08:00
Bo-Yi Wu 405e47454a fix bugs.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-14 15:01:22 +08:00
Bo-Yi Wu 2ee04c1fb0 Add color
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-14 14:51:15 +08:00
Bo-Yi Wu 13351b0dc6 add default template
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-14 12:24:45 +08:00
Bo-Yi Wu c9991a6207 fix bugs
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-14 11:16:05 +08:00
Bo-Yi Wu 12ff54fee0 add comment
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-14 11:14:32 +08:00
Bo-Yi Wu e4a13b26fb add Embed payload
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-14 11:03:44 +08:00
Bo-Yi Wu 100ff18145 update struct.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-10 17:42:11 +08:00
Bo-Yi Wu 4d0a3378a1 add comment
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-10 17:29:46 +08:00