Skip to content

Commit

Permalink
[api] [view] Can now set Github repo as source
Browse files Browse the repository at this point in the history
  * Switch between code / repo / gist
  * Adds `main` entry point parameter for source
  * Ensures options are passed to stack plugin
  • Loading branch information
Marak committed Oct 14, 2016
1 parent 804e24c commit dd15d09
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 13 deletions.
18 changes: 18 additions & 0 deletions lib/resources/hook/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ hook.property('gist', {
"description": "source of the Hook provided as a Github Gist Url"
});

hook.property('githubRepo', {
"type": "string",
"required": false,
"description": "github repo of the Hook source code"
});

hook.property('githubBranch', {
"type": "string",
"required": false,
"description": "github repo branch of the Hook source code"
});

hook.property('mainEntry', {
"type": "string",
"required": false,
"description": "main entry point of service"
});

hook.property('ran', {
"type": "number",
"default": 0
Expand Down
8 changes: 5 additions & 3 deletions lib/resources/hook/runHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ module['exports'] = function runHook (opts, callback) {
console.log('using gist', gistID, req._user);
stack.plugins.sourceGithubGist({
gistID: gistID,
main: req.hook.mainEntry,
token: req._user.githubAccessToken
})(req, res, function (){
if (err) {
Expand All @@ -230,10 +231,11 @@ module['exports'] = function runHook (opts, callback) {
});
});
}
else if (typeof untrustedService.repo === "string" && untrustedService.repo.length > 0) {
else if (req.hook.sourceType === "githubRepo" && typeof req.hook.githubRepo === "string" && req.hook.githubRepo.length > 0) {
stack.plugins.sourceGithubRepo({
repo: untrustedService.repo,
branch: untrustedService.branch,
repo: req.hook.githubRepo,
branch: req.hook.githubBranch,
main: req.hook.mainEntry,
token: req._user.githubAccessToken
})(req, res, function (){
if (err) {
Expand Down
63 changes: 53 additions & 10 deletions view/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,13 @@
width: 100%;
}

.githubRepoHolder {
padding-top: 10px;
width: 100%;
display: none;
}


.missingFeature {
color: #CCCCCC;
}
Expand Down Expand Up @@ -474,16 +481,24 @@

$('#editorSource').on('click', function(){
$('.gistUrlHolder').hide();
$('.githubRepoHolder').hide();
$('.codeEditorHolder').show();
editor.refresh();
});


$('#gistSource').on('click', function(){
$('.codeEditorHolder').hide();
$('.githubRepoHolder').hide();
$('.gistUrlHolder').show();
});

$('#githubRepoSource').on('click', function(){
$('.codeEditorHolder').hide();
$('.gistUrlHolder').hide();
$('.githubRepoHolder').show();
});


$('input[name="cronActive"]').click(function(){
if($(this).prop('checked')) {
$('.cronRow').show();
Expand Down Expand Up @@ -910,32 +925,60 @@ <h2 class="warning">Warning</h2>

<div class="form-control">
<label class="radio-inline" for="editorSource">
<input tabindex="5" type="radio" value="code" class="editorSource" id="editorSource" name="hookSource" title="Specify the source of the Service from text editor">
<input type="radio" value="code" class="editorSource" id="editorSource" name="hookSource" title="Specify the source of the Service from text editor">
Code Editor
</label>
<label class="radio-inline" for="gistSource">
<input tabindex="4" type="radio" value="gist" class="gistSource" id="gistSource" name="hookSource" title="Specify the source of the Service as a Github Gist">
<input type="radio" value="gist" class="gistSource" id="gistSource" name="hookSource" title="Specify the source of the Service as a Github Gist">
Github Gist
</label>
<label class="radio-inline" for="githubRepoSource">
<input type="radio" value="githubRepo" class="githubRepoSource" id="githubRepoSource" name="hookSource" title="Specify the source of the Service as a Github Gist">
Github Repo
</label>
</div>

</div>

<div class="form-group gistUrlHolder">
<label for="gist">Gist Url</label>
<input tabindex="6" type="text" class="form-control gist" name="gist" id="gist" placeholder="https://gist.github.com/Marak/357645b8a17daeb17458" value="https://gist.github.com/Marak/357645b8a17daeb17458" size="80">
<input type="text" class="form-control gist" name="gist" id="gist" placeholder="https://gist.github.com/Marak/357645b8a17daeb17458" value="https://gist.github.com/Marak/357645b8a17daeb17458" size="80"/>
<div class="tiny" style="padding-left:5px;padding-top:5px;">
<a href="https://gist.github.com/new" target="_blank" id="fork" name="fork" type="submit">Click here to create new Github Gist</a>
</div>

<label for="mode" class="i18n">Mode</label>
<select class="form-control mode" name="mode">
<option value="Development" class="i18n">Development</option>
<option value="Production" class="i18n">Production</option>
</select>
<p class="smaller" class="i18n"><strong class="i18n">Important:</strong> Setting Mode to <code>Production</code> will greatly improve the performance of the Service by caching it's source files. Setting Mode to <code>Development</code> will ensure the latest source files are always pulled ( which will cause longer response times for your Hook )</p>
<label for="gistMainEntry">Main Entry Point</label>
<input type="text" class="form-control gistMainEntry" name="gistMainEntry" id="gistMainEntry" placeholder="index.js" value="" size="80"/>

<!--
<label for="mode" class="i18n">Mode</label>
<select class="form-control mode" name="mode">
<option value="Development" class="i18n">Development</option>
<option value="Production" class="i18n">Production</option>
</select>
<p class="smaller" class="i18n"><strong class="i18n">Important:</strong> Setting Mode to <code>Production</code> will greatly improve the performance of the Service by caching it's source files. Setting Mode to <code>Development</code> will ensure the latest source files are always pulled ( which will cause longer response times for your Hook )</p>
-->

</div>

<div class="form-group githubRepoHolder">
<label for="repo">Repo Name</label>
<input type="text" class="form-control repo" name="repo" id="repo" placeholder="stackvana/microservice-examples" value="" size="80"/>

<label for="repo">Repo Branch</label>
<input type="text" class="form-control repo" name="branch" id="branch" placeholder="master" value="" size="80"/>

<label for="githubMainEntry">Main Entry Point</label>
<input type="text" class="form-control githubMainEntry" name="githubMainEntry" id="githubMainEntry" placeholder="index.js" value="" size="80"/>

<!--
<label for="mode" class="i18n">Mode</label>
<select class="form-control mode" name="mode">
<option value="Development" class="i18n">Development</option>
<option value="Production" class="i18n">Production</option>
</select>
<p class="smaller" class="i18n"><strong class="i18n">Important:</strong> Setting Mode to <code>Production</code> will greatly improve the performance of the Service by caching it's source files. Setting Mode to <code>Development</code> will ensure the latest source files are always pulled ( which will cause longer response times for your Hook )</p>
-->
</div>

<div class="form-group codeEditorHolder">
Expand Down
8 changes: 8 additions & 0 deletions view/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ module['exports'] = function view (opts, callback) {
params.source = params.codeEditor;
} else if (params.hookSource === "gist") {
delete params.source;
data.mainEntry = params.gistMainEntry;
} else if (params.hookSource === "githubRepo") {
data.githubRepo = params.repo;
data.githubBranch = params.branch;
data.mainEntry = params.githubMainEntry;
}

data.sourceType = params.hookSource;
Expand Down Expand Up @@ -344,6 +349,9 @@ module['exports'] = function view (opts, callback) {
if (h.sourceType === "gist") {
$('#gist').attr('value', h.gist);
$('#gistSource').attr('checked', 'CHECKED');
} else if (h.sourceType === "githubRepo") {
$('#repo').attr('value', h.repo);
$('#gistSource').attr('checked', 'CHECKED');
} else {
$('#editorSource').attr('checked', 'CHECKED');
$('.gistUrlHolder').attr('style', 'display:none;');
Expand Down

0 comments on commit dd15d09

Please sign in to comment.