Skip to content

monkey-projects/plugin-pushover

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MonkeyCI Pushover Plugin

This is a MonkeyCI plugin that provides a build job that sends a message to Pushover. This makes it possible to send notifications from your builds.

Usage

Clojars Project

First include it in your build deps.edn:

com.monkeyci/plugin-pushover {:mvn/version "0.1.1"}

Or when using Leiningen:

[com.monkeyci/plugin-pushover "0.1.1"]

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

(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:

(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!

(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.

;; 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:

(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).

(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

MIT License

About

MonkeyCI plugin to send to pushover

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors