Shields: [Github] Traffic Badges - Views, Clones, Paths, referrers

Created on 8 Feb 2020  路  8Comments  路  Source: badges/shields

:clipboard: Description

It will be great if we can have Traffic Badge that will show us Total Number of Clones/Views that a Github repository gets. As of now only the owner of repository has access to this data in the Repository>Insight>Traffic

:link: Data

service-badge

Most helpful comment

Thanks for the help, I finally did it :)

All 8 comments

Total no of Repository Clones/ Views are often hidden from non owner

The same is true via the API:

$ curl "https://api.github.com/repos/badges/shields/traffic/clones"
{
  "message": "Must have push access to repository",
  "documentation_url": "https://developer.github.com/v3/repos/traffic/#clones"
}

We could not offer this badge on shields.io because the user would have to expose a token allowing an attacker write access to their repo.

I guess it could possibly be a feature for self-hosting users only.

I tried to host this php file in my server and then used it to get the data and then query it in shields.io Dynamic

<?php
$url = 'https://api.github.com/repos/USERNAME/REPOSITORY/traffic/clones';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_USERPWD, 'USERNAME' . ':' . 'PASSWORD');
$headers = array();
$headers[] = 'Content-Type: application/json; charset=utf-8';
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
echo($response);
?>

I am not good in php but my past experience shows that sometimes the whole php code gets visible in the browser.
Is there some alternatives ?

@alx-xlx - due to the user-specific authorization requirements @chris48s detailed above, this is not something that can be added natively to the Shields.io service. The only path I could see that would allow you to get these types of badges would be via Shields.io endpoint badge.

You would need to develop a little api/endpoint that was capable of retrieving the data from your repositories, and you'd then be able to use the Shields endpoint badge with your new api endpoint.

The only path I could see that would allow you to get these types of badges would be via Shields.io endpoint badge.

Good call. I should have thought to suggest that :+1:

Thanks for the help, I finally did it :)

Glad to hear it @alx-xlx! I'm going to close this out accordingly, though feel free to ping us again here and/or on Discord if you have any other questions

i was wondering if something like this [https://hits.dwyl.com] could be possible in here,
at least for views

Hmm, what is that and how does it work?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

najeeb-ur-rehman picture najeeb-ur-rehman  路  3Comments

chadwhitacre picture chadwhitacre  路  4Comments

rominf picture rominf  路  3Comments

korenyoni picture korenyoni  路  3Comments

irgolic picture irgolic  路  3Comments