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

Commit

Permalink
Fix the short ref bug (#305)
Browse files Browse the repository at this point in the history
* Fix the short ref bug
  • Loading branch information
Noah Lee committed Jan 9, 2022
1 parent 38fac57 commit ba3e585
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
10 changes: 10 additions & 0 deletions ui/src/libs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Deployment, DeploymentType } from "../models"

/**
* The function returns the short-formatted ref string.
* @param deployment
* @returns
*/
export const getShortRef = (deployment: Deployment): string => {
return deployment.type === DeploymentType.Commit? deployment.ref.substring(0, 7) : deployment.ref
}
2 changes: 2 additions & 0 deletions ui/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
HttpRequestError,
HttpInternalServerError,
HttpUnauthorizedError,
HttpPaymentRequiredError,
HttpForbiddenError,
HttpNotFoundError,
HttpConflictError,
Expand Down Expand Up @@ -50,6 +51,7 @@ export {
HttpRequestError,
HttpInternalServerError,
HttpUnauthorizedError,
HttpPaymentRequiredError,
HttpForbiddenError,
HttpNotFoundError,
HttpConflictError,
Expand Down
15 changes: 8 additions & 7 deletions ui/src/redux/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
EventTypeEnum,
HttpInternalServerError,
HttpUnauthorizedError,
HttpPaymentRequiredError,
License,
} from "../models"
import {
Expand All @@ -19,7 +20,7 @@ import {
searchReviews as _searchReviews,
getLicense
} from "../apis"
import { HttpPaymentRequiredError } from "../models/errors"
import { getShortRef } from "../libs"

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

if (event.kind !== EventKindEnum.Deployment) {
if (!(event.kind === EventKindEnum.Deployment && event.deployment)) {
return
}

if (event.deployment?.deployer?.id !== user?.id) {
if (event.deployment.deployer?.id !== user?.id) {
return
}

if (event.type === EventTypeEnum.Created) {
notify(`New Deployment #${event.deployment?.number}`, {
notify(`New Deployment #${event.deployment.number}`, {
icon: "/logo192.png",
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}.`,
body: `Start to deploy ${getShortRef(event.deployment)} to the ${event.deployment.env} environment of ${event.deployment.repo?.namespace}/${event.deployment.repo?.name}.`,
tag: String(event.id),
})
return
}

notify(`Deployment Updated #${event.deployment?.number}`, {
notify(`Deployment Updated #${event.deployment.number}`, {
icon: "/logo192.png",
body: `The deployment ${event.deployment?.number} of ${event.deployment?.repo?.namespace}/${event.deployment?.repo?.name} is updated ${event.deployment?.status}.`,
body: `The deployment ${event.deployment.number} of ${event.deployment.repo?.namespace}/${event.deployment.repo?.name} is updated ${event.deployment.status}.`,
tag: String(event.id),
})
}
Expand Down

0 comments on commit ba3e585

Please sign in to comment.