From 235b7df5db4d0881f7bd313f9c396e2aac31b5b3 Mon Sep 17 00:00:00 2001 From: Eric Horacek Date: Wed, 6 May 2015 23:31:33 -0700 Subject: [PATCH 1/3] Add CocoaPods documentation percent --- server.js | 26 ++++++++++++++++++++++++++ try.html | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/server.js b/server.js index bacef08362aa0..ccd4e41d1b41e 100644 --- a/server.js +++ b/server.js @@ -2028,6 +2028,32 @@ cache(function(data, match, sendBadge, request) { }); })); +camp.route(/^\/cocoapods\/metrics\/doc-percent\/(.*)\.(svg|png|gif|jpg|json)$/, +cache(function(data, match, sendBadge, request) { + var spec = match[1]; // eg, AFNetworking + var format = match[2]; + var apiUrl = 'http://metrics.cocoapods.org/api/v1/pods/' + spec; + var badgeData = getBadgeData('pod', data); + badgeData.colorscheme = null; + request(apiUrl, function(err, res, buffer) { + if (err != null) { + badgeData.text[1] = 'inaccessible'; + sendBadge(format, badgeData); + } + try { + var data = JSON.parse(buffer); + var percentage = data.cocoadocs.doc_percent; + badgeData.colorscheme = coveragePercentageColor(percentage); + badgeData.text[0] = 'docs'; + badgeData.text[1] = percentage + '%' + sendBadge(format, badgeData); + } catch(e) { + badgeData.text[1] = 'invalid'; + sendBadge(format, badgeData); + } + }); +})); + // GitHub tag integration. camp.route(/^\/github\/tag\/([^\/]+)\/([^\/]+)\.(svg|png|gif|jpg|json)$/, cache(function(data, match, sendBadge, request) { diff --git a/try.html b/try.html index 13c2df621eed2..d206ce820328e 100644 --- a/try.html +++ b/try.html @@ -518,6 +518,10 @@

Miscellaneous

https://img.shields.io/cocoapods/p/AFNetworking.svg + CocoaPods: + + https://img.shields.io/cocoapods/metrics/doc-percent/AFNetworking.svg + Wheelmap: https://img.shields.io/wheelmap/a/2323004600.svg From dffbc3ab1ef7fceaf299b9db9d89aeff30301752 Mon Sep 17 00:00:00 2001 From: Eric Horacek Date: Mon, 11 May 2015 13:00:15 -0700 Subject: [PATCH 2/3] Remove unnecessary line --- server.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server.js b/server.js index ccd4e41d1b41e..571627fa12ee3 100644 --- a/server.js +++ b/server.js @@ -2034,7 +2034,6 @@ cache(function(data, match, sendBadge, request) { var format = match[2]; var apiUrl = 'http://metrics.cocoapods.org/api/v1/pods/' + spec; var badgeData = getBadgeData('pod', data); - badgeData.colorscheme = null; request(apiUrl, function(err, res, buffer) { if (err != null) { badgeData.text[1] = 'inaccessible'; From a996e9c1be77ad723517c965cc4372c1b9fb6b1b Mon Sep 17 00:00:00 2001 From: Eric Horacek Date: Mon, 11 May 2015 13:00:26 -0700 Subject: [PATCH 3/3] Add early return on error --- server.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server.js b/server.js index 571627fa12ee3..a7b925bbe9473 100644 --- a/server.js +++ b/server.js @@ -2038,6 +2038,7 @@ cache(function(data, match, sendBadge, request) { if (err != null) { badgeData.text[1] = 'inaccessible'; sendBadge(format, badgeData); + return; } try { var data = JSON.parse(buffer);