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
Branch
swh-badge-endpoints
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 9273
Build 13558: Cypress tests for swh-web diffsJenkins
Build 13557: tox-on-jenkinsJenkins
Build 13556: arc lint + arc unit

Event Timeline

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 :-)

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.

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

swh/web/misc/badges.py
62–65

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

168–169

"Errors should never pass silently."

This revision now requires changes to proceed.Nov 21 2019, 2:38 PM
swh/web/misc/badges.py
62–65

Ack

168–169

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

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

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 :-)

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.

This revision is now accepted and ready to land.Nov 28 2019, 2:22 PM