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

Add new commit statuses: 'cancelled', 'skipped' #280

Merged
merged 3 commits into from
Dec 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions internal/pkg/github/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/server/api/v1/repos/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
8 changes: 5 additions & 3 deletions model/extent/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
2 changes: 2 additions & 0 deletions openapi/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,8 @@ components:
- pending
- failure
- success
- cancelled
- skipped
required:
- context
- avatar_url
Expand Down
22 changes: 14 additions & 8 deletions ui/src/apis/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Commit[]> => {
Expand Down
27 changes: 18 additions & 9 deletions ui/src/components/StatusStateIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Popover, Avatar, Typography, Row, Col, Divider, Space } from "antd"
import { CheckOutlined, CloseOutlined } from "@ant-design/icons"
import { CheckOutlined, CloseOutlined, StopOutlined, ExclamationCircleOutlined } from "@ant-design/icons"

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

Expand Down Expand Up @@ -64,19 +64,27 @@ export default function StatusStateIcon(props: StatusStateIconProps): JSX.Elemen
function mapStateToIcon(state: StatusState): JSX.Element {
switch (state) {
case StatusState.Null:
return <span></span>
return <></>
case StatusState.Pending:
return <span>
<span className="gitploy-pending-icon" />&nbsp;&nbsp;
</span>
return (
<span>
<span className="gitploy-pending-icon" />&nbsp;&nbsp;
</span>
)
case StatusState.Success:
return <CheckOutlined style={{color: colorSuccess}}/>
case StatusState.Failure:
return <CloseOutlined style={{color: colorFailure}}/>
case StatusState.Cancelled:
return <ExclamationCircleOutlined />
case StatusState.Skipped:
return <StopOutlined />
default:
return <span>
<span className="gitploy-pending-icon" />&nbsp;&nbsp;
</span>
return (
<span>
<span className="gitploy-pending-icon" />&nbsp;&nbsp;
</span>
)
}
}

Expand All @@ -87,7 +95,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
}
}
Expand Down
2 changes: 2 additions & 0 deletions ui/src/models/Commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ export enum StatusState {
Pending = "pending",
Success = "success",
Failure = "failure",
Cancelled = "cancelled",
Skipped = "skipped"
}