Add endpoint to generate a shields.io badge

[?]
Dec 24, 2020, 2:44 PM
2E23VP5JOIJSVVVFIER2WEWFKBHKJ3F2O6NKPGMCTMPZ2XQ6XN7QC

Dependencies

  • [2] LX326CB7 Add hydra OpenAPI description (#750)
  • [3] NZXX6PLD Remove the Jobs table
  • [*] DEMSSSB2 * Controller for jobs which inherits all actions in ListBuilds. So
  • [*] ODNCGFQ5 * Improved the navigation bar: don't include all projects (since that
  • [*] NQJFHYBI job: create a prometheus endpoint

Change contents

  • edit in hydra-api.yaml at line 387
    [2.12022]
    [2.12022]
    /job/{project-id}/{jobset-id}/{job-id}/shield:
    get:
    summary: Generate data for a shields.io badge
    parameters:
    - name: project-id
    in: path
    description: project identifier
    required: true
    schema:
    type: string
    - name: jobset-id
    in: path
    description: jobset identifier
    required: true
    schema:
    type: string
    - name: job-id
    in: path
    description: job identifier
    required: true
    schema:
    type: string
    responses:
    '200':
    description: see <a href="https://shields.io/endpoint">https://shields.io/endpoint</a> on how to use this
    content:
    application/json:
    examples:
    shield-success:
    value:
    color: green
    schemaVersion: 1
    label: hydra build
    message: passing
  • edit in src/lib/Hydra/Controller/Job.pm at line 29
    [3.129]
    [5.427]
    }
    sub shield :Chained('job') PathPart('shield') Args(0) {
    my ($self, $c) = @_;
    my $job = $c->stash->{job};
    my $lastBuild = $c->stash->{jobset}->builds->find(
    { job => $job, finished => 1 },
    { order_by => 'id DESC', rows => 1, columns => [@buildListColumns] }
    );
    notFound($c, "No latest build for job ‘$job’.") unless defined $lastBuild;
    my $color =
    $lastBuild->buildstatus == 0 ? "green" :
    $lastBuild->buildstatus == 4 ? "yellow" :
    "red";
    my $message =
    $lastBuild->buildstatus == 0 ? "passing" :
    $lastBuild->buildstatus == 4 ? "cancelled" :
    "failing";
    $c->response->content_type('application/json');
    $c->stash->{'plain'} = {
    data => scalar (JSON::Any->objToJson(
    {
    schemaVersion => 1,
    label => "hydra build",
    color => $color,
    message => $message,
    }))
    };
    $c->forward('Hydra::View::Plain');
  • edit in src/lib/Hydra/Controller/Job.pm at line 64
    [6.1]
    [7.22]