Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
fix: parse hostname
Browse files Browse the repository at this point in the history
Parse hostname from given input. This allows for either real hostnames or urls to select a hostname from.

Closes #208
  • Loading branch information
KnisterPeter committed Oct 2, 2017
1 parent 52eeeff commit 2e78e01
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/commands/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { component, inject } from 'tsdi';
import * as vscode from 'vscode';

import { Command } from '../command';
import { getHostname } from '../helper';
import { WorkflowManager, Tokens } from '../workflow-manager';

@component({eager: true})
Expand Down Expand Up @@ -61,7 +62,7 @@ export class SetGithubEnterpriseToken extends Command {
});
if (tokenInput) {
const tokens = this.context.globalState.get<Tokens>('tokens', {});
tokens[hostInput] = {
tokens[getHostname(hostInput)] = {
token: tokenInput,
provider: 'github'
};
Expand Down Expand Up @@ -98,7 +99,7 @@ export class SetGitLabToken extends Command {
});
if (tokenInput) {
const tokens = this.context.globalState.get<Tokens>('tokens', {});
tokens[hostInput] = {
tokens[getHostname(hostInput)] = {
token: tokenInput,
provider: 'gitlab'
};
Expand Down
8 changes: 8 additions & 0 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ export function getConfiguration(): Configuration {
}
return config;
}

export function getHostname(input: string): string {
const match = input.match(/.*?(?::\/\/|@)([^:\/]+)/);
if (match) {
return match[1];
}
return input;
}

0 comments on commit 2e78e01

Please sign in to comment.