Skip to content

Commit

Permalink
fix: add missing approved by info and link PR commit (#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
wass3r authored Feb 22, 2024
1 parent 8ddb96f commit d42df76
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 32 deletions.
29 changes: 29 additions & 0 deletions cypress/fixtures/build_approved.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"id": 15,
"repo_id": 1,
"number": 9,
"parent": 1,
"event": "pull_request",
"status": "success",
"error": "",
"enqueued": 1572980376,
"created": 1572980376,
"started": 1572980375,
"finished": 1572980375,
"deploy": "",
"clone": "https://github.com/github/octocat.git",
"source": "https://github.com/github/octocat/pull/42",
"title": "pull_request received from https://github.com/github/octocat",
"message": "fixing docker params",
"commit": "9b1d8bded6e992ab660eaee527c5e3232d0a2441",
"sender": "CookieCat",
"author": "CookieCat",
"branch": "main",
"ref": "refs/pull/42/head",
"base_ref": "main",
"host": "",
"runtime": "docker",
"distribution": "linux",
"approved_by": "gh0st",
"approved_at": 1572980375
}
14 changes: 8 additions & 6 deletions cypress/fixtures/build_pending_approval.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
"finished": 1572980375,
"deploy": "",
"clone": "https://github.com/github/octocat.git",
"source": "https://github.com/github/octocat/commit/9b1d8bded6e992ab660eaee527c5e3232d0a2441",
"title": "push received from https://github.com/github/octocat",
"source": "https://github.com/github/octocat/pull/42",
"title": "pull_request 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": "",
"branch": "main",
"ref": "refs/pull/42/head",
"base_ref": "main",
"host": "",
"runtime": "docker",
"distribution": "linux"
"distribution": "linux",
"approved_by": "",
"approved_at": 0
}
24 changes: 12 additions & 12 deletions cypress/fixtures/builds_all.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"repo_id": 1,
"number": 2,
"parent": 1,
"event": "pull",
"event": "pull_request",
"status": "success",
"error": "unable to retrieve repo secret docker_username: unable to get secret repo/vela/ui/docker_username from native service: record not found",
"enqueued": 1572980376,
Expand All @@ -42,15 +42,15 @@
"deploy": "",
"link": "/github/octocat/2",
"clone": "https://github.com/github/octocat.git",
"source": "https://github.com/github/octocat/commit/7bd468e69a42e92153525288800692186bb0120b",
"title": "push received from https://github.com/github/octocat",
"source": "https://github.com/github/octocat/pull/42",
"title": "pull_request received from https://github.com/github/octocat",
"message": "fixing docker params",
"commit": "7bd468e69a42e92153525288800692186bb0120b",
"sender": "CookieCat",
"author": "CookieCat",
"branch": "infra",
"ref": "refs/heads/infra",
"base_ref": "",
"branch": "main",
"ref": "refs/pull/42/head",
"base_ref": "main",
"host": "",
"runtime": "docker",
"distribution": "linux"
Expand All @@ -60,7 +60,7 @@
"repo_id": 1,
"number": 3,
"parent": 1,
"event": "pull",
"event": "pull_request",
"status": "failure",
"error": "unable to retrieve repo secret docker_username: unable to get secret repo/vela/ui/docker_username from native service: record not found",
"enqueued": 1572980376,
Expand All @@ -70,15 +70,15 @@
"deploy": "",
"link": "/github/octocat/3",
"clone": "https://github.com/github/octocat.git",
"source": "https://github.com/github/octocat/commit/7bd468e69a42e92153525288800692186bb0120b",
"title": "push received from https://github.com/github/octocat",
"source": "https://github.com/github/octocat/pull/42",
"title": "pull_request received from https://github.com/github/octocat",
"message": "fixing docker params",
"commit": "7bd468e69a42e92153525288800692186bb0120b",
"sender": "CookieCat",
"author": "CookieCat",
"branch": "infra",
"ref": "refs/heads/infra",
"base_ref": "",
"branch": "main",
"ref": "refs/pull/42/head",
"base_ref": "main",
"host": "",
"runtime": "docker",
"distribution": "linux"
Expand Down
20 changes: 10 additions & 10 deletions cypress/fixtures/builds_pull.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
"deploy": "",
"link": "/github/octocat/2",
"clone": "https://github.com/github/octocat.git",
"source": "https://github.com/github/octocat/commit/7bd468e69a42e92153525288800692186bb0120b",
"title": "push received from https://github.com/github/octocat",
"source": "https://github.com/github/octocat/pull/42",
"title": "pull_request received from https://github.com/github/octocat",
"message": "fixing docker params",
"commit": "7bd468e69a42e92153525288800692186bb0120b",
"sender": "CookieCat",
"author": "CookieCat",
"branch": "infra",
"ref": "refs/heads/infra",
"base_ref": "",
"branch": "main",
"ref": "refs/pull/42/head",
"base_ref": "main",
"host": "",
"runtime": "docker",
"distribution": "linux"
Expand All @@ -42,15 +42,15 @@
"deploy": "",
"link": "/github/octocat/3",
"clone": "https://github.com/github/octocat.git",
"source": "https://github.com/github/octocat/commit/7bd468e69a42e92153525288800692186bb0120b",
"title": "push received from https://github.com/github/octocat",
"source": "https://github.com/github/octocat/pull/42",
"title": "pull_request received from https://github.com/github/octocat",
"message": "fixing docker params",
"commit": "7bd468e69a42e92153525288800692186bb0120b",
"sender": "CookieCat",
"author": "CookieCat",
"branch": "infra",
"ref": "refs/heads/infra",
"base_ref": "",
"branch": "main",
"ref": "refs/pull/42/head",
"base_ref": "main",
"host": "",
"runtime": "docker",
"distribution": "linux"
Expand Down
19 changes: 18 additions & 1 deletion cypress/integration/build.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ context('Build', () => {
method: 'POST',
url: 'api/v1/repos/*/*/builds/*/approve',
status: 200,
response: 'approved build github/octocat/8',
response: 'Successfully approved build github/octocat/8',
});
cy.get('[data-test=approve-build]').as('approvedBuild');
});
Expand All @@ -230,6 +230,23 @@ context('Build', () => {
});
});

context('server stubbed Approved Build', () => {
beforeEach(() => {
cy.visit('/github/octocat/9');
cy.server();
});

it('should show who approved the build', () => {
cy.get('[data-test=git-info]').contains('approved by gh0st');
});

it('sha should link to the commit in the PR', () => {
cy.get('[data-test=commit-link]')
.invoke('attr', 'href')
.should('contains', 'pull/42/commits/');
});
});

context('visit running build', () => {
beforeEach(() => {
cy.visit('/github/octocat/1');
Expand Down
7 changes: 7 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Cypress.Commands.add('stubBuild', () => {
cy.fixture('build_error.json').as('errorBuild');
cy.fixture('build_canceled.json').as('cancelBuild');
cy.fixture('build_pending_approval.json').as('pendingApprovalBuild');
cy.fixture('build_approved.json').as('approvedBuild');
cy.route({
method: 'GET',
url: 'api/v1/repos/*/*/builds/1',
Expand Down Expand Up @@ -112,6 +113,12 @@ Cypress.Commands.add('stubBuild', () => {
status: 200,
response: `@pendingApprovalBuild`,
});
cy.route({
method: 'GET',
url: 'api/v1/repos/*/*/builds/9',
status: 200,
response: `@approvedBuild`,
});
});

Cypress.Commands.add('stubBuilds', () => {
Expand Down
17 changes: 14 additions & 3 deletions src/elm/Pages/Build/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,11 @@ viewPreview msgs openMenu showMenu now zone org repo showTimestamp build =
, text (getNameFromRef build.ref)
]
, text " ("
, a [ href build.source ] [ text <| Util.trimCommitHash build.commit ]
, a
[ href (Util.buildPRCommitURL build.source build.commit)
, Util.testAttribute "commit-link"
]
[ text <| Util.trimCommitHash build.commit ]
, text <| ")"
]

Expand Down Expand Up @@ -391,6 +395,13 @@ viewPreview msgs openMenu showMenu now zone org repo showTimestamp build =

statusClass =
statusToClass build.status

approvedBy =
if build.approved_at /= 0 && build.event == "pull_request" then
[ text <| " (approved by " ++ build.approved_by ++ ")" ]

else
[]
in
div [ class "build-container", Util.testAttribute "build" ]
[ div [ class "build", statusClass ]
Expand All @@ -401,12 +412,12 @@ viewPreview msgs openMenu showMenu now zone org repo showTimestamp build =
, div [ class "commit-msg" ] [ strong [] message ]
]
, div [ class "row" ]
[ div [ class "git-info" ]
[ div [ class "git-info", Util.testAttribute "git-info" ]
[ div [ class "commit" ] commit
, text "on"
, div [ class "branch" ] branch
, text "by"
, div [ class "sender" ] sender
, div [ class "sender" ] (sender ++ approvedBy)
]
, div [ class "time-info" ]
[ div [ class "time-completed" ]
Expand Down
8 changes: 8 additions & 0 deletions src/elm/Util.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Util exposing
, base64Decode
, boolToString
, boolToYesNo
, buildPRCommitURL
, buildRefURL
, checkScheduleAllowlist
, dispatch
Expand Down Expand Up @@ -514,6 +515,13 @@ buildRefURL clone ref =
String.dropRight 4 clone ++ "/tree/" ++ ref


{-| buildPRCommitURL : creates a direct link to a commit in a PR
-}
buildPRCommitURL : String -> String -> String
buildPRCommitURL source commit =
source ++ "/commits/" ++ commit


{-| trimCommitHash : takes the first 7 characters of the full commit hash
-}
trimCommitHash : String -> String
Expand Down

0 comments on commit d42df76

Please sign in to comment.