Permalink
Browse files

Now abstracting v1 and some github request options

  • Loading branch information...
1 parent eb232ac commit 355eaeb37c6d107d21e43ec8fd428d4032c33b4c @kans kans committed Jun 6, 2012
View
@@ -132,7 +132,7 @@ exports.request_maker = function(options, call_back) {
_.extend(options.headers, headers);
method = options.port === 80 ? http : https;
- log.debug(options);
+ log.debug(options.method, options.host, options.path);
req = method.request(options, function(res) {
var data = '';
@@ -170,21 +170,30 @@ exports.request_maker = function(options, call_back) {
* @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;
+exports.github_options = function(api_config, path, uri) {
+ var host;
+ var parsed_uri;
+ if (uri !== undefined){
+ parsed_uri = url.parse(uri);
+ path = parsed_uri.path;
+ host = parsed_uri.host;
+ } else{
+ if (path instanceof Array){
+ path = path.join('');
+ }
+ path = util.format("/repos/%s/%s%s", api_config.org, api_config.repo, path);
+ host = url.parse(api_config.url).host;
+ }
+
+ if (!host || !path){
+ throw new Error('Not enough info to build a github request!');
+ }
return {
return_response: true,
- host: parsed.host,
+ host: host,
port: 443,
- path: _path,
+ path: path,
method: 'GET',
headers: {
'Content-Type': 'application/json',
View
@@ -126,7 +126,7 @@ exports.options = function(v1_config, path){
if (path instanceof Array){
path = path.join('');
}
- path = util.format('/%s/rest-1.v1/%s',v1_config.name, path);
+ path = util.format('/%s/rest-1.v1%s',v1_config.name, path);
return {
port: v1_config.port,
host: v1_config.host,
View
@@ -4,6 +4,42 @@ var utils = require('../../utils').common;
var async = require('async');
var url = require('url');
+
+/**
+ *
+ * @param devops_github
+ * @param is_closed
+ * @returns
+ */
+var make_github_options = function(devops_github, is_closed) {
+ var parsed_url = url.parse(devops_github.url);
+ var path = [
+ "/repos/",
+ devops_github.org,
+ "/",
+ devops_github.repo,
+ '/pulls'
+ ];
+
+ if (is_closed) {
+ path.push("?state=closed");
+ }else{
+ path.push('?state=open');
+ }
+ path.push('&per_page=150&page=1');
+
+ return {
+ host: parsed_url.host,
+ port: 443,
+ path: path.join(''),
+ method: 'GET',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': utils.create_basic_auth(devops_github.username,
+ devops_github.apikey)
+ }
+ };
+};
/** Adds github field to devops if github related api is present
* @param {object} devops devops object
*/
@@ -88,42 +124,6 @@ var parse_github_response = function(data){
return formatted_metrics;
};
-/**
- *
- * @param devops_github
- * @param is_closed
- * @returns
- */
-var make_github_options = function(devops_github, is_closed) {
- var parsed_url = url.parse(devops_github.url);
- var path = [
- "/repos/",
- devops_github.org,
- "/",
- devops_github.repo,
- '/pulls'
- ];
-
- if (is_closed) {
- path.push("?state=closed");
- }else{
- path.push('?state=open');
- }
- path.push('&per_page=150&page=1');
-
- return {
- host: parsed_url.host,
- port: 443,
- path: path.join(''),
- method: 'GET',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': utils.create_basic_auth(devops_github.username,
- devops_github.apikey)
- }
- };
-};
-
/**
* Pulls out metric information for a set of Github pull request objects.
* @todo The "user" part of the name "user_stats" is an assumption not a requirement.
@@ -71,7 +71,7 @@ var Poller = utils.make_class({
var options, path;
var scopes = v1.scope_maker(self.api_config.project);
- path = ["Data/Defect?sel=",
+ path = ["/Data/Defect?sel=",
SELECTION,
"&where=AssetState='64','128';Scope=",
scopes];
@@ -56,7 +56,7 @@ module.exports = function(payload) {
var api_config = payload.get_config();
var scope = v1.scope_maker(api_config.project);
var path = [
- "Data/Defect?sel=",
+ "/Data/Defect?sel=",
selection,
"&where=AssetState='0','64';Scope=",
scope];
@@ -45,6 +45,7 @@ module.exports = utils.make_class({
self._end = end;
self.cb = undefined;
self.v1_config = v1_config;
+ self.github_config = github_config;
self.github_commit_task = undefined;
self.date_of_last_merge_before_deploy = undefined;
// this is really the time of the commit for the last pr merged into master that was deployed-
@@ -60,8 +61,6 @@ module.exports = utils.make_class({
self.v1_support = v1_config ? true : false;
- self._github_options = _.bind(utils.github_request_options, self, github_config);
-
self.v1_response_handler = _.bind(self.__v1_response_handler, self);
self.github_response_handler = _.bind(self.__github_response_handler, self);
@@ -133,7 +132,7 @@ module.exports = utils.make_class({
_get_history_options: function(start, end, type){
var self = this;
var path = [
- "Hist/",
+ "/Hist/",
type,
util.format("?where=Scope=%s;ChangeDate>'%s';ChangeDate<'%s'&sel=%s&s",
v1.scope_maker(self.v1_config.project), start.toISOString(), end.toISOString(), notes.SELECTION)
@@ -144,6 +143,7 @@ module.exports = utils.make_class({
var self = this;
var options, path, identifier;
path = [
+ '/',
v1_story_info.long_name,
util.format("?where=Number='%s'&sel=%s", v1_story_info.number, notes.SELECTION)
];
@@ -201,6 +201,7 @@ module.exports = utils.make_class({
},
_die: function(err){
var self = this;
+ log.error(arguments);
self.cb(err);
delete self._q;
},
@@ -219,18 +220,8 @@ module.exports = utils.make_class({
self.last_merged_sha = sha;
return {
- options: {
- return_response: true,
- host: url.parse(github_config.url).host,
- port: 443,
- path: util.format('/repos/%s/%s/commits/%s', github_config.org, github_config.repo, sha),
- method: 'GET',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': utils.create_basic_auth(github_config.username,
- github_config.apikey)
- }
- },
+ options: utils.github_options(self.github_config,
+ util.format('/commits/%s', sha)),
cb: _.bind(self.github_sha_getter_cb, self)
};
},
@@ -256,12 +247,15 @@ module.exports = utils.make_class({
log.log(self.last_pr_commit_to_live_time);
self.pr_id = data.id;
}catch(e){
- return self._die('Github says: ' + e);
+ return self._die(e, 'Github says');
}
},
_q_github_request: function(uri){
var self = this;
- var options = self._github_options(uri);
+ var options;
+ var path;
+ options = utils.github_options(self.github_config, '/pulls?state=closed&per_page=100&page=1', uri);
+ console.log(options);
self._push_to_q({options: options, cb: self.github_response_handler});
},
_q_v1_request: function(note){

0 comments on commit 355eaeb

Please sign in to comment.