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

Commit 2828f4e

Browse files
author
Noah Lee
authored
Fix the short ref bug (#305)
* Fix the short ref bug
1 parent 8b7748f commit 2828f4e

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

ui/src/libs/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Deployment, DeploymentType } from "../models"
2+
3+
/**
4+
* The function returns the short-formatted ref string.
5+
* @param deployment
6+
* @returns
7+
*/
8+
export const getShortRef = (deployment: Deployment): string => {
9+
return deployment.type === DeploymentType.Commit? deployment.ref.substring(0, 7) : deployment.ref
10+
}

ui/src/models/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
HttpRequestError,
1919
HttpInternalServerError,
2020
HttpUnauthorizedError,
21+
HttpPaymentRequiredError,
2122
HttpForbiddenError,
2223
HttpNotFoundError,
2324
HttpConflictError,
@@ -50,6 +51,7 @@ export {
5051
HttpRequestError,
5152
HttpInternalServerError,
5253
HttpUnauthorizedError,
54+
HttpPaymentRequiredError,
5355
HttpForbiddenError,
5456
HttpNotFoundError,
5557
HttpConflictError,

ui/src/redux/main.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
EventTypeEnum,
1212
HttpInternalServerError,
1313
HttpUnauthorizedError,
14+
HttpPaymentRequiredError,
1415
License,
1516
} from "../models"
1617
import {
@@ -19,7 +20,7 @@ import {
1920
searchReviews as _searchReviews,
2021
getLicense
2122
} from "../apis"
22-
import { HttpPaymentRequiredError } from "../models/errors"
23+
import { getShortRef } from "../libs"
2324

2425
interface MainState {
2526
available: boolean
@@ -143,26 +144,26 @@ export const notifyDeploymentEvent = createAsyncThunk<void, Event, { state: { ma
143144
async (event, { getState }) => {
144145
const { user } = getState().main
145146

146-
if (event.kind !== EventKindEnum.Deployment) {
147+
if (!(event.kind === EventKindEnum.Deployment && event.deployment)) {
147148
return
148149
}
149150

150-
if (event.deployment?.deployer?.id !== user?.id) {
151+
if (event.deployment.deployer?.id !== user?.id) {
151152
return
152153
}
153154

154155
if (event.type === EventTypeEnum.Created) {
155-
notify(`New Deployment #${event.deployment?.number}`, {
156+
notify(`New Deployment #${event.deployment.number}`, {
156157
icon: "/logo192.png",
157-
body: `Start to deploy ${event.deployment?.ref.substring(0, 7)} to the ${event.deployment?.env} environment of ${event.deployment?.repo?.namespace}/${event.deployment?.repo?.name}.`,
158+
body: `Start to deploy ${getShortRef(event.deployment)} to the ${event.deployment.env} environment of ${event.deployment.repo?.namespace}/${event.deployment.repo?.name}.`,
158159
tag: String(event.id),
159160
})
160161
return
161162
}
162163

163-
notify(`Deployment Updated #${event.deployment?.number}`, {
164+
notify(`Deployment Updated #${event.deployment.number}`, {
164165
icon: "/logo192.png",
165-
body: `The deployment ${event.deployment?.number} of ${event.deployment?.repo?.namespace}/${event.deployment?.repo?.name} is updated ${event.deployment?.status}.`,
166+
body: `The deployment ${event.deployment.number} of ${event.deployment.repo?.namespace}/${event.deployment.repo?.name} is updated ${event.deployment.status}.`,
166167
tag: String(event.id),
167168
})
168169
}

0 commit comments

Comments
 (0)