An open API service indexing awesome lists of open source software.

https://github.com/monkey-projects/plugin-pushover

MonkeyCI plugin to send to pushover
https://github.com/monkey-projects/plugin-pushover

Last synced: 4 months ago
JSON representation

MonkeyCI plugin to send to pushover

Awesome Lists containing this project

README

          

# MonkeyCI Pushover Plugin

This is a [MonkeyCI](https://monkeyci.com) plugin that provides a build job
that sends a message to [Pushover](https://pushover.net). This makes it
possible to send notifications from your builds.

## Usage

[![Clojars Project](https://img.shields.io/clojars/v/com.monkeyci/plugin-pushover.svg)](https://clojars.org/com.monkeyci/plugin-pushover)

First include it in your build `deps.edn`:
```clojure
com.monkeyci/plugin-pushover {:mvn/version "0.1.1"}
```

Or when using Leiningen:
```clojure
[com.monkeyci/plugin-pushover "0.1.1"]
```

In order to add a job to your build, invoke the `pushover-msg` function:

```clojure
(require '[monkey.ci.plugin.pushover :as pp])

[my-other-jobs
;; Add a job to your build that will send the message
(pp/pushover-msg {:msg "Hi, this is a message from pushover"})]
```

At the very least, you should provide a `msg`, which can either be a string,
or a function. If it's a function, it will be passed the build context, so
you can generate a message depending on the situation. Any other options
(apart from the credentials, see below), are either directly passed to the
Pushover API, or the build job.

The default job id is `pushover`, but you can override this by specifying
the `:id` property.

## Credentials

In order to push a message, you need to have an account. By default, the plugin
will fetch the user and token from the build parameters. The default parameter
keys are `pushover-user` and `pushover-token`. But you can override these
by specifying the `:user-param` and `:token-param` options. Like so:

```clojure
(pp/pushover-msg {:msg "some test message"
:user-param "overridden-user"
:token-param "overridden-token"})
;; This will create a job that will post to Pushover using the user and token
;; fetched from the build parameters respectively as "overridden-user" and
;; "overridden-token".
```

You can also directly specify the credentials, although this is not advised from
a security point of view!
```clojure
(pp/pushover-msg {:msg "test message"
:user "test-user"
:token "test-token"})
```

## Dependencies

You can make the job dependent on another job by adding them to the `:dependencies`
option. It will be automatically passed on to the job configuration.
```clojure
;; This job will only be executed if "other-job" has succeeded.
(pp/pushover-msg {:msg "test message" :dependencies ["other-job"]})
```

## Other Actions

`pushover-msg` creates an action job of its own. However, in some situations you may
want to combine this functionality with other functions, without creating multiple
jobs in your pipeline. In order to do this you could either directly call the Pushover
API, but you can also call the action function that does the work directly. For this,
you can use `pushover-action`. It takes the same configuration as the job, and also
the build context. This is necessary to fetch some additional information, like the
credentials should they not be passed in directly.

For example, you could do this:
```clojure
(ns build
(:require [monkey.ci.api :as m]
[monkey.ci.plugin.pushover :as pp))

(def combined-job
(m/action-job
"combined-job"
(fn [ctx]
;; Only send a message if the condition returns true
(when (do-something-complicated ctx)
(pp/pushover-action {:msg "The complicated action has finished"} ctx)))))
```

## Testing

In unit tests it may be cumbersome to mock out the actual network call to the Pushover
API. So to make it easier, you can pass in your own `poster` function in the job
configuration. This receives the same configuration as would be passed to the default
poster, which allows you to investigate the parameters in tests. The poster is expected
to return a HTTP response with a valid status (typically `200`).

```clojure
(pp/pushover-msg {:msg "test message"
:poster (fn [conf]
(println "This is a fake poster")
{:status 200})})
```

## License

Copyright (c) 2024-2026 by [Monkey Projects](https://www.monkey-projects.be)

[MIT License](LICENSE)