Skip to content

Commit

Permalink
Merge pull request #10 from keyoke/keyoke/features
Browse files Browse the repository at this point in the history
Keyoke/features
  • Loading branch information
keyoke authored Sep 13, 2021
2 parents f10eeb3 + cd3411c commit 66eb06c
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/block-duplicate-observer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as SDK from "azure-devops-extension-sdk";
import { CommonServiceIds, getClient, IProjectInfo, IProjectPageService, ILocationService } from "azure-devops-extension-api";
import { IWorkItemFormService, WorkItemQueryResult, WorkItemReference, WorkItemTrackingRestClient, WorkItemTrackingServiceIds } from "azure-devops-extension-api/WorkItemTracking";
import { IWorkItemFormService, WorkItemQueryResult, WorkItemReference, WorkItemTrackingRestClient, WorkItemTrackingServiceIds, IWorkItemNotificationListener } from "azure-devops-extension-api/WorkItemTracking";
import * as stringSimilarity from "string-similarity";
import * as striptags from "striptags";

class duplicateObserver {
class duplicateObserver implements IWorkItemNotificationListener {
_similarityIndex : number = 0.8;
_workItemFormService: IWorkItemFormService;
_locationService: ILocationService;
Expand Down Expand Up @@ -170,9 +170,11 @@ class duplicateObserver {

// when changes are made wait a bit before triggering the validation
if (this._timeout) clearTimeout(this._timeout);
console.log(`Setting timer for triggering validation.`);
this._timeout = setTimeout(() => {
console.log(`Triggering validation.`);
this.validateWorkItem();
}, 1000);
}, 3000);
}

// Called when a new work item is being loaded in the UI
Expand Down Expand Up @@ -203,22 +205,33 @@ class duplicateObserver {
}
}

SDK.init(<SDK.IExtensionInitOptions>{ explicitNotifyLoaded: true });
SDK.ready().then(async () => {
const main = async () =>{
await SDK.init(<SDK.IExtensionInitOptions>{
explicitNotifyLoaded: true
});

// wait until we are ready
await SDK.ready();

// soft-cor.block-duplicate-work-items.block-duplicate-observer or block-duplicate-observer ??
const contributionId : string = SDK.getContributionId();
// Get The ADO Services which we will need later
const locationService: ILocationService = await SDK.getService(CommonServiceIds.LocationService);
const projectService: IProjectPageService = await SDK.getService<IProjectPageService>(CommonServiceIds.ProjectPageService);
const workItemFormService: IWorkItemFormService = await SDK.getService<IWorkItemFormService>(WorkItemTrackingServiceIds.WorkItemFormService);
const observer: duplicateObserver = new duplicateObserver(workItemFormService, locationService, projectService);

// soft-cor.block-duplicate-work-items.block-duplicate-observer or block-duplicate-observer ??
let contributionId : string = SDK.getContributionId();
console.log(contributionId);

// Register our contribution
SDK.register(contributionId, () => {
// Get the Work Item Form Service
return observer;
});

// notify we are loaded
await SDK.notifyLoadSucceeded();
});
};

// execute our entrypoint
main().catch((error) => { console.error(error); });

0 comments on commit 66eb06c

Please sign in to comment.