Page MenuHomeSoftware Heritage

Add new endpoints to generate swh badges
ClosedPublic

Authored by anlambert on Nov 19 2019, 3:56 PM.

Details

Summary

Add endpoints /badge/(object_type)/(object_id)/ and /badge/(object_pid)/
to generate Github style like SVG badges for linking to the archive in
a README file.

Those new endpoints add CORS header to the HTTP responses in order to be
used from a different domain than *.softwareheritage.org ones.

Below is a preview of the generated badges according to swh object type:

  • origin:
  • content:
  • directory:
  • release:
  • revision:
  • snapshot:

Colors and texts might still be improved.

Related to T2090

Test Plan

Tests checking the badges are well-formed but also checking HTTP status codes
when an error occurs have been added.

Diff Detail

Repository
rDWAPPS Web applications
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

anlambert created this revision.Nov 19 2019, 3:56 PM
anlambert edited the summary of this revision. (Show Details)Nov 19 2019, 4:02 PM

Thanks for the images at the beginning of the diff, the badges are very cool !
I pinged @marla.dasilva to see the result and we might want to change the colors to more positive colors.
We are planning to meet about that on Friday, maybe we can even show it to @rdicosmo :-)

anlambert updated this revision to Diff 8011.Nov 21 2019, 2:07 PM

Update: Generate an error badge when something went wrong

I think the "origin" badge should show the URL instead; so in forks it shows that it's the initial repository that is archive, while the fork may not be. It's also better for consistency.

vlorentz requested changes to this revision.Nov 21 2019, 2:38 PM

Shouldn't the badges be part of the API? Or at least be versioned.

swh/web/misc/badges.py
63–66

Nitpick: it's not a base64-encoded SVG, it's a data-URI containing the SWH logo

169–170

"Errors should never pass silently."

This revision now requires changes to proceed.Nov 21 2019, 2:38 PM
anlambert added inline comments.Nov 21 2019, 2:44 PM
swh/web/misc/badges.py
63–66

Ack

169–170

Ack, will move the pid parsing in the first endpoint implementation then.

anlambert updated this revision to Diff 8016.Nov 21 2019, 3:20 PM

Update: Address @vlorentz comments and add tests for pid badge errors

anlambert updated this revision to Diff 8019.Nov 21 2019, 3:47 PM

Update: slight changes in test for generating a new commit id for fixing D2320 CI builds (arc patch fails, I messed up somewhere)

@vlorentz I'm not convinced about having the url in the text of the badge.
I understand that a fork can use the "wrong" badge, by using the main repository's badge.
But the sha1 is already very long for a badge and this is really kind of a gimmick link :-)

anlambert edited the summary of this revision. (Show Details)Nov 22 2019, 4:43 PM
anlambert updated this revision to Diff 8346.Nov 28 2019, 10:52 AM

Update: Rebase and use a white version of the swh logo in the bages

I think you missed this comment:

Shouldn't the badges be part of the API? Or at least be versioned.

Shouldn't the badges be part of the API? Or at least be versioned.

I don't think so, having a separate endpoint dedicated to the badge generation seems appropriate here.
API endpoints return JSON responses while the badge endpoints return SVG ones.

Also I don't see the interest having versioned badges.

vlorentz accepted this revision.Nov 28 2019, 2:22 PM
This revision is now accepted and ready to land.Nov 28 2019, 2:22 PM
This revision was automatically updated to reflect the committed changes.