Add issue creation

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez
2023-03-01 15:12:03 +01:00
parent d71f47a98a
commit d1168dc6ff
33 changed files with 848 additions and 327 deletions
+3 -2
View File
@@ -1,4 +1,5 @@
import { defaultSeedPort } from "@app/lib/seed";
import { isLocal } from "@app/lib/utils";
export interface Host {
host: string;
@@ -19,7 +20,7 @@ export class Request {
this.base = api.host;
}
this.path = path.startsWith("/") ? path.slice(1) : path;
this.protocol = api.host === "0.0.0.0" ? "http://" : "https://";
this.protocol = isLocal(api.host) ? "http://" : "https://";
}
async get(
@@ -87,7 +88,7 @@ export class Request {
const query: Record<string, string> = {};
for (const [key, val] of Object.entries(params)) {
if (val !== undefined && val !== null) {
query[key] = val.toString();
query[key] = val;
}
}
+11 -14
View File
@@ -1,26 +1,23 @@
import type { PeerId } from "@app/lib/project";
export type Thread = Comment<Comment[]>;
export interface Comment<R = null> {
author: Author;
body: string;
reactions: Record<string, number>;
timestamp: number;
replies: R; // TODO: Remove for Heartwood migration
replyTo: R;
}
export interface Author {
peer: PeerId;
id: string;
profile: {
name: string;
ens: {
name: string;
} | null;
} | null;
}
export interface PeerIdentity {
id: string;
name: string;
ens: {
name: string;
} | null;
}
export interface PeerInfo {
id: PeerId;
id: string;
person?: PeerIdentity;
delegate: boolean;
}
+28 -5
View File
@@ -1,5 +1,7 @@
import { type Host, Request } from "@app/lib/api";
import type { Author } from "@app/lib/cobs";
import type { Host } from "@app/lib/api";
import { Request } from "@app/lib/api";
export interface TimelineItem {
person: Author;
@@ -14,7 +16,8 @@ export interface IIssue {
state: State;
comment: Comment; // TODO: Remove this after we have migrated to Heartwood.
discussion: Thread[];
tags: Tag[];
tags: string[];
assignees: string[];
timestamp: number;
}
@@ -38,8 +41,6 @@ export interface Comment<R = null> {
export type Thread = Comment<Comment[]>;
export type Tag = string;
export function groupIssues(issues: Issue[]): {
open: Issue[];
closed: Issue[];
@@ -60,7 +61,8 @@ export class Issue {
state: State;
comment: Comment; // TODO: Remove this after we have migrated to Heartwood.
discussion: Thread[];
tags: Tag[];
tags: string[];
assignees: string[];
timestamp: number;
constructor(issue: IIssue) {
@@ -71,6 +73,7 @@ export class Issue {
this.comment = issue.comment; // TODO: Remove this after we have migrated to Heartwood.
this.discussion = issue.discussion;
this.tags = issue.tags;
this.assignees = issue.assignees;
if (window.HEARTWOOD) {
this.timestamp = issue.discussion[0].timestamp;
} else {
@@ -92,6 +95,26 @@ export class Issue {
}
}
static async createIssue(
project: string,
title: string,
description: string,
assignees: string[],
tags: string[],
host: Host,
authToken: string,
): Promise<void> {
await new Request(`projects/${project}/issues`, host).post(
{
title,
description,
assignees,
tags,
},
{ Authorization: `Bearer ${authToken}` },
);
}
static async getIssues(id: string, host: Host): Promise<Issue[]> {
const response: IIssue[] = await new Request(
`projects/${id}/issues`,
+24 -12
View File
@@ -41,10 +41,17 @@ export interface ProjectInfo {
name: string;
description: string;
defaultBranch: string;
delegates: Delegate[]; // TODO: Remove this after we have migrated to Heartwood.
delegates: string[];
remotes: PeerId[]; // TODO: Remove this after we have migrated to Heartwood.
patches?: number;
issues?: number;
patches: {
proposed: number;
draft: number;
archived: number;
};
issues: {
open: number;
closed: number;
};
}
export interface Tree {
@@ -153,14 +160,20 @@ export class Project implements ProjectInfo {
name: string;
description: string;
defaultBranch: string;
delegates: Delegate[]; // TODO: Remove this after we have migrated to Heartwood.
delegates: string[];
remotes: PeerId[]; // TODO: Remove this after we have migrated to Heartwood.
seed: Seed;
peers: Peer[];
branches: Branches;
// At the moment we still have seed nodes which won't return neither patches or issues
patches?: number;
issues?: number;
patches: {
proposed: number;
draft: number;
archived: number;
};
issues: {
open: number;
closed: number;
};
constructor(
id: string,
@@ -174,7 +187,7 @@ export class Project implements ProjectInfo {
this.name = info.name;
this.description = info.description;
this.defaultBranch = info.defaultBranch;
this.delegates = info.delegates; // TODO: Remove this after we have migrated to Heartwood.
this.delegates = info.delegates;
this.remotes = info.remotes; // TODO: Remove this after we have migrated to Heartwood.
this.seed = seed;
this.peers = peers;
@@ -407,11 +420,10 @@ export class Project implements ProjectInfo {
? seedHost.split(":")
: [seedHost, defaultSeedPort];
const seed = await Seed.lookup(host, Number(port));
if (!seed) {
const seed = await Seed.lookup(host, Number(port)).catch(() => {
throw new Error("Couldn't load project");
}
});
if (!seed?.valid) {
throw new Error("Couldn't load project: invalid seed");
}
+18 -3
View File
@@ -256,6 +256,11 @@ export function routeToPath(route: Route) {
return `${hostPrefix}/${route.params.id}${peer}/patches${suffix}`;
} else if (route.params.view.resource === "patch") {
return `${hostPrefix}/${route.params.id}${peer}/patches/${route.params.view.params.patch}`;
} else if (
route.params.view.resource === "issues" &&
route.params.view.params?.view.resource === "new"
) {
return `${hostPrefix}/${route.params.id}${peer}/issues/new${suffix}`;
} else if (route.params.view.resource === "issues") {
return `${hostPrefix}/${route.params.id}${peer}/issues${suffix}`;
} else if (route.params.view.resource === "issue") {
@@ -344,10 +349,20 @@ function resolveProjectRoute(
};
}
} else if (content === "issues") {
const issue = segments.shift();
if (issue) {
const issueOrAction = segments.shift();
if (issueOrAction === "new") {
return {
view: { resource: "issue", params: { issue } },
view: { resource: "issues", params: { view: { resource: "new" } } },
id,
seed,
peer,
search: sanitizeQueryString(url.search),
path: undefined,
revision: undefined,
};
} else if (issueOrAction) {
return {
view: { resource: "issue", params: { issue: issueOrAction } },
id,
seed,
peer,
+6 -1
View File
@@ -15,7 +15,12 @@ export interface ProjectsParams {
| { resource: "commits" }
| { resource: "history" }
| { resource: "issue"; params: { issue: string } }
| { resource: "issues" }
| {
resource: "issues";
params?: {
view: { resource: "new" };
};
}
| { resource: "patch"; params: { patch: string } }
| { resource: "patches" };
seed: string;
+1 -1
View File
@@ -1,6 +1,6 @@
import { derived, get, writable } from "svelte/store";
interface Session {
export interface Session {
id: string;
publicKey: string;
}
+38 -2
View File
@@ -1,4 +1,5 @@
import md5 from "md5";
import bs58 from "bs58";
import twemojiModule from "twemoji";
import { assert } from "@app/lib/error";
@@ -56,6 +57,41 @@ export function formatRadicleId(id: string): string {
}
}
// Parses a NID into an object of prefix and pubkey,
// since prefix can be undefined
export function parseNid(
nid: string,
): { prefix: string; pubkey: string } | undefined {
const match = /^(did:key:)?(z[a-zA-Z0-9]+)$/.exec(nid);
if (match) {
const hex = bs58.decode(match[2].substring(1));
// This checks also that the first 2 bytes are equal
// to the ed25519 public key type used.
if (!(hex.byteLength === 34 && hex[0] === 0xed && hex[1] === 1)) {
return undefined;
}
return { prefix: match[1] || "did:key:", pubkey: match[2] };
}
return undefined;
}
// Format a Node Identifier (NID), also represents users or peers
export function formatNodeId(nid: string): string {
const parsedNid = parseNid(nid);
if (parsedNid) {
const { prefix, pubkey } = parsedNid;
const formattedPubKey =
pubkey.substring(0, 6) +
"…" +
pubkey.substring(pubkey.length - 6, pubkey.length);
return `${prefix}${formattedPubKey}`;
}
return nid;
}
export function formatCommit(oid: string): string {
return oid.substring(0, 7);
}
@@ -158,7 +194,7 @@ export const formatTimestamp = (
// Check whether the input is a Radicle ID.
export function isRadicleId(input: string): boolean {
if (window.HEARTWOOD) {
return /^rad:[a-zA-Z0-9]+$/.test(input);
return /^(did:key:)?[a-zA-Z0-9]+$/.test(input);
} else {
return /^rad:[a-z]+:[a-zA-Z0-9]+$/.test(input);
}
@@ -226,7 +262,7 @@ export function isMarkdownPath(path: string): boolean {
export function isDomain(input: string): boolean {
return (
(/^[a-z][a-z0-9.-]+$/.test(input) && /\.[a-z]+$/.test(input)) ||
(!import.meta.env.PROD && /^0.0.0.0$/.test(input))
(!import.meta.env.PROD && isLocal(input))
);
}