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

Fix the short ref bug #305

Merged
merged 2 commits into from
Jan 9, 2022
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
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mutate the ref for the commit type.

}
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