# Create a status nudge button in Github

{% hint style="info" %}
🍎 Before you begin this tutorial, make sure you've completed the [Developer Quick Start Guide](https://docs.pixiebrix.com/quick-start/mod-developer).
{% endhint %}

I don’t know about you, but I struggle with communicating through GitHub sometimes. As a developer, I do a lot of work there, but I can’t keep up with the comments there. *(Maybe I just haven’t figured out how to configure my GitHub notification settings… but that seems like another post entirely 😂 )*

At PixieBrix, we developed a way to click one button when we're inside an issue on GitHub, and it sends a message to Slack letting the team know what we're working on. (This was built with PixieBrix, of course!)

Here's how it looks!

{% embed url="<https://www.youtube.com/watch?v=fHqc2AF4pOY>" %}

### 📺 Prefer to watch this instead of reading along? Here's a video tutorial! <a href="#block-1fa99d563ab24bd9bc36ab6de955ccb8" id="block-1fa99d563ab24bd9bc36ab6de955ccb8"></a>

If you prefer to watch a video instead, follow along here:

{% embed url="<https://www.youtube.com/watch?v=njOVzjtWDyw>" %}

The following steps are written instructions from the video above.&#x20;

### 1. Start with a Button Brick <a href="#block-63b276420fe442c59496dcec622c44bb" id="block-63b276420fe442c59496dcec622c44bb"></a>

First, navigate to an issue in GitHub. Feel free to use [this URL](https://github.com/pixiebrix/pixiebrix-extension/issues/2302) as an example. Open the [PixieBrix Page Editor](https://docs.pixiebrix.com/platform-overview/page-editor/open-the-page-editor) (fn + F12 on your keyboard, then select the PixieBrix tab).

Add a Button starter brick. Click **New Mod** then choose **Button**.

<figure><img src="https://2274778196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq123bF1HPQPV35s5vHa1%2Fuploads%2Fw40xmpQd4y1vGLpmpD5x%2FCleanShot%202024-10-16%20at%2009.44.16.png?alt=media&#x26;token=96af067b-115f-4b39-8f8a-549ca887175b" alt=""><figcaption></figcaption></figure>

Click the arrow to select a button on GitHub that you want to duplicate. *I chose the “New issue” button, but you can select any other one.*

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/da8e2767-2efb-4015-a555-542d7be5e454/Untitled/w=640,quality=80" alt="" width="375"><figcaption></figcaption></figure>

Set the caption to “Send Status” - you can name it whatever you’d like; this is just the text that shows up on the button, so it won’t impact any of the other steps!

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/2ae62e53-89ad-4d7b-ac40-4918045fb7e4/Untitled/w=3840,quality=80" alt="" width="375"><figcaption></figcaption></figure>

You’ll also want to specify which sites you want this button to appear on. In this case, we only want it to appear on GitHub.

### 2. Grab the Username <a href="#block-4f50561737314a95b676f3ffe02682b9" id="block-4f50561737314a95b676f3ffe02682b9"></a>

Now we need to add another brick to get the username of the person clicking the button (aka, who is logged in).

**a) Add the “Simulate a DOM event” brick.**

{% hint style="info" %}
📢Wondering what we’re doing here? We’re clicking the profile button, so it shows your username at the top right! Go ahead and try it out for yourself and see.
{% endhint %}

Click the **+** button underneath your Button Brick to add another brick.

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/d614e245-69b1-4f29-95bc-c2f8c2e6cc38/Untitled/w=1080,quality=80" alt="" width="375"><figcaption></figcaption></figure>

Search for the Simulate DOM Event Brick, and then click **+ Add**.

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/3fde63f1-5205-46eb-ac30-d21a0291a62e/Untitled/w=3840,quality=80" alt=""><figcaption></figcaption></figure>

Click into the selector box to see a pointer button appear. Click that, and you can then select the profile button from the top right corner of your GitHub page…

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/8be6a9e0-59bd-4a01-abbc-a69ebd9c0ae2/Untitled/w=1080,quality=80" alt="" width="375"><figcaption></figcaption></figure>

… or copy the code below in the \`selector\` box.

`[aria-label='View\ profile\ and\ more']`

In the Event field, select the click option.

This is what your configuration should look like.

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/bdd58c09-5dd4-4a8c-bd8c-213564122871/Untitled/w=3840,quality=80" alt="" width="375"><figcaption></figcaption></figure>

**b) Add the “Wait for a DOM element” brick**

We need to wait for a second for the profile menu to load before looking for the username, so we will add this brick and tell it what element we’re waiting for.

Once again, select the **+** below your other brick to add another brick. This time search for the `Wait for a DOM element` brick, then press **+ Add**.

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/34b2afee-e39d-4380-9f7f-5d10fb4f755f/Untitled/w=3840,quality=80" alt="" width="375"><figcaption></figcaption></figure>

Again, you can select (with the pointer button) OR type this into the field.

`.user-profile-link strong`

Your settings should look like this

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/9e973e26-5d37-4cfd-8f1a-25bbdc67a939/Untitled/w=3840,quality=80" alt="" width="375"><figcaption></figcaption></figure>

*You can leave the max wait time field blank.*

**c) Add the Extract from Page brick**

Now we need to go look for the value of that specific element! (Aka… the GitHub username!) We’re saying here, “hey, remember that thing I told you to watch for loading? Well, it loaded. Can you look up what it is and save that as a value I can reference later?”

Select the **+** below your other bricks to add another brick. Search for the `Extract from Page` brick, then press **+ Add**.

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/5ad86556-dbac-4f7d-8f49-00bc350d8a58/Untitled/w=3840,quality=80" alt="" width="375"><figcaption></figcaption></figure>

Edit the property name (I called it `username` to make it easy to reference, but you can call it whatever you like), and for the value, use the same value you used in the last brick.

`.user-profile-link strong`

You can also **change the output** at the top to `gh` to more easily reference that later.

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/266f0401-991c-4940-ac3d-d6813cfe835d/Untitled/w=3840,quality=80" alt=""><figcaption></figcaption></figure>

**d) Copy the Simulate DOM Event brick from above.**

Now we need to close the profile menu, so the page returns to its standard look. This brick should look **exactly** like the one we made in step 1. Rather than adding another brick, we can copy the one we already made! Go to the Simulate a DOM brick, click the copy clipboard icon at the top of the bricks, and then paste it below the Extract from Page Reader.

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/bce23425-da49-45c7-a067-d03a084d0971/Untitled/w=640,quality=80" alt="" width="375"><figcaption></figcaption></figure>

And now you’ve opened the modal, gotten the username, and closed it! You’ll be able to reference the GitHub username with `{{@gh.username}}`! *(But more on that in a few steps.)*

### 3. Select a status and add a message <a href="#block-ec5eea101784490eaea09954a4ee1237" id="block-ec5eea101784490eaea09954a4ee1237"></a>

We will give the user a way to select their action on the issue and provide an additional note before sending it to Slack.

We’ll add a **“Show a modal or sidebar form”** brick to do that. Select the **+** below your other bricks to add another brick. Search for the `Show a modal or sidebar form` brick, then press **+ Add**.

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/647ff696-d998-4324-91f6-4d7afaa15d22/Untitled/w=3840,quality=80" alt=""><figcaption></figcaption></figure>

Give the form a title, such as `Update Status in Slack`. You can add a description if you want or leave it blank.

Now, let’s create a status drop-down field for this form. Give it a name that you’ll use to reference the value later. I chose `status`. Update the Label value to update the text above the field. You can see the preview on the right side of the page if you’re wondering what it will look like.

You can add a field description or leave it blank.

Next, select an Input Type. I will choose `Dropdown` so people can quickly pick a status rather than have to write one. Add options by clicking the **Add Item** button. Set a default one to be the one you think would be most commonly used, perhaps something like “working on”. This is how your first field might look.

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/9902703b-b41d-435c-a7dd-b026390d9f7a/Untitled/w=3840,quality=80" alt=""><figcaption></figcaption></figure>

Add one more field by scrolling back to the top and selecting the **+ Add new field** button. Call it `message`, and change the input type to Paragraph Text.

Your form should now look like this:

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/b2afe473-c6f5-48d9-8ccc-dab897b59831/Untitled/w=3840,quality=80" alt=""><figcaption></figcaption></figure>

Finally, update the “**Submit Button Text**” to say “**Send update**” instead of “**Submit**”.

Now we just need to ship it off to Slack!

### 4. Send all the data to Slack <a href="#block-4a9772bd3076440f873d2a1999da4523" id="block-4a9772bd3076440f873d2a1999da4523"></a>

We’ve got all sorts of data now! Let’s review:

* Github username ✅
* Github URL and title of issue (from the context in the first brick) ✅
* Status ✅
* Optional message to go with a status ✅

Time to plug it all into Slack!

1. **Add the Slack Send Simple Message** brick.

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/1bc5a3be-0665-4691-b6dd-553e0dde3386/Untitled/w=3840,quality=80" alt=""><figcaption></figcaption></figure>

You’ll need to set up a Slack integration if you haven’t already. You can do that by clicking the link below the `Slack` field. It’s as simple as going to the Integration page in the [Admin Console](https://app.pixiebrix.com/), selecting **+ Add Integration**, searing for Slack, and following the prompts to approve and connect your Slack workspace, like this.

<figure><img src="https://assets.super.so/ba851d67-1c75-48a9-b05e-2423d4987620/images/9feda483-a29d-48be-8d81-82648df07546/Untitled.gif?w=1500" alt=""><figcaption></figcaption></figure>

Time to plug all our data into the format of a message! You can style the message however you want, but I prefer to style it like this.

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/ea59027c-0a5b-4ac0-947e-a375febc77ce/Untitled/w=3840,quality=80" alt=""><figcaption></figcaption></figure>

*Feel free to copy and paste that block if you don’t want to type it out.*

```
{{@gh.username}} is {{@form.status}} <{{@input.url}}|{{@input.title}}> {{@form.message}}
```

Set the channel you’d like these updates posted to. Make sure to include the `#` in the name (or an `@` if it’s a DM).

Now click save, and go try it out!

Clicking the **Save** icon will bring up a modal for [packaging-a-mod](https://docs.pixiebrix.com/developing-mods/sharing-mods/packaging-a-mod "mention"). Set an alias (like a username) if you haven't already and give the mod a unique ID and description, then click **Create**.

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/08fe6051-579a-4b41-9cca-6ee86cbe65d3/Untitled/w=3840,quality=80" alt=""><figcaption></figcaption></figure>

Head over to any Github issue and you should see that new button on the page. Click it, select a status, add a message if you want, click send, then go check slack for your message!

<figure><img src="https://assets.super.so/ba851d67-1c75-48a9-b05e-2423d4987620/images/85d8b8ab-1478-4700-898d-413a388abd5c/github-status-demo.gif?w=1500" alt=""><figcaption></figcaption></figure>

### 🐛 Not working? Here’s a checklist for debugging <a href="#block-5ab63e4494ef40a69cfb19fb136d91e3" id="block-5ab63e4494ef40a69cfb19fb136d91e3"></a>

* Did you **grant PixieBrix permission** to view the page? Hit refresh on the page while you have the page inspector open and see if something pops up asking you to grant access.
* Use the **“Window alert” brick as a “console.log”** where you can type in variables and see what PixieBrix thinks it's returning. If it’s not returning the right thing there, then you need to change your variable.
* Make sure you have the **right syntax** on your fields.
  * Creating a URL in the slack message is \<URL|text>
  * Variables should have two {{ around them and an @ symbol at the front<br>

{% hint style="info" %}
&#x20;🙋 Need some help with building? [Head over to the Slack Community](https://slack.pixiebrix.com/), and we’ll gladly help you!
{% endhint %}
