import { match } from 'tiny-types';

import { ArbitraryTag, IssueTag, ManualTag, Tag } from './';

/**
 * @package
 */
export class Tags {
    private static Pattern = /^@([\w-]+)[:\s]?(.*)/i;

    public static from(text: string): Tag[] {
        const [ , type, val ] = Tags.Pattern.exec(text);

        return match<Tag[]>(type.toLowerCase())
            .when('manual',     _ => [ new ManualTag() ])
            // todo: map as arbitrary tag if value === ''; look up ticket id
            .when(/issues?/,    _ => val.split(',').map(value => new IssueTag(value.trim())))
            .else(value           => [ new ArbitraryTag(value.trim()) ]);
    }
}

import { match } from 'tiny-types';

import { ArbitraryTag, IssueTag, ManualTag, Tag } from './';

/**
 * @package
 */
export class Tags {
    private static Pattern = /^@([\w-]+)[:\s]?(.*)/i;

    public static from(text: string): Tag[] {
        const [ , type, val ] = Tags.Pattern.exec(text);

        return match<Tag[]>(type.toLowerCase())
            .when('manual',     _ => [ new ManualTag() ])
            // todo: map as arbitrary tag if value === ''; look up ticket id
            .when(/^issues?$/,  _ => val.split(',').map(value => new IssueTag(value.trim())))
            .else(value           => [ new ArbitraryTag(value.trim()) ]);
    }
}

Support tags with "issues" in their name, i.e. "known_issues".
fix(core): Support tags with "issues" in their name, i.e. "known_issues".
