Skip to content

Commit

Permalink
Add release channel page
Browse files Browse the repository at this point in the history
  • Loading branch information
WalshyDev committed Dec 8, 2023
1 parent a117a93 commit c5681d9
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 3 deletions.
12 changes: 10 additions & 2 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import { ProjectList } from 'worker/src/store/ProjectStore';
import { ProjectList } from '../../../worker/src/store/ProjectStore';

export function getProjects(env: Env) {
return _fetch<ProjectList>(env, '/api/projects');
}

export function getAllBuildsPerProject(env: Env, project: string) {
export function getAllBuildsPerProject(env: Env, project: string, releaseChannel?: string) {
if (releaseChannel) {
return getAllBuildsPerProjectAndReleaseChannel(env, project, releaseChannel);
}
return _fetch<BuildList>(env, `/api/builds/${project}`);
}

export function getAllBuildsPerProjectAndReleaseChannel(env: Env, project: string, releaseChannel: string) {
return _fetch<BuildList>(env, `/api/builds/${project}/${releaseChannel}`);
}

export function _fetch<T = unknown>(env: Env, path: string, init?: RequestInit): Promise<ApiResponse<T>> {
// TODO: handle auth

console.log(`fetching ${path}`);
return env.API.fetch(`https://api.local${path}`, init).then(res => res.json());
}
1 change: 1 addition & 0 deletions site/src/remix.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface Env {

interface BlobParams {
project?: string;
releaseChannel?: string;
}

interface DataFunctionArgs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { getAllBuildsPerProject } from '~/api/api';
import { BuildsTable } from '~/components/projects/BuildsTable';

export const loader: LoaderFunction<BuildList | { error: string }> = async ({ context, params }) => {
const builds = await getAllBuildsPerProject(context, params.project!);
if (!params.project) {
return json({ error: 'No project provided' });
}

const builds = await getAllBuildsPerProject(context, params.project, params.releaseChannel);
if (builds.success) {
const buildList = builds.data ?? {};
for (const channel of Object.keys(buildList)) {
Expand Down
27 changes: 27 additions & 0 deletions worker/src/handlers/builds/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,33 @@ export async function getAllProjectBuilds(ctx: Ctx) {
return success('Success', res);
}

// GET /api/builds/:projectName
export async function getAllProjectBuildsForReleaseChannel(ctx: Ctx) {
const projectName = ctx.req.param('projectName');
const releaseChannelName = ctx.req.param('releaseChannel');

const project = await ProjectStore.getProjectByName(projectName);
if (project === undefined) {
return errors.ProjectNotFound.toResponse(ctx);
}
const releaseChannel = await ReleaseChannelStore.getReleaseChannel(releaseChannelName, project.projectId);
if (releaseChannel === undefined) {
return errors.ReleaseChannelNotFound.toResponse(ctx);
}
const builds = await BuildStore.getProjectBuildsForReleaseChannel(project.projectId, releaseChannel.releaseChannelId);
if (builds === undefined) {
return errors.BuildNotFound.toResponse(ctx);
}

const res: { [releaseChannel: string]: BuildResponse[] } = {};
res[releaseChannel.name] = [];
for (const build of builds) {
res[releaseChannel.name].push(toBuildResponse(build, project));
}

return success('Success', res);
}

// GET /api/builds/:projectName/latest
export async function getProjectLatestBuild(ctx: Context) {
const projectName = ctx.req.param('projectName');
Expand Down
5 changes: 5 additions & 0 deletions worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
postUploadBuild,
getAllProjectBuilds,
getProjectBuildVersion,
getAllProjectBuildsForReleaseChannel,
} from '~/handlers/builds/build';
import { getDownloadBuild } from '~/handlers/builds/download';
import {
Expand Down Expand Up @@ -72,6 +73,10 @@ app.get(
'/api/builds/:projectName',
getAllProjectBuilds,
);
app.get(
'/api/builds/:projectName/:releaseChannel',
getAllProjectBuildsForReleaseChannel,
);
app.get(
'/api/builds/:projectName/latest',
getProjectLatestBuild,
Expand Down
13 changes: 13 additions & 0 deletions worker/src/store/BuildStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ class _BuildStore {
.all();
}

getProjectBuildsForReleaseChannel(projectId: number, releaseChannelId: number): Promise<Build[]> {
return getDb().select()
.from(builds)
.where(
and(
eq(builds.projectId, projectId),
eq(builds.releaseChannelId, releaseChannelId),
),
)
.orderBy(desc(builds.buildId))
.all();
}

// Get latest build for a project and release channel
getLatestBuildForReleaseChannel(projectName: string, releaseChannel: string): Promise<Build> {
return getDb().select({ ...selectStar(builds) })
Expand Down

0 comments on commit c5681d9

Please sign in to comment.