Skip to content

Add support for a project release notification #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions src/UnisonShare/Notification.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module UnisonShare.Notification exposing (..)

import Code.BranchRef as BranchRef exposing (BranchRef)
import Code.Version as Version exposing (Version)
import Json.Decode as Decode exposing (field, string)
import Json.Decode.Extra exposing (when)
import Json.Decode.Pipeline exposing (required, requiredAt)
Expand Down Expand Up @@ -78,6 +79,10 @@ type NotificationEventData
{ projectRef : ProjectRef
, branchRef : BranchRef
}
| ProjectReleaseCreated
{ projectRef : ProjectRef
, version : Version
}


type alias NotificationEvent =
Expand Down Expand Up @@ -246,6 +251,11 @@ decodeEventData =
Decode.succeed (\projectRef branchRef -> ProjectBranchUpdated { projectRef = projectRef, branchRef = branchRef })
|> requiredAt [ "project", "projectShortHand" ] ProjectRef.decode
|> requiredAt [ "branch", "branchShortHand" ] BranchRef.decode

decodeReleaseCreated =
Decode.succeed (\projectRef version -> ProjectReleaseCreated { projectRef = projectRef, version = version })
|> requiredAt [ "project", "projectShortHand" ] ProjectRef.decode
|> requiredAt [ "release", "version" ] Version.decode
in
Decode.oneOf
[ whenFieldIs "kind" "project:contribution:created" (field "payload" decodeContributionCreated)
Expand All @@ -255,6 +265,7 @@ decodeEventData =
, whenFieldIs "kind" "project:ticket:updated" (field "payload" decodeTicketUpdated)
, whenFieldIs "kind" "project:ticket:comment" (field "payload" decodeTicketComment)
, whenFieldIs "kind" "project:branch:updated" (field "payload" decodeBranchUpdated)
, whenFieldIs "kind" "project:release:created" (field "payload" decodeReleaseCreated)
]


Expand Down
13 changes: 13 additions & 0 deletions src/UnisonShare/Page/NotificationsPage.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module UnisonShare.Page.NotificationsPage exposing (..)

import Code.BranchRef as BranchRef
import Code.ProjectNameListing as ProjectNameListing
import Code.Version as Version
import Html exposing (Html, div, footer, h1, h2, h4, span, text)
import Html.Attributes exposing (class, classList)
import Json.Decode as Decode exposing (string)
Expand Down Expand Up @@ -427,6 +428,18 @@ viewNotification appContext selection notification =
, projectRef = eventData.projectRef
}

Notification.ProjectReleaseCreated eventData ->
{ kind = "New release"
, title = Version.toString eventData.version
, link = Link.projectRelease eventData.projectRef eventData.version
, event =
Link.projectRelease eventData.projectRef eventData.version
|> Click.view
[ class "notification-row_event-ref" ]
[ text ("Release: " ++ Version.toString eventData.version) ]
, projectRef = eventData.projectRef
}

isUnread =
Notification.isUnread notification

Expand Down
7 changes: 4 additions & 3 deletions tests/e2e/NotificationsPage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ test.describe("when signed in", () => {

test("can view notifications", async ({ page }) => {
await Page.goto(page, "/notifications");
await expect(page.locator(".notification-row")).toHaveCount(6);
await expect(page.locator(".notification-row")).toHaveCount(7);
});

test("can mark a notification as read", async ({ page }) => {
await Page.goto(page, "/notifications");

await expect(page.locator(".notification-row")).toHaveCount(6);
await expect(page.locator(".notification-row")).toHaveCount(7);
await page.locator(".notification-row:first-child input").click();
await expect(Page.button(page, "Mark as read")).toBeVisible();

Expand All @@ -50,11 +50,12 @@ test.describe("when signed in", () => {
notification(),
notification(),
notification(),
notification(),
],
});

await Page.button(page, "Mark as read").click();

await expect(page.locator(".notification-row")).toHaveCount(5);
await expect(page.locator(".notification-row")).toHaveCount(6);
});
});
1 change: 1 addition & 0 deletions tests/e2e/TestHelpers/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ async function getNotificationsHub(
notification("project:ticket:created"),
notification("project:ticket:updated"),
notification("project:ticket:comment"),
notification("project:release:created"),
],
...(data_ ? data_ : {}),
};
Expand Down
63 changes: 43 additions & 20 deletions tests/e2e/TestHelpers/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ function userHandle() {
return faker.lorem.slug(1);
}

function version() {
return faker.system.semver();
}

type User = {
avatarUrl: string;
handle: string;
Expand Down Expand Up @@ -225,28 +229,28 @@ type DiffErrorCulprit = "new" | "old";
type DiffErrorDetails =
| { tag: "impossibleError" }
| {
tag: "constructorAlias";
oldOrNewBranch: DiffErrorCulprit;
typeName: string;
constructorName1: string;
constructorName2: string;
}
tag: "constructorAlias";
oldOrNewBranch: DiffErrorCulprit;
typeName: string;
constructorName1: string;
constructorName2: string;
}
| {
tag: "missingConstructorName";
oldOrNewBranch: DiffErrorCulprit;
typeName: string;
}
tag: "missingConstructorName";
oldOrNewBranch: DiffErrorCulprit;
typeName: string;
}
| {
tag: "nestedDeclAlias";
oldOrNewBranch: DiffErrorCulprit;
constructorName1: string;
constructorName2: string;
}
tag: "nestedDeclAlias";
oldOrNewBranch: DiffErrorCulprit;
constructorName1: string;
constructorName2: string;
}
| {
tag: "strayConstructor";
oldOrNewBranch: DiffErrorCulprit;
constructorName: string;
};
tag: "strayConstructor";
oldOrNewBranch: DiffErrorCulprit;
constructorName: string;
};

type ContributionDiffConfig =
| { tag: "ok" }
Expand Down Expand Up @@ -304,7 +308,8 @@ type NotificationEventKind =
| "project:ticket:created"
| "project:ticket:updated"
| "project:ticket:comment"
| "project:branch:updated";
| "project:branch:updated"
| "project:release:created";

function notificationEventKind(): NotificationEventKind {
return faker.helpers.arrayElement([
Expand All @@ -315,6 +320,7 @@ function notificationEventKind(): NotificationEventKind {
"project:ticket:updated",
"project:ticket:comment",
"project:branch:updated",
"project:release:created",
]);
}

Expand Down Expand Up @@ -438,6 +444,23 @@ function notificationEventPayload(kind?: NotificationEventKind) {
},
};
}
case "project:release:created": {
const projectRef_ = projectRef();
const [projectHandle, projectSlug] = projectRef_.split("/");

return {
release: {
version: version()
},
project: {
projectId: faker.string.uuid(),
projectOwnerHandle: projectHandle,
projectOwnerUserId: faker.string.uuid(),
projectShortHand: projectRef_,
projectSlug: projectSlug,
},
};
}
}
}

Expand Down
Loading