From d244f24de13e31b27ac5cbc4eb3bf6968b33f28d Mon Sep 17 00:00:00 2001 From: noah Date: Mon, 20 Dec 2021 22:16:25 +0900 Subject: [PATCH 1/2] Add new status: 'cancelled', 'skipped' --- internal/pkg/github/mapper.go | 15 ++++++-------- internal/server/api/v1/repos/commit.go | 2 +- model/extent/commit.go | 8 +++++--- ui/src/apis/commit.ts | 22 +++++++++++++-------- ui/src/components/StatusStateIcon.tsx | 27 +++++++++++++++++--------- ui/src/models/Commit.ts | 2 ++ 6 files changed, 46 insertions(+), 30 deletions(-) diff --git a/internal/pkg/github/mapper.go b/internal/pkg/github/mapper.go index ea6bea4a..e672822f 100644 --- a/internal/pkg/github/mapper.go +++ b/internal/pkg/github/mapper.go @@ -115,18 +115,15 @@ func mapGithubCheckRunToStatus(c *github.CheckRun) *extent.Status { // Conclusion exist when the status is 'completed', only. if c.Conclusion == nil { - return &extent.Status{ - Context: *c.Name, - AvatarURL: *c.App.Owner.AvatarURL, - TargetURL: *c.HTMLURL, - State: extent.StatusStatePending, - } - } - - if *c.Conclusion == "success" { + state = extent.StatusStatePending + } else if *c.Conclusion == "success" { state = extent.StatusStateSuccess } else if *c.Conclusion == "failure" { state = extent.StatusStateFailure + } else if *c.Conclusion == "cancelled" { + state = extent.StatusStateCancelled + } else if *c.Conclusion == "skipped" { + state = extent.StatusStateSkipped } else { state = extent.StatusStatePending } diff --git a/internal/server/api/v1/repos/commit.go b/internal/server/api/v1/repos/commit.go index 8bd1ef3d..0dec9c74 100644 --- a/internal/server/api/v1/repos/commit.go +++ b/internal/server/api/v1/repos/commit.go @@ -87,7 +87,7 @@ func (r *Repo) ListStatuses(c *gin.Context) { func mergeState(ss []*extent.Status) string { // The state is failure if one of them is failure. for _, s := range ss { - if s.State == extent.StatusStateFailure { + if s.State == extent.StatusStateFailure || s.State == extent.StatusStateCancelled { return string(extent.StatusStateFailure) } } diff --git a/model/extent/commit.go b/model/extent/commit.go index add936e8..2d4e3e8c 100644 --- a/model/extent/commit.go +++ b/model/extent/commit.go @@ -35,7 +35,9 @@ type ( ) const ( - StatusStateSuccess StatusState = "success" - StatusStateFailure StatusState = "failure" - StatusStatePending StatusState = "pending" + StatusStateSuccess StatusState = "success" + StatusStateFailure StatusState = "failure" + StatusStatePending StatusState = "pending" + StatusStateCancelled StatusState = "cancelled" + StatusStateSkipped StatusState = "skipped" ) diff --git a/ui/src/apis/commit.ts b/ui/src/apis/commit.ts index 9607e256..76a7d766 100644 --- a/ui/src/apis/commit.ts +++ b/ui/src/apis/commit.ts @@ -52,15 +52,21 @@ const mapDataToStatus = (data: StatusData): Status => { } } -const mapStatusState = (state: string) => { - if (state === "pending") { - return StatusState.Pending - } else if (state === "success") { - return StatusState.Success - } else if (state === "failure") { - return StatusState.Failure +const mapStatusState = (state: string): StatusState => { + switch (state) { + case "pending": + return StatusState.Pending + case "success": + return StatusState.Success + case "failure": + return StatusState.Failure + case "cancelled": + return StatusState.Cancelled + case "skipped": + return StatusState.Skipped + default: + return StatusState.Pending } - return StatusState.Pending } export const listCommits = async (namespace: string, name: string, branch: string, page = 1, perPage = 30): Promise => { diff --git a/ui/src/components/StatusStateIcon.tsx b/ui/src/components/StatusStateIcon.tsx index 388ed6eb..82039f3f 100644 --- a/ui/src/components/StatusStateIcon.tsx +++ b/ui/src/components/StatusStateIcon.tsx @@ -1,5 +1,5 @@ import { Popover, Avatar, Typography, Row, Col, Divider } from "antd" -import { CheckOutlined, CloseOutlined } from "@ant-design/icons" +import { CheckOutlined, CloseOutlined, StopOutlined, ExclamationCircleOutlined } from "@ant-design/icons" import { Status, StatusState } from "../models" @@ -41,19 +41,27 @@ export default function StatusStateIcon(props: StatusStateIconProps): JSX.Elemen function mapStateToIcon(state: StatusState): JSX.Element { switch (state) { case StatusState.Null: - return + return <> case StatusState.Pending: - return -    - + return ( + +    + + ) case StatusState.Success: return case StatusState.Failure: return + case StatusState.Cancelled: + return + case StatusState.Skipped: + return default: - return -    - + return ( + +    + + ) } } @@ -64,7 +72,8 @@ function mergeStatusStates(states: StatusState[]): StatusState { // The state is failure if one of them is failure. for (let idx = 0; idx < states.length; idx++) { - if (states[idx] === StatusState.Failure) { + if (states[idx] === StatusState.Failure + || states[idx] === StatusState.Cancelled) { return StatusState.Failure } } diff --git a/ui/src/models/Commit.ts b/ui/src/models/Commit.ts index 9c23db7d..a91b25da 100644 --- a/ui/src/models/Commit.ts +++ b/ui/src/models/Commit.ts @@ -24,4 +24,6 @@ export enum StatusState { Pending = "pending", Success = "success", Failure = "failure", + Cancelled = "cancelled", + Skipped = "skipped" } \ No newline at end of file From 6cbb056958aae92333d08e2430ef905fd47a2a0b Mon Sep 17 00:00:00 2001 From: noah Date: Mon, 20 Dec 2021 22:18:37 +0900 Subject: [PATCH 2/2] Add new statuses to openapi --- openapi/v1.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openapi/v1.yaml b/openapi/v1.yaml index dcdc775b..5b5378e3 100644 --- a/openapi/v1.yaml +++ b/openapi/v1.yaml @@ -1559,6 +1559,8 @@ components: - pending - failure - success + - cancelled + - skipped required: - context - avatar_url