Skip to content

Commit

Permalink
Merge branch 'main' into feat/deploy-config
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper committed Jan 10, 2025
2 parents 42cda89 + c633f97 commit cbb787b
Show file tree
Hide file tree
Showing 27 changed files with 2,123 additions and 63 deletions.
231 changes: 231 additions & 0 deletions cypress/integration/insights.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
/*
* SPDX-License-Identifier: Apache-2.0
*/

const dayInSeconds = 24 * 60 * 60;

/**
* Creates a build object with the provided properties.
* @param {Object} props - The properties to include in the build object.
* @param {number} props.enqueued - The timestamp when the build was enqueued.
* @param {number} props.created - The timestamp when the build was created.
* @param {number} props.started - The timestamp when the build was started.
* @param {number} props.finished - The timestamp when the build was finished.
* @param {string} props.status - The status of the build, defaulting to "success".
* @param {number} [props.number=1] - The build number, defaulting to 1.
* @returns {Object} The created build object.
*/
function createBuild({
enqueued,
created,
started,
finished,
status = 'success',
number = 1,
}) {
return {
id: number,
repo_id: 1,
number: number,
parent: 1,
event: 'push',
status: status,
error: '',
enqueued: enqueued,
created: created,
started: started,
finished: finished,
deploy: '',
link: `/github/octocat/${number}`,
clone: 'https://github.com/github/octocat.git',
source:
'https://github.com/github/octocat/commit/9b1d8bded6e992ab660eaee527c5e3232d0a2441',
title: 'push received from https://github.com/github/octocat',
message: 'fixing docker params',
commit: '9b1d8bded6e992ab660eaee527c5e3232d0a2441',
sender: 'CookieCat',
author: 'CookieCat',
branch: 'infra',
ref: 'refs/heads/infra',
base_ref: '',
host: '',
runtime: 'docker',
distribution: 'linux',
};
}

/**
* Returns the current Unix timestamp with an optional offset in seconds.
* @param {number} [offsetSeconds=0] - The number of seconds to offset the timestamp by.
* @returns {number} The current Unix timestamp plus the optional offset.
*/
function getUnixTime(offsetSeconds = 0) {
return Math.floor(Date.now() / 1000) + offsetSeconds;
}

context('insights', () => {
context('no builds', () => {
beforeEach(() => {
cy.server();
cy.route({
method: 'GET',
url: '*api/v1/repos/*/*/builds*',
response: [],
});
cy.login('/github/octocat/insights');
});

it('should show no builds message', () => {
cy.get('[data-test=no-builds]').should('be.visible');
});
});

context('varying builds', () => {
beforeEach(() => {
let builds = [];

builds.push(
createBuild({
enqueued: getUnixTime(-3 * dayInSeconds),
created: getUnixTime(-3 * dayInSeconds),
started: getUnixTime(-3 * dayInSeconds),
finished: getUnixTime(-3 * dayInSeconds + 30 * 60),
status: 'success',
number: 1,
}),
);

builds.push(
createBuild({
enqueued: getUnixTime(-2 * dayInSeconds),
created: getUnixTime(-2 * dayInSeconds),
started: getUnixTime(-2 * dayInSeconds),
finished: getUnixTime(-2 * dayInSeconds + 30 * 60),
status: 'failure',
number: 2,
}),
);

builds.push(
createBuild({
enqueued: getUnixTime(-2 * dayInSeconds + 600),
created: getUnixTime(-2 * dayInSeconds + 600),
started: getUnixTime(-2 * dayInSeconds + 600),
finished: getUnixTime(-2 * dayInSeconds + 600 + 15 * 60),
status: 'success',
number: 3,
}),
);

builds.push(
createBuild({
enqueued: getUnixTime(-dayInSeconds),
created: getUnixTime(-dayInSeconds),
started: getUnixTime(-dayInSeconds),
finished: getUnixTime(-dayInSeconds + 45 * 60),
status: 'success',
number: 4,
}),
);

cy.server();
cy.route({
method: 'GET',
url: '*api/v1/repos/*/*/builds*',
response: builds,
});
cy.login('/github/octocat/insights');
});

it('daily average should be 2', () => {
cy.get(
'[data-test=metrics-quicklist-activity] > :nth-child(1) > .metric-value',
).should('have.text', '2');
});

it('average build time should be 30m 0s', () => {
cy.get(
'[data-test=metrics-quicklist-duration] > :nth-child(1) > .metric-value',
).should('have.text', '30m 0s');
});

it('reliability should be 75% success', () => {
cy.get(
'[data-test=metrics-quicklist-reliability] > :nth-child(1) > .metric-value',
).should('have.text', '75.0%');
});

it('time to recover should be 10 minutes', () => {
cy.get(
'[data-test=metrics-quicklist-reliability] > :nth-child(3) > .metric-value',
).should('have.text', '10m 0s');
});

it('average queue time should be 0 seconds', () => {
cy.get(
'[data-test=metrics-quicklist-queue] > :nth-child(1) > .metric-value',
).should('have.text', '0s');
});
});

context('one identical build a day', () => {
beforeEach(() => {
const epochTime = getUnixTime(-6 * dayInSeconds);

const builds = Array.from({ length: 7 }, (_, index) => {
const created = epochTime + index * dayInSeconds;
const enqueued = created + 10;
const started = enqueued + 10;
const finished = started + 30;

return createBuild({
enqueued,
created,
started,
finished,
number: index + 1,
});
});

cy.server();
cy.route({
method: 'GET',
url: '*api/v1/repos/*/*/builds*',
response: builds,
});
cy.login('/github/octocat/insights');
});

it('should show 4 metric quicklists', () => {
cy.get('[data-test^=metrics-quicklist-]').should('have.length', 4);
});

it('should show 4 charts', () => {
cy.get('[data-test=metrics-chart]').should('have.length', 4);
});

it('daily average should be 1', () => {
cy.get(
'[data-test=metrics-quicklist-activity] > :nth-child(1) > .metric-value',
).should('have.text', '1');
});

it('average build time should be 30 seconds', () => {
cy.get(
'[data-test=metrics-quicklist-duration] > :nth-child(1) > .metric-value',
).should('have.text', '30s');
});

it('reliability should be 100% success', () => {
cy.get(
'[data-test=metrics-quicklist-reliability] > :nth-child(1) > .metric-value',
).should('have.text', '100.0%');
});

it('average queue time should be 10 seconds', () => {
cy.get(
'[data-test=metrics-quicklist-queue] > :nth-child(1) > .metric-value',
).should('have.text', '10s');
});
});
});
19 changes: 19 additions & 0 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
"elm/url": "1.0.0",
"elm-community/graph": "6.0.0",
"elm-community/json-extra": "4.3.0",
"elm-community/typed-svg": "7.0.0",
"elmcraft/core-extra": "2.0.0",
"feathericons/elm-feather": "1.5.0",
"gampleman/elm-visualization": "2.4.2",
"jackfranklin/elm-parse-link-header": "2.0.2",
"jzxhuang/http-extras": "2.1.0",
"krisajenkins/remotedata": "6.0.1",
Expand All @@ -29,13 +31,30 @@
"vito/elm-ansi": "9.0.2"
},
"indirect": {
"avh4/elm-color": "1.0.0",
"avh4/elm-fifo": "1.0.4",
"elm/parser": "1.1.0",
"elm/random": "1.0.0",
"elm/regex": "1.0.0",
"elm/virtual-dom": "1.0.3",
"elm-community/intdict": "3.1.0",
"elm-community/list-extra": "8.7.0",
"folkertdev/elm-deque": "3.0.1",
"folkertdev/one-true-path-experiment": "6.0.1",
"folkertdev/svg-path-lowlevel": "4.0.1",
"gampleman/elm-rosetree": "1.1.0",
"ianmackenzie/elm-1d-parameter": "1.0.1",
"ianmackenzie/elm-float-extra": "1.1.0",
"ianmackenzie/elm-geometry": "3.11.0",
"ianmackenzie/elm-interval": "3.1.0",
"ianmackenzie/elm-triangular-mesh": "1.1.0",
"ianmackenzie/elm-units": "2.10.0",
"ianmackenzie/elm-units-interval": "3.2.0",
"ianmackenzie/elm-units-prefixed": "2.8.0",
"justinmimbs/date": "4.1.0",
"justinmimbs/time-extra": "1.2.0",
"myrho/elm-round": "1.0.5",
"rtfeldman/elm-hex": "1.0.0",
"rtfeldman/elm-iso8601-date-strings": "1.1.4"
}
},
Expand Down
6 changes: 3 additions & 3 deletions src/elm/Api/Endpoint.elm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Endpoint
| Hooks (Maybe Pagination.Page) (Maybe Pagination.PerPage) Vela.Org Vela.Repo
| Hook Vela.Org Vela.Repo Vela.HookNumber
| OrgBuilds (Maybe Pagination.Page) (Maybe Pagination.PerPage) (Maybe Vela.Event) Vela.Org
| Builds (Maybe Pagination.Page) (Maybe Pagination.PerPage) (Maybe Vela.Event) Vela.Org Vela.Repo
| Builds (Maybe Pagination.Page) (Maybe Pagination.PerPage) (Maybe Vela.Event) (Maybe Int) Vela.Org Vela.Repo
| Build Vela.Org Vela.Repo Vela.BuildNumber
| CancelBuild Vela.Org Vela.Repo Vela.BuildNumber
| ApproveBuild Vela.Org Vela.Repo Vela.BuildNumber
Expand Down Expand Up @@ -107,8 +107,8 @@ toUrl api endpoint =
OrgBuilds maybePage maybePerPage maybeEvent org ->
url api [ "repos", org, "builds" ] <| Pagination.toQueryParams maybePage maybePerPage ++ [ UB.string "event" <| Maybe.withDefault "" maybeEvent ]

Builds maybePage maybePerPage maybeEvent org repo ->
url api [ "repos", org, repo, "builds" ] <| Pagination.toQueryParams maybePage maybePerPage ++ [ UB.string "event" <| Maybe.withDefault "" maybeEvent ]
Builds maybePage maybePerPage maybeEvent maybeAfter org repo ->
url api [ "repos", org, repo, "builds" ] <| Pagination.toQueryParams maybePage maybePerPage ++ [ UB.string "event" <| Maybe.withDefault "" maybeEvent, UB.int "after" <| Maybe.withDefault 0 maybeAfter ]

Build org repo build ->
url api [ "repos", org, repo, "builds", build ] []
Expand Down
29 changes: 29 additions & 0 deletions src/elm/Api/Operations.elm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module Api.Operations exposing
, finishAuthentication
, getAllBuildServices
, getAllBuildSteps
, getAllBuilds
, getBuild
, getBuildGraph
, getBuildServiceLog
Expand Down Expand Up @@ -280,6 +281,7 @@ getRepoBuilds :
, pageNumber : Maybe Int
, perPage : Maybe Int
, maybeEvent : Maybe String
, maybeAfter : Maybe Int
}
-> Request (List Vela.Build)
getRepoBuilds baseUrl session options =
Expand All @@ -288,6 +290,7 @@ getRepoBuilds baseUrl session options =
options.pageNumber
options.perPage
options.maybeEvent
options.maybeAfter
options.org
options.repo
)
Expand Down Expand Up @@ -707,6 +710,32 @@ getBuildSteps baseUrl session options =
|> withAuth session


{-| getAllBuilds : retrieves all builds.
-}
getAllBuilds :
String
-> Session
->
{ a
| org : String
, repo : String
, after : Int
}
-> Request Vela.Build
getAllBuilds baseUrl session options =
get baseUrl
(Api.Endpoint.Builds
(Just 1)
(Just 100)
Nothing
(Just options.after)
options.org
options.repo
)
Vela.decodeBuild
|> withAuth session


{-| getAllBuildSteps : retrieves all steps for a build.
-}
getAllBuildSteps :
Expand Down
Loading

0 comments on commit cbb787b

Please sign in to comment.