Last active
December 11, 2017 19:33
-
-
Save glennblock/34e28dc294a6ad67d31bac62844bbb82 to your computer and use it in GitHub Desktop.
jira-webtask.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var Webtask = require('webtask-tools'); | |
var bodyParser = require('body-parser'); | |
var app = express(); | |
app.use(bodyParser.json()); | |
module.exports = Webtask.fromExpress(app); | |
app.get('/helloworld.html', function(req, res) { | |
res.send(helloworld); | |
}); | |
app.get('/atlassian-connect.json', function(req, res) { | |
res.send(descriptor); | |
}); | |
app.post('/issue_created', function(req,res) { | |
console.log(`Issue created\r\n${0}`, req.body); | |
}); | |
app.post("/comment_created", function(req,res) { | |
console.log(`Comment created\r\n${0}`, req.body); | |
}) | |
var descriptor = ` | |
{ | |
"name": "Hello World", | |
"description": "Atlassian Connect add-on", | |
"key": "com.example.myaddon", | |
"baseUrl": "https://wt-glenn-block-gmail-com-0.run.webtask.io/jira-hello-world", | |
"vendor": { | |
"name": "Auth0", | |
"url": "https://auth0.com" | |
}, | |
"authentication": { | |
"type": "none" | |
}, | |
"scopes": [ | |
"read" | |
], | |
"apiVersion": 1, | |
"modules": { | |
"generalPages": [ | |
{ | |
"url": "/helloworld.html", | |
"key": "hello-world", | |
"location": "system.top.navigation.bar", | |
"name": { | |
"value": "Greeting" | |
} | |
} | |
], | |
"webhooks": [ | |
{ | |
"event": "jira:issue_created", | |
"url": "/issue_created", | |
"excludeBody": false | |
}, | |
{ | |
"event": "comment_created", | |
"url": "/comment_created", | |
"excludeBody": false | |
} | |
] | |
} | |
}`; | |
var helloworld = ` | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<link rel="stylesheet" href="//aui-cdn.atlassian.com/aui-adg/5.9.12/css/aui.min.css" media="all"> | |
</head> | |
<body> | |
<section id="content" class="ac-content"> | |
<div class="aui-page-header"> | |
<div class="aui-page-header-main"> | |
<h1>Hello from Webtask</h1> | |
</div> | |
</div> | |
</section> | |
<script id="connect-loader" data-options="sizeToParent:true;"> | |
(function() { | |
var getUrlParam = function (param) { | |
var codedParam = (new RegExp(param + '=([^&]*)')).exec(window.location.search)[1]; | |
return decodeURIComponent(codedParam); | |
}; | |
var baseUrl = getUrlParam('xdm_e') + getUrlParam('cp'); | |
var options = document.getElementById('connect-loader').getAttribute('data-options'); | |
var script = document.createElement("script"); | |
script.src = baseUrl + '/atlassian-connect/all.js'; | |
if(options) { | |
script.setAttribute('data-options', options); | |
} | |
document.getElementsByTagName("head")[0].appendChild(script); | |
})(); | |
</script> | |
</body> | |
</html>`; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment