How to: Get push notifications from GitHub
Tags: github, actions, push, notifications
Published: 2019-11-12 09:23:23

If you’ve got a mobile phone, then you probably know what push notifications are. A [push notification](https://www.twilio.com/docs/glossary/what-is-push-notification) (also known as a server push notification) is the delivery of information to a computing device from an application server where the request for the transaction is started by the server rather than by an explicit request from the client.

> We will use Push ([push.techulus.com](https://push.techulus.com)) as the medium for receiving push notifications.

In this article, we’ll be discussing how we can get notifications from GitHub as push notifications on our device.

# Let’s get started

We will setup a real-time push notification workflow using [GitHub actions](https://github.com/marketplace/actions/send-push-notification) (FYI, we could do the same using [Zapier integration](https://zapier.com/platform/public-invite/7743/eacfd29c4087cb67e7798c9876698682/) also). Before we start, make sure you’ve setup your account at [push.techulus.com](https://push.techulus.com/), installed the app on your device and copied the API key.

![1_aZajy6OtuvSyE26rZIFDLQ.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1573550060239/nBKysFjL6.png)

Now that we have everything ready, let’s create our workflow on GitHub. We will create a workflow that sends a push notification whenever there is a new issue in our repository.

**Step 1.** Open your GitHub repository page (I will use this repository [https://github.com/arjunkomath/ama](https://github.com/arjunkomath/ama)) and go to **Actions** page.

![1_91_bKN62hBMmZCgrarpjvw.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1573550083777/7lEG7R6RK.png)

**Step 2.** To create a new workflow click on “New workflow” or “Set up a workflow yourself” button. Now GitHub will draft a new workflow for you with an `echo Hello, world!` command. Let’s change this and add our custom action.

**Step 3.** Rename the file to `issues_push.yml` and then paste the following into your editor.

```
name: Notify issues

on:
  issues:
    types: [opened]

jobs:
  push:

    runs-on: ubuntu-latest

    steps:
    - name: Send Push Notification
      uses: techulus/push-github-action@v0.0.2
      env:
        API_KEY: ${{ secrets.PUSH_API_KEY }}
        MESSAGE: "There is a new issue 😅"</span>
```

Let’s go through the lines one by one:

*   The first line defines the `name` of this workflow
*   The second line specify the trigger for this workflow, in our case it is when a new issue is opened
*   Next we have defined a job `push` that runs on `ubuntu-latest` , the [virtual environment](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners) in which our workflow commands will be executed.
*   Finally, we have the steps for the workflow which is to send the actual notification. We will use [Send Push Notification](https://github.com/marketplace/actions/send-push-notification) action that has been published to GitHub marketplace.
*   Below that we’ve specified our `API_KEY` as a secret and at last the message for our notification. We will see how to create a secret in a moment.

Commit this file to master and we have created our workflow! 🎉

**Step 4.** Before testing the notification we have to create a secret to store our `API_KEY` . Open your repository settings and go to secrets tab and then click on **Add a new secret.**

![1_QxVgmlDA-jbRXKUQUBGXnw.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1573550109904/0B7o4bMPA.png)

Enter the name as `PUSH_API_KEY` (we specified this in our workflow using `secrets.PUSH_API_KEY` ) and enter the API key you copied from push console as the value. Click on **Add secret** and we’re done!

![1_UhU2Zq1edR_oN9v_qTvhkA.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1573550196132/tEWuuw_iu.png)

Time to test our workflow, create a new issue in your repository and momentarily you should get the notification on your device.

![1_3t5btXWbEh385vAMps546Q.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1573550236786/IJrHH0NXW.png)

We can reuse the same action to implement different notifications based on different triggers. You can find more examples on the marketplace page [https://github.com/marketplace/actions/send-push-notification](https://github.com/marketplace/actions/send-push-notification).

Feel free to leave comments in case you have any questions.

Thank you!