From 1f0a978ad2b8e5bcd57eef37baca93e00fd6b20b Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 18 Feb 2019 19:56:13 +0800 Subject: Add get pat api. --- .../todo-list-page/todo-list-page.component.css | 4 +++ Timeline/ClientApp/src/app/todo-list.service.ts | 39 ++++++++++++++-------- 2 files changed, 30 insertions(+), 13 deletions(-) (limited to 'Timeline/ClientApp/src') diff --git a/Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.css b/Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.css index 43bd26d8..c17267c5 100644 --- a/Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.css +++ b/Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.css @@ -6,3 +6,7 @@ width: 1.2rem; height: 1.2rem; } + +mat-list-item { + margin: 10px; +} diff --git a/Timeline/ClientApp/src/app/todo-list.service.ts b/Timeline/ClientApp/src/app/todo-list.service.ts index b1bc5ff3..238919d3 100644 --- a/Timeline/ClientApp/src/app/todo-list.service.ts +++ b/Timeline/ClientApp/src/app/todo-list.service.ts @@ -28,28 +28,41 @@ export interface WorkItem { export class TodoListService { private username = 'crupest'; - private pat = 'ehnmegogmk6r7qlkpy6zdl2hnfl6ntqbvggzxvvgp4a5vhr7lmnq'; private organization = 'crupest-web'; private project = 'Timeline'; private fieldId = 'System.Title'; - private headers: HttpHeaders; - constructor(private client: HttpClient) { - this.headers = new HttpHeaders({ - 'Accept': 'application/json', - 'Authorization': `Basic ${btoa(this.username + ':' + this.pat)}` + constructor(private client: HttpClient) { } + + private getAzureDevOpsPat(): Observable { + return this.client.get('/api/TodoList/AzureDevOpsPat', { + headers: { + 'Accept': 'text/plain' + }, + responseType: 'text' }); } getWorkItemList(): Observable { - return this.client.post(`https://dev.azure.com/${this.organization}/${this.project}/_apis/wit/wiql?api-version=5.0`, { - query: 'SELECT [System.Id] FROM workitems WHERE [System.TeamProject] = @project' - }, { headers: this.headers }).pipe( - switchMap(result => result.workItems), - concatMap(result => this.client.get(result.url, {headers: this.headers})), - map(result => { id: result.id, title: result.fields[this.fieldId] }), - toArray() + return this.getAzureDevOpsPat().pipe( + switchMap( + pat => { + const headers = new HttpHeaders({ + 'Accept': 'application/json', + 'Authorization': `Basic ${btoa(this.username + ':' + pat)}` + }); + return this.client.post( + `https://dev.azure.com/${this.organization}/${this.project}/_apis/wit/wiql?api-version=5.0`, { + query: 'SELECT [System.Id] FROM workitems WHERE [System.TeamProject] = @project' + }, { headers: headers }).pipe( + switchMap(result => result.workItems), + concatMap(result => this.client.get(result.url, { headers: headers })), + map(result => { id: result.id, title: result.fields[this.fieldId] }), + toArray() + ); + } + ) ); } } -- cgit v1.2.3