Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 34c1917

Browse files
author
Noah Lee
authored
Add new status: 'cancelled', 'skipped' (#280)
* Add new status: 'cancelled', 'skipped' * Add new statuses to openapi
1 parent 1d01093 commit 34c1917

File tree

7 files changed

+48
-30
lines changed

7 files changed

+48
-30
lines changed

internal/pkg/github/mapper.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,15 @@ func mapGithubCheckRunToStatus(c *github.CheckRun) *extent.Status {
115115

116116
// Conclusion exist when the status is 'completed', only.
117117
if c.Conclusion == nil {
118-
return &extent.Status{
119-
Context: *c.Name,
120-
AvatarURL: *c.App.Owner.AvatarURL,
121-
TargetURL: *c.HTMLURL,
122-
State: extent.StatusStatePending,
123-
}
124-
}
125-
126-
if *c.Conclusion == "success" {
118+
state = extent.StatusStatePending
119+
} else if *c.Conclusion == "success" {
127120
state = extent.StatusStateSuccess
128121
} else if *c.Conclusion == "failure" {
129122
state = extent.StatusStateFailure
123+
} else if *c.Conclusion == "cancelled" {
124+
state = extent.StatusStateCancelled
125+
} else if *c.Conclusion == "skipped" {
126+
state = extent.StatusStateSkipped
130127
} else {
131128
state = extent.StatusStatePending
132129
}

internal/server/api/v1/repos/commit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (r *Repo) ListStatuses(c *gin.Context) {
8787
func mergeState(ss []*extent.Status) string {
8888
// The state is failure if one of them is failure.
8989
for _, s := range ss {
90-
if s.State == extent.StatusStateFailure {
90+
if s.State == extent.StatusStateFailure || s.State == extent.StatusStateCancelled {
9191
return string(extent.StatusStateFailure)
9292
}
9393
}

model/extent/commit.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ type (
3535
)
3636

3737
const (
38-
StatusStateSuccess StatusState = "success"
39-
StatusStateFailure StatusState = "failure"
40-
StatusStatePending StatusState = "pending"
38+
StatusStateSuccess StatusState = "success"
39+
StatusStateFailure StatusState = "failure"
40+
StatusStatePending StatusState = "pending"
41+
StatusStateCancelled StatusState = "cancelled"
42+
StatusStateSkipped StatusState = "skipped"
4143
)

openapi/v1.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,8 @@ components:
15591559
- pending
15601560
- failure
15611561
- success
1562+
- cancelled
1563+
- skipped
15621564
required:
15631565
- context
15641566
- avatar_url

ui/src/apis/commit.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,21 @@ const mapDataToStatus = (data: StatusData): Status => {
5252
}
5353
}
5454

55-
const mapStatusState = (state: string) => {
56-
if (state === "pending") {
57-
return StatusState.Pending
58-
} else if (state === "success") {
59-
return StatusState.Success
60-
} else if (state === "failure") {
61-
return StatusState.Failure
55+
const mapStatusState = (state: string): StatusState => {
56+
switch (state) {
57+
case "pending":
58+
return StatusState.Pending
59+
case "success":
60+
return StatusState.Success
61+
case "failure":
62+
return StatusState.Failure
63+
case "cancelled":
64+
return StatusState.Cancelled
65+
case "skipped":
66+
return StatusState.Skipped
67+
default:
68+
return StatusState.Pending
6269
}
63-
return StatusState.Pending
6470
}
6571

6672
export const listCommits = async (namespace: string, name: string, branch: string, page = 1, perPage = 30): Promise<Commit[]> => {

ui/src/components/StatusStateIcon.tsx

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Popover, Avatar, Typography, Row, Col, Divider, Space } from "antd"
2-
import { CheckOutlined, CloseOutlined } from "@ant-design/icons"
2+
import { CheckOutlined, CloseOutlined, StopOutlined, ExclamationCircleOutlined } from "@ant-design/icons"
33

44
import { Status, StatusState } from "../models"
55

@@ -64,19 +64,27 @@ export default function StatusStateIcon(props: StatusStateIconProps): JSX.Elemen
6464
function mapStateToIcon(state: StatusState): JSX.Element {
6565
switch (state) {
6666
case StatusState.Null:
67-
return <span></span>
67+
return <></>
6868
case StatusState.Pending:
69-
return <span>
70-
<span className="gitploy-pending-icon" />&nbsp;&nbsp;
71-
</span>
69+
return (
70+
<span>
71+
<span className="gitploy-pending-icon" />&nbsp;&nbsp;
72+
</span>
73+
)
7274
case StatusState.Success:
7375
return <CheckOutlined style={{color: colorSuccess}}/>
7476
case StatusState.Failure:
7577
return <CloseOutlined style={{color: colorFailure}}/>
78+
case StatusState.Cancelled:
79+
return <ExclamationCircleOutlined />
80+
case StatusState.Skipped:
81+
return <StopOutlined />
7682
default:
77-
return <span>
78-
<span className="gitploy-pending-icon" />&nbsp;&nbsp;
79-
</span>
83+
return (
84+
<span>
85+
<span className="gitploy-pending-icon" />&nbsp;&nbsp;
86+
</span>
87+
)
8088
}
8189
}
8290

@@ -87,7 +95,8 @@ function mergeStatusStates(states: StatusState[]): StatusState {
8795

8896
// The state is failure if one of them is failure.
8997
for (let idx = 0; idx < states.length; idx++) {
90-
if (states[idx] === StatusState.Failure) {
98+
if (states[idx] === StatusState.Failure
99+
|| states[idx] === StatusState.Cancelled) {
91100
return StatusState.Failure
92101
}
93102
}

ui/src/models/Commit.ts

+2
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ export enum StatusState {
2424
Pending = "pending",
2525
Success = "success",
2626
Failure = "failure",
27+
Cancelled = "cancelled",
28+
Skipped = "skipped"
2729
}

0 commit comments

Comments
 (0)