Permalink
Browse files

Merge pull request #92 from racker/release_notes

Release notes
  • Loading branch information...
kans committed May 1, 2012
2 parents c37c91a + dfbd9ca commit 951c08c7ef49df08a4519c769bff673c380e7023
View
@@ -1,3 +1,21 @@
+/*
+ * Copyright 2011 Rackspace
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
var http = require('http'),
https = require('https'),
fs = require('fs'),
@@ -28,7 +46,7 @@ var generate_worker = function(name, devopsjson_url) {
console.log("Error writing file ", devopsjson_url, filename, error);
next(error, null);
}else{
- fs.writeFile(filename, data, function (err) {
+ fs.writeFile(filename, data.data, function (err) {
if (err) {
console.log("Error writing file ", filename, err);
} else {
View
@@ -1,12 +1,31 @@
+/*
+ * Copyright 2011 Rackspace
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
var fs = require('fs');
var path = require('path');
var http = require('http');
var https = require('https');
+var url = require('url');
+var JSV = require('JSV').JSV;
+var _ = require('underscore');
+
var urls = require('./web/urls');
var settings = require('./settings');
var schema = require('../extern/devopsjson/lib/web/schema').schema;
-var JSV = require('JSV').JSV;
-var _ = require('underscore');
// A bunch of enum like things for the stats push API (no hidden interfaces via magic strings!)
var HEALTH_UNKNOWN = 0;
@@ -286,26 +305,74 @@ exports.load_devops = function(devops_path) {
* @param {fn} on_error callback that takes an Exception as a parameter
*/
exports.request_maker = function(options, call_back) {
- var method = options.port === 443 ? https : http;
- var req = method.get(options, function(res) {
+ var post_data = "";
+ var headers = {};
+ if ( options.post_data !== undefined ){
+ post_data = JSON.stringify(options.post_data);
+ delete options.post_data;
+ }
+
+ headers['Content-length'] = post_data.length;
+
+ if (options.headers){
+ _.extend(options.headers, headers);
+ }else{
+ options.headers = headers;
+ }
+
+ var req = https.request(options, function(res) {
var data = '';
res.setEncoding('utf8');
res.on('data', function(d) {
data += d;
});
res.on('end', function() {
- //TODO: this is pretty strange, change me.
try{
- call_back(null, data);
+ call_back(null, {data: data, res: res});
}catch(e){
- call_back(e, data);
+ call_back(e, {data: data, res: res});
}
});
- }).on('error', function(e) {
+ });
+ req.on('error', function(e) {
call_back(e, null);
});
+
+ if (post_data){
+ req.write(post_data);
+ }
+ req.end();
};
+/**
+ *
+ * @param devops_github
+ * @param is_closed
+ * @returns
+ */
+exports.github_request_options = function(api_config, uri) {
+ var parsed = url.parse(uri || api_config.url);
+ var _path = parsed.path === '/' ? [
+ "/repos/",
+ api_config.org,
+ "/",
+ api_config.repo,
+ '/pulls?state=closed&per_page=100&page=1'
+ ].join('') : parsed.path;
+
+ return {
+ return_response: true,
+ host: parsed.host,
+ port: 443,
+ path: _path,
+ method: 'GET',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': exports.create_basic_auth(api_config.username,
+ api_config.apikey)
+ }
+ };
+};
/**
* @param string
* @returns new string with first letter capitalized
View
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2011 Rackspace
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
var path = require('path');
var fs = require('fs');
@@ -9,6 +25,7 @@ var express = require('express');
var load_devops = require('./load_devops');
var middleware = require('./middleware');
var routes = require('./routes');
+var routes_secure = require('./routes_secure');
var utils = require('../utils');
var settings = require('../settings');
var pollers = require('./pollers');
@@ -62,9 +79,12 @@ exports.run = function(port, devops_directory, host) {
pollers.install(devops, function(polling_data){
app.use(middleware.injector.inject(polling_data, devops));
- routes.install(app, secure_app, status_api, devops);
+
+ routes.install(app, status_api, devops);
app.listen(port, host);
+
if (secure_app){
+ routes_secure.install(secure_app, status_api, devops);
secure_app.listen(443, '0.0.0.0');
}
if (settings.testing !== true){
@@ -79,7 +79,8 @@ var jade_locals = utils.make_class({
}
if (related_apis.github) {
- _navbar.DevHealth = urls.DEVHEALTH.replace(':project', project);
+ _navbar['Dev Health'] = urls.DEVHEALTH.replace(':project', project);
+ _navbar['Release Notes'] = urls.RELEASE_NOTES.replace(':project', project);
}
_navbar["Service Health"] = urls.SERVICE_HEALTH.replace(':project', project);
@@ -27,8 +27,8 @@ request.prototype = {
}
};
-module.exports = function dreadnot(payload, api_config) {
-
+module.exports = function dreadnot(payload) {
+ var api_config = payload.config;
var requests = [];
_.each(api_config.stacks, function(a_stack){
_.each(_.keys(a_stack), function(stack_name){
@@ -53,7 +53,7 @@ module.exports = function dreadnot(payload, api_config) {
try{
_.each(results, function(value){
- value = JSON.parse(value);
+ value = JSON.parse(value.data);
if (value instanceof Array){
stacks[value[0].stackName].deploys = value;
}else{
@@ -7,10 +7,11 @@ var url = require('url');
/** Adds github field to devops if github related api is present
* @param {object} devops devops object
*/
-module.exports = function github(payload, api_config) {
-
+module.exports = function github(payload) {
+ var api_config = payload.config;
var open_options = make_github_options(api_config);
var closed_options = make_github_options(api_config, true);
+
var pulls;
async.parallel({
@@ -31,7 +32,7 @@ module.exports = function github(payload, api_config) {
try{
// open_pull_requests: github response string
_.each(results, function(val, key) {
- val = JSON.parse(val);
+ val = JSON.parse(val.data);
data = data.concat(val);
});
data = parse_github_response(data);
@@ -26,8 +26,8 @@ module.exports = _highscores;
/** Adds github field to devops if github related api is present
* @param {object} devops devops object
*/
-function _highscores(payload, api_config) {
-
+function _highscores(payload) {
+ var api_config = payload.config;
var options = {
host: api_config.url,
port: api_config.port,
@@ -43,7 +43,7 @@ function _highscores(payload, api_config) {
return;
}
- data = JSON.parse(results);
+ data = JSON.parse(results.data);
var position = 1;
var modifier = " ";
View
@@ -27,14 +27,25 @@ var polling_apis = {
github: require('./github'),
new_relic: require('./new_relic'),
dreadnot: require('./dreadnot'),
- highscores: require('./highscores')
+ highscores: require('./highscores'),
+ release_notes: require('./release_notes')
};
+
+// which apis does a given poller depend on?
+var poller_to_relatedapi = {release_notes: 'github'};
+// defaults to its own name
+_.each(polling_apis, function(val, name){
+ if (!poller_to_relatedapi[name]){
+ poller_to_relatedapi[name] = name;
+ }
+});
+
var to_call = [];
-var _install_api = function(api, api_config, payload){
+var _install_api = function(api, payload){
var call_api = function(){
try{
- api(payload, api_config);
+ api(payload);
}catch (e){
payload.error = e;
}
@@ -44,7 +55,7 @@ var _install_api = function(api, api_config, payload){
call_api();
// NOTE: we don't make users wait for all api calls to finish, just to start
cb();
- setInterval(call_api, 5*60*1000);
+ setInterval(call_api, payload.config.poll_interval || 5*60*1000);
});
};
@@ -57,6 +68,7 @@ exports.install = function(devops, cb){
var name;
var this_devops;
var payload;
+ var related_api_name;
for (name in polling_apis){
api = polling_apis[name];
this_devops = devops[project];
@@ -66,11 +78,13 @@ exports.install = function(devops, cb){
//TODO: change payload to use setters/getters and freeze it to avoid accidentally setting errors/err, etc
payload = {error: null, data: null, config: null};
polling_data[project][name] = payload;
- if (!this_devops.related_apis || !this_devops.related_apis[name]) {
+ related_api_name = poller_to_relatedapi[name];
+ if (!this_devops.related_apis || !this_devops.related_apis[related_api_name]) {
continue;
}
- payload.config = this_devops.related_apis[name];
- _install_api(api, this_devops.related_apis[name], payload);
+
+ payload.config = this_devops.related_apis[related_api_name];
+ _install_api(api, payload);
}
});
@@ -1,7 +1,8 @@
var utils = require('../../utils'),
NewRelicApi = require('newrelicapi');
-module.exports = function _new_relic(payload, api_config) {
+module.exports = function _new_relic(payload) {
+ var api_config = payload.config;
var appid = api_config.appid;
var nra = new NewRelicApi({
apikey: api_config.apikey,
@@ -8,7 +8,8 @@ var _ = require('underscore');
* on_end_cb a callback that gets called with the XHR response data
*/
-module.exports = function(payload, api_config) {
+module.exports = function(payload) {
+ var api_config = payload.config;
// PagerDuty requires the date range for all requests.
var now, until, options;
@@ -42,7 +43,7 @@ module.exports = function(payload, api_config) {
return;
}
try{
- payload.data = JSON.parse(data);
+ payload.data = JSON.parse(data.data);
} catch (e){
payload.error = e;
return;
@@ -0,0 +1,5 @@
+var _ = require('underscore');
+var util = require('util');
+var utils = require('../../utils');
+var async = require('async');
+var url = require('url');
@@ -35,7 +35,8 @@ var selection = ["Custom_Severity.Name",
"Scope",
"Priority"];
-module.exports = function(payload, api_config) {
+module.exports = function(payload) {
+ var api_config = payload.config;
var options = {
port: api_config.port,
host: api_config.host,
@@ -77,7 +78,7 @@ module.exports = function(payload, api_config) {
payload.error = error;
return;
}
- var etree = et.parse(data);
+ var etree = et.parse(data.data);
if (!_.isEmpty(data.error)){
payload.error = data.error.code + ": " + data.error.message;
return;
Oops, something went wrong.

0 comments on commit 951c08c

Please sign in to comment.