[ https://issues.apache.org/jira/browse/CB-8870?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14519979#comment-14519979 ]
ASF GitHub Bot commented on CB-8870: ------------------------------------ Github user muratsu commented on a diff in the pull request: https://github.com/apache/cordova-medic/pull/47#discussion_r29369904 --- Diff: bin/lib/couchdb.js --- @@ -0,0 +1,151 @@ + +/* +Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved. + +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 request = require('request'); +var follow = require('follow'); + +var DEFAULT_COUCHDB_URI = "http://localhost"; + +var couchdbURI = DEFAULT_COUCHDB_URI; + +function init(uri) { + couchdbURI = uri; +} + +// Generic interface + convenience functions for working with couch dbs +function db(name) { + this.name = name; + this.db_url = couchdbURI + '/' + this.name; + this.is_following = false; +} + +db.prototype = { + get:function(id, callback) { + // Gets a specific document by id + + var db = this; + var url = this.db_url + '/' + id; + request.get(url, function(error, response, body) { + if (error) { + callback(error); + } else { + if (response.statusCode == 200) { + callback(false, JSON.parse(body)); + } else if (response.statusCode == 404) { + callback(true, 404); + } else { + callback(true, response.statusCode); + } + } + }); + }, + query_view:function(design, view, callback) { + // Queries a view. + + var db = this; + var url = this.db_url + '/_design/' + design + '/_view/' + view; + request.get(url, function(error, response, body) { + if (error) { + callback(error); + } else { + if (response.statusCode == 200) { + callback(false, JSON.parse(body)); + } else if (response.statusCode == 404) { + callback(true, 404); + } else { + callback(true, response.statusCode); + } + } + }); + }, + clobber:function(id, document, callback) { + // Overwrites a document + var db = this; + var url = this.db_url + '/' + id; + + request.put({ + url:url, + json:document + }, function(error, response, body) { + if (error || response.statusCode === 404) { + console.error('Request failed: ' + url); + callback(true, JSON.stringify(body)); + return; + } + + var status = response.statusCode; + if (status == 201) callback(false, body); + else if (status == 409) { + request.get(url, function(err, resp, bod) { + if (err) callback(err); + else { + if (resp.statusCode == 200) { + var existing = JSON.parse(bod); + var rev = existing._rev; + request.del({ + url:url + '?rev=' + rev, + }, function(er, res, boday) { + if (er) callback(er); + else { + if (res.statusCode == 200) { + request.put({ + url:url, + json:document + }, function(argh, r, bodee) { + if (argh) callback(argh); + else { + if(r){ + if (r.statusCode == 201) callback(false, bodee); + else callback(true, r.statusCode); + } else { + callback(true,"URL failed?"); + } + } + }); + } else callback(true, res.statusCode); + } + }); + } else callback(true, resp.statusCode); + } + }); + } else callback(true, response.statusCode); + + }); + }, + follow:function(callback) { + if (!this.is_following) { + this.is_following = true; + follow({ + db:this.db_url, + since:'now', + include_docs:true + }, function(err, change) { + if (!err) callback(false, change); + else callback(err); + }); + return true; + } else return false; + } +}; + +module.exports = { + init: init, + db: db, +}; + +// build_errors:new db('build_errors'), +// mobilespec_results:new db('mobilespec_results'), +// test_details:new db('test_details') --- End diff -- Unncecessary comments? > Medic should display test failures in build status > -------------------------------------------------- > > Key: CB-8870 > URL: https://issues.apache.org/jira/browse/CB-8870 > Project: Apache Cordova > Issue Type: Improvement > Components: Medic > Affects Versions: Master > Reporter: Dmitry Blotsky > Labels: improvement, medic > Original Estimate: 72h > Remaining Estimate: 72h > -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For additional commands, e-mail: issues-h...@cordova.apache.org