Path: blob/main/components/gitpod-protocol/src/attribution.ts
2498 views
/**1* Copyright (c) 2022 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { Organization } from "./teams-projects-protocol";78export type AttributionId = TeamAttributionId;9export type AttributionTarget = "user" | "team";1011export interface TeamAttributionId {12kind: "team";13teamId: string;14}1516export namespace AttributionId {17const SEPARATOR = ":";1819export function createFromOrganizationId(organizationId: string): AttributionId {20return { kind: "team", teamId: organizationId };21}2223export function create(organization: Organization): AttributionId {24return createFromOrganizationId(organization.id);25}2627export function parse(s: string): AttributionId | undefined {28if (!s) {29return undefined;30}31const parts = s.split(":");32if (parts.length !== 2) {33return undefined;34}35switch (parts[0]) {36case "team":37return { kind: "team", teamId: parts[1] };38}39return undefined;40}4142export function render(id: AttributionId): string {43switch (id.kind) {44case "team":45return `team${SEPARATOR}${id.teamId}`;46}47// allthough grayed as unreachable it is reachable at runtime48throw new Error("invalid attributionId kind : " + id.kind);49}5051export function equals(a: AttributionId, b: AttributionId): boolean {52return render(a) === render(b);53}54}555657