Merge pull request #2665 from alecmerdler/fix-trigger-build-source

Fixed Build Source in Custom Git Trigger
This commit is contained in:
Alec Merdler 2017-05-24 15:18:47 -07:00 committed by GitHub
commit c61e212ecd
2 changed files with 19 additions and 1 deletions

View file

@ -47,6 +47,23 @@ describe("ManageTriggerComponent", () => {
});
});
describe("checkBuildSource", () => {
it("sets selected repository full name if given build source matches regex pattern", () => {
const buildSource: string = "git@somegithost.net:user/repo.git";
component.checkBuildSource(buildSource);
expect(component.local.selectedRepository.full_name).toEqual(buildSource);
});
it("sets selected repository full name to null if given build source does not match regex pattern", () => {
const buildSource: string = "a_randomstring";
component.checkBuildSource(buildSource);
expect(component.local.selectedRepository.full_name).toBe(null);
});
});
describe("getTriggerIcon", () => {
beforeEach(() => {

View file

@ -70,8 +70,9 @@ export class ManageTriggerComponent implements OnInit {
}
public checkBuildSource(buildSource: string): void {
const buildSourceRegExp = new RegExp(/(((http|https):\/\/)(.+)|\w+@(.+):(.+))/, 'i');
try {
this.local.selectedRepository.full_name = buildSource.split(':')[1].replace('.git', '');
this.local.selectedRepository.full_name = buildSourceRegExp.test(buildSource) ? buildSource : null;
} catch (error) {
this.local.selectedRepository.full_name = null;
}