From ea4208f482efd7445f0e4a44b4caab5abb8d7e69 Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Wed, 20 May 2015 13:12:08 +0100 Subject: [PATCH 1/6] Support private repository tokens for codecov --- server.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index da64916..3d68953 100644 --- a/server.js +++ b/server.js @@ -1540,13 +1540,24 @@ cache(function(data, match, sendBadge, request) { var userRepo = match[1]; // eg, `github/codecov/example-python`. var branch = match[2]; var format = match[3]; + var token = data['token']; // for private repositories (?token=1234) var apiUrl = { url: 'https://codecov.io/' + userRepo + '/coverage.svg', followRedirect: false, method: 'HEAD', }; + // Query Params + queryParams = []; if (branch) { - apiUrl.url += '?branch=' + branch; + queryParams.push({name: 'branch', value: branch}) + } + if (token) { + queryParams.push({name: 'token', value: token}) + } + for (i = 0; i < queryParams.length; i++) { + var param = queryParams[i]; + var sep = (i == 0 ? '?' : '&'); + apiUrl.url += sep + param.name + '=' + param.value; } var badgeData = getBadgeData('coverage', data); request(apiUrl, function(err, res) { From cbd12a758019c831002ce80df6a783d0ae020ef6 Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Wed, 20 May 2015 13:20:44 +0100 Subject: [PATCH 2/6] Added codecov branch and private usage to try.html --- try.html | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/try.html b/try.html index 72af700..9802475 100644 --- a/try.html +++ b/try.html @@ -160,6 +160,14 @@ Pixel-perfect   Retina-ready   Fast   Consistent   Hackable https://img.shields.io/codecov/c/github/codecov/example-python.svg + Codecov branch: + + https://img.shields.io/codecov/c/github/codecov/example-python/master.svg + + Codecov private: + + https://img.shields.io/codecov/c/github/codecov/example-python.svg?token=foo + Coverity Scan: https://img.shields.io/coverity/scan/3997.svg From e383f0e72517446d01ab6b276c484c2798a317d3 Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Thu, 21 May 2015 15:46:42 +0100 Subject: [PATCH 3/6] Implemtned new regex to support tokens in the request url path rather than a new query string --- server.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server.js b/server.js index 3d68953..3fb91f9 100644 --- a/server.js +++ b/server.js @@ -1535,12 +1535,12 @@ cache(function(data, match, sendBadge, request) { })); // Codecov integration. -camp.route(/^\/codecov\/c\/([^\/]+\/[^\/]+\/[^\/]+)(?:\/(.+))?\.(svg|png|gif|jpg|json)$/, +camp.route(/^\/codecov\/c\/(?:t:([A-Za-z1-9]+))?[+\/]?([^\/]+\/[^\/]+\/[^\/]+)(?:\/(.+))?\.(svg|png|gif|jpg|json)$/, cache(function(data, match, sendBadge, request) { - var userRepo = match[1]; // eg, `github/codecov/example-python`. - var branch = match[2]; - var format = match[3]; - var token = data['token']; // for private repositories (?token=1234) + var token = match[1]; + var userRepo = match[2]; // eg, `github/codecov/example-python`. + var branch = match[3]; + var format = match[4]; var apiUrl = { url: 'https://codecov.io/' + userRepo + '/coverage.svg', followRedirect: false, From 193498aed8c7eb68443a515154b2e82fee2d3cec Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Thu, 21 May 2015 15:47:10 +0100 Subject: [PATCH 4/6] Use querystring to build the codecov query string --- server.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/server.js b/server.js index 3fb91f9..ea3ac94 100644 --- a/server.js +++ b/server.js @@ -12,6 +12,7 @@ var fs = require('fs'); var LruCache = require('./lru-cache.js'); var badge = require('./badge.js'); var svg2img = require('./svg-to-img.js'); +var querystring = require('querystring'); var serverSecrets; try { // Everything that cannot be checked in but is useful server-side @@ -1547,18 +1548,14 @@ cache(function(data, match, sendBadge, request) { method: 'HEAD', }; // Query Params - queryParams = []; + queryParams = {}; if (branch) { - queryParams.push({name: 'branch', value: branch}) + queryParams.branch = branch; } if (token) { - queryParams.push({name: 'token', value: token}) - } - for (i = 0; i < queryParams.length; i++) { - var param = queryParams[i]; - var sep = (i == 0 ? '?' : '&'); - apiUrl.url += sep + param.name + '=' + param.value; + queryParams.token = token; } + apiUrl.url += '?' + querystring.stringify(queryParams); var badgeData = getBadgeData('coverage', data); request(apiUrl, function(err, res) { if (err != null) { From 1c98ba8c1650dc0c04c62d849b09febe12b06b0f Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Thu, 21 May 2015 15:52:26 +0100 Subject: [PATCH 5/6] Updated try.html documentation --- try.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/try.html b/try.html index 9802475..cd62df5 100644 --- a/try.html +++ b/try.html @@ -166,7 +166,7 @@ Pixel-perfect   Retina-ready   Fast   Consistent   Hackable Codecov private: - https://img.shields.io/codecov/c/github/codecov/example-python.svg?token=foo + https://img.shields.io/codecov/c/t:YOURTOKEN/github/codecov/example-python.svg Coverity Scan: From 2f5a53e1deee752b2b48bbfc8712e3e3c8a7c460 Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Fri, 22 May 2015 09:33:14 +0100 Subject: [PATCH 6/6] Updated codecov regex to support /token/TOKEN/ rather than /t:TOKEN/ --- server.js | 2 +- try.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index ea3ac94..78315a6 100644 --- a/server.js +++ b/server.js @@ -1536,7 +1536,7 @@ cache(function(data, match, sendBadge, request) { })); // Codecov integration. -camp.route(/^\/codecov\/c\/(?:t:([A-Za-z1-9]+))?[+\/]?([^\/]+\/[^\/]+\/[^\/]+)(?:\/(.+))?\.(svg|png|gif|jpg|json)$/, +camp.route(/^\/codecov\/c\/(?:token\/(\w+))?[+\/]?([^\/]+\/[^\/]+\/[^\/]+)(?:\/(.+))?\.(svg|png|gif|jpg|json)$/, cache(function(data, match, sendBadge, request) { var token = match[1]; var userRepo = match[2]; // eg, `github/codecov/example-python`. diff --git a/try.html b/try.html index cd62df5..23980ff 100644 --- a/try.html +++ b/try.html @@ -166,7 +166,7 @@ Pixel-perfect   Retina-ready   Fast   Consistent   Hackable Codecov private: - https://img.shields.io/codecov/c/t:YOURTOKEN/github/codecov/example-python.svg + https://img.shields.io/codecov/c/token/YOURTOKEN/github/codecov/example-python.svg Coverity Scan: