Skip to content

Commit

Permalink
Add support for multiple build hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
grumpyoldman-io committed Sep 18, 2018
1 parent e1c3573 commit 6c0a02a
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 55 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.1.2 - 2018-09-18
### Added
- Support for multiple hooks

> {warning} You will need to resave the existing webhooks, they will be dropped on upgrade!
## 1.0.2 - 2018-09-07
### Added
- "craftcms/cms" as a requirement for the Plugin Store. (thanks @angrybrad)
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Add Deploy hooks for Netlify

![Screemshot](resources/img/screenshot.jpg)
![Screenshot](resources/img/screenshot.png)

## Requirements

Expand All @@ -26,15 +26,14 @@ To install the plugin, follow these instructions.

## NetHooks Overview

This will add a Deploy Button to your Utilities.
This will add a Deploy Buttons to your Utilities.

## Configuring NetHooks

Go to NetHooks under settings and provide a Netlify Build Webhook [[?]](https://www.netlify.com/docs/webhooks/#incoming-webhooks)
Go to NetHooks under settings and provide one or more Netlify Build Webhooks [[?]](https://www.netlify.com/docs/webhooks/#incoming-webhooks)

## NetHooks Roadmap

* Expand the set-up to include setting deploy hooks
* Provide an overview of deploys
* deploy status

Expand Down
Binary file added assets.sketch
Binary file not shown.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "jungleminds/nethooks",
"description": "Add Deploy hooks for Netlify",
"type": "craft-plugin",
"version": "1.0.2",
"version": "1.1.2",
"keywords": [
"craft",
"cms",
Expand Down
Binary file removed logo.sketch
Binary file not shown.
Binary file removed resources/img/screenshot.jpg
Binary file not shown.
Binary file added resources/img/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions src/assetbundles/nethooksutility/dist/css/Nethooks.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
* @copyright Copyright (c) 2018 Jungle Minds
* @link https://jungleminds.com
* @package Nethooks
* @since 1.0.2
* @since 1.1.2
*/

#content .deploy + .deploy { margin-top: 24px; }
#content .deploy .deploy-header { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-align: center; -ms-flex-align: center; align-items: center; padding-bottom: 10px; border-bottom: 1px solid #e3e5e8; margin-bottom: 16px; }
#content .deploy .deploy-header .readable { -webkit-box-flex: 1; -ms-flex-positive: 1; flex-grow: 1; margin: 0; }
#content .deploy .deploy-header .buttons { margin: 0; }
#content .deploy .deploy-header .buttons button:disabled { pointer-events: none; }
#content .nethooks + .nethooks { margin-top: 24px; }
#content .nethooks .nethooks-header { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-align: center; -ms-flex-align: center; align-items: center; padding-bottom: 10px; border-bottom: 1px solid #e3e5e8; margin-bottom: 16px; }
#content .nethooks .nethooks-header .readable { -webkit-box-flex: 1; -ms-flex-positive: 1; flex-grow: 1; margin: 0; }
#content .nethooks .hooks .hook { margin-bottom: 5px; }
#content .nethooks .hooks .hook button:disabled { pointer-events: none; }
25 changes: 13 additions & 12 deletions src/assetbundles/nethooksutility/dist/js/Nethooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@
* @copyright Copyright (c) 2018 Jungle Minds
* @link https://jungleminds.com
* @package Nethooks
* @since 1.0.2
* @since 1.1.2
*/
!function ($) {
var deployButton = $('#nethooks-deploy-button');
if (deployButton) {
deployButton.on('click', function () {
$(deployButton).addClass('add loading');
$(deployButton).removeClass('submit');
$(deployButton).prop('disabled', true);
var deployButtons = $('#content .nethooks .hooks .hook button');
if (deployButtons) {
deployButtons.on('click', function () {
var _this = this
$(_this).addClass('add loading');
$(_this).removeClass('submit');
$(_this).prop('disabled', true);
$.ajax({
type: "POST",
url: $(deployButton).attr('data-build-hook'),
url: $(_this).attr('data-build-hook'),
error: function () {
$(deployButton).removeClass('add loading');
$(deployButton).addClass('submit');
$(deployButton).prop('disabled', false);
$(_this).removeClass('add loading');
$(_this).addClass('submit');
$(_this).prop('disabled', false);
},
success: function () {
$(deployButton).removeClass('add loading');
$(_this).removeClass('add loading');
}
});
});
Expand Down
5 changes: 4 additions & 1 deletion src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

return [

"buildHook" => 'https://api.netlify.com/build_hooks/...',
"buildHooks" => [[
'name' => 'default',
'url' => 'https://api.netlify.com/build_hooks/...'
]],

];
15 changes: 10 additions & 5 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @author Jungle Minds
* @package Nethooks
* @since 1.0.2
* @since 1.1.2
*/
class Settings extends Model
{
Expand All @@ -37,9 +37,12 @@ class Settings extends Model
/**
* Some field model attribute
*
* @var string
* @var array
*/
public $buildHook = 'https://api.netlify.com/build_hooks/...';
public $buildHooks = [[
'name' => 'default',
'url' => 'https://api.netlify.com/build_hooks/...'
]];

// Public Methods
// =========================================================================
Expand All @@ -57,8 +60,10 @@ class Settings extends Model
public function rules()
{
return [
['buildHook', 'string'],
['buildHook', 'default', 'value' => 'https://api.netlify.com/build_hooks/...'],
['buildHooks', 'default', 'value' => [[
'name' => 'default',
'url' => 'https://api.netlify.com/build_hooks/...'
]]],
];
}
}
34 changes: 19 additions & 15 deletions src/templates/_components/utilities/Nethooks_content.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,34 @@
* @copyright Copyright (c) 2018 Jungle Minds
* @link https://jungleminds.com
* @package Nethooks
* @since 1.0.2
* @since 1.1.2
*/
#}
{% set defaultBuildHook = 'https://api.netlify.com/build_hooks/...' %}
<div class="deploy">
<div class="deploy-header">
{% set defaultActive = buildHooks[0]['url'] == defaultBuildHook and buildHooks | length > 1 %}

<div class="nethooks">
<div class="nethooks-header">
<div class="readable left">
<h1>Nethooks</h1>
</div>
{% if buildHook|length > defaultBuildHook|length %}
<div class="buttons right">
<button
id="nethooks-deploy-button"
class="btn icon submit"
data-build-hook="{{buildHook}}"
>
{{ "Deploy"|t }}
</button>
</div>
{% endif %}
</div>
{% if buildHook|length <= defaultBuildHook|length %}
{% if defaultActive %}
<div class="warning">
<p>{{ "Please add a webhook to the plugin settings first"|t }}</p>
</div>
{% else %}
<div class="hooks">
{% for i, buildHook in buildHooks %}
<div class="hook">
<button
class="btn icon submit"
data-build-hook="{{ buildHook['url'] }}"
>
{{ "Deploy"|t }} {{ buildHook['name'] }}
</button>
</div>
{% endfor %}
</div>
{% endif %}
</div>
43 changes: 34 additions & 9 deletions src/templates/settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,42 @@
* @copyright Copyright (c) 2018 Jungle Minds
* @link https://jungleminds.com
* @package Nethooks
* @since 1.0.2
* @since 1.1.2
*/
#}

{% import "_includes/forms" as forms %}

{{ forms.textField({
label: 'Netlify Build Hook',
instructions: 'add your <a href="https://www.netlify.com/docs/webhooks/#incoming-webhooks">Build Hook</a>',
id: 'buildHook',
name: 'buildHook',
placeholder: 'https://api.netlify.com/build_hooks/...',
value: settings['buildHook']})
}}
<div class="field">
<div class="heading">
<label for="buildHook">
Netlify Build Hook
</label>
<div class="instructions">
add your <a href="https://www.netlify.com/docs/webhooks/#incoming-webhooks">Build Hooks</a></br>
&nbsp;
</div>
<div class="input">
{{
forms.editableTable({
id: 'buildHooks',
name: 'buildHooks',
addRowLabel: 'Add a buildHook',
cols: {
name: {
heading: 'Name',
type: 'singleline'
},
url: {
heading: 'URL',
type: 'singleline'
}
},
rows: settings['buildHooks']
})
}}
</div>
</div>
</div>


4 changes: 2 additions & 2 deletions src/utilities/NethooksUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @author Jungle Minds
* @package Nethooks
* @since 1.0.2
* @since 1.1.2
*/
class NethooksUtility extends Utility
{
Expand Down Expand Up @@ -70,7 +70,7 @@ public static function contentHtml(): string
return Craft::$app->getView()->renderTemplate(
'nethooks/_components/utilities/Nethooks_content',
[
'buildHook' => Craft::$app->plugins->getPlugin('nethooks')->getSettings()->buildHook
'buildHooks' => Craft::$app->plugins->getPlugin('nethooks')->getSettings()->buildHooks
]
);
}
Expand Down

0 comments on commit 6c0a02a

Please sign in to comment.