-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Surface Associated Pull Request Information
- Loading branch information
1 parent
d039913
commit 97c2f28
Showing
8 changed files
with
205 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/dotnet/APIView/APIViewWeb/LeanControllers/PullRequestsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using APIViewWeb.Extensions; | ||
using APIViewWeb.Helpers; | ||
using APIViewWeb.Managers; | ||
using APIViewWeb.Models; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace APIViewWeb.LeanControllers | ||
{ | ||
public class PullRequestsController : BaseApiController | ||
{ | ||
private readonly ILogger<PullRequestsController> _logger; | ||
private readonly IPullRequestManager _pullRequestManager; | ||
|
||
public PullRequestsController(ILogger<PullRequestsController> logger, IPullRequestManager pullRequestManager) | ||
{ | ||
_logger = logger; | ||
_pullRequestManager = pullRequestManager; | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves Pull Requests associated with an API Revision | ||
/// </summary> | ||
/// <param name="reviewId"></param> | ||
/// <param name="apiRevisionId"></param> | ||
/// <returns></returns> | ||
[HttpGet("{reviewId}/{apiRevisionId}", Name = "GetAssociatedPullRequests")] | ||
public async Task<ActionResult<IEnumerable<PullRequestModel>>> GetAssociatedPullRequestsAsync(string reviewId, string apiRevisionId) | ||
{ | ||
var results = await _pullRequestManager.GetPullRequestsModelAsync(reviewId, apiRevisionId); | ||
return new LeanJsonResult(results, StatusCodes.Status200OK); | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves Pull Requests of all API Revisions associated with a Review | ||
/// </summary> | ||
/// <param name="reviewId"></param> | ||
/// <param name="apiRevisionId"></param> | ||
/// <returns></returns> | ||
[HttpGet("{reviewId}/{apiRevisionId}/prsofassociatedapirevisions", Name = "GetPRsOfAssociatedAPIRevisions")] | ||
public async Task<ActionResult<IEnumerable<PullRequestModel>>> GetPRsOfAssociatedAPIRevisionsAsync(string reviewId, string apiRevisionId) | ||
{ | ||
IEnumerable<PullRequestModel> results = new List<PullRequestModel>(); | ||
var creatingPR = (await _pullRequestManager.GetPullRequestsModelAsync(reviewId, apiRevisionId)).FirstOrDefault(); | ||
if (creatingPR != null) | ||
{ | ||
results = await _pullRequestManager.GetPullRequestsModelAsync(creatingPR.PullRequestNumber, creatingPR.RepoName); | ||
} | ||
return new LeanJsonResult(results, StatusCodes.Status200OK); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/dotnet/APIView/ClientSPA/src/app/_models/pullRequestModel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
export class PullRequestModel { | ||
id: string; | ||
reviewId: string; | ||
apiRevisionId: string; | ||
baselineApiRevisionId: string; | ||
pullRequestNumber: number; | ||
commits: string[] = []; | ||
repoName: string; | ||
filePath: string; | ||
isOpen: boolean = true; | ||
createdBy: string; | ||
packageName: string; | ||
language: string; | ||
assignee: string; | ||
isDeleted: boolean; | ||
|
||
constructor( | ||
id: string, | ||
reviewId: string, | ||
apiRevisionId: string, | ||
baselineApiRevisionId: string, | ||
pullRequestNumber: number, | ||
repoName: string, | ||
filePath: string, | ||
createdBy: string, | ||
packageName: string, | ||
language: string, | ||
assignee: string, | ||
isDeleted: boolean | ||
) { | ||
this.id = id; | ||
this.reviewId = reviewId; | ||
this.apiRevisionId = apiRevisionId; | ||
this.baselineApiRevisionId = baselineApiRevisionId; | ||
this.pullRequestNumber = pullRequestNumber; | ||
this.repoName = repoName; | ||
this.filePath = filePath; | ||
this.createdBy = createdBy; | ||
this.packageName = packageName; | ||
this.language = language; | ||
this.assignee = assignee; | ||
this.isDeleted = isDeleted; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/dotnet/APIView/ClientSPA/src/app/_services/pull-requests/pull-requests.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { PullRequestsService } from './pull-requests.service'; | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { ConfigService } from '../config/config.service'; | ||
import { of } from 'rxjs'; | ||
|
||
describe('PullRequestsService', () => { | ||
let service: PullRequestsService; | ||
|
||
beforeEach(() => { | ||
const configServiceMock = { | ||
apiUrl: 'http://localhost:5000/', | ||
loadConfig: () => of({ apiUrl: 'http://localhost:5000/' }) | ||
}; | ||
|
||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule], | ||
providers: [ | ||
PullRequestsService, | ||
{ provide: ConfigService, useValue: configServiceMock } | ||
] | ||
}); | ||
service = TestBed.inject(PullRequestsService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
src/dotnet/APIView/ClientSPA/src/app/_services/pull-requests/pull-requests.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { ConfigService } from '../config/config.service'; | ||
import { PullRequestModel } from 'src/app/_models/pullRequestModel'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class PullRequestsService { | ||
baseUrl : string = this.configService.apiUrl + "pullrequests"; | ||
|
||
constructor(private http: HttpClient, private configService: ConfigService) { } | ||
|
||
getAssociatedPullRequests(reviewId: string, apiRevisionId : string) : Observable<PullRequestModel[]> { | ||
return this.http.get<PullRequestModel[]>(this.baseUrl + `/${reviewId}/${apiRevisionId}`, { withCredentials: true }); | ||
} | ||
|
||
getPullRequestsOfAssociatedAPIRevisions(reviewId: string, apiRevisionId : string) : Observable<PullRequestModel[]> { | ||
return this.http.get<PullRequestModel[]>(this.baseUrl + `/${reviewId}/${apiRevisionId}/prsofassociatedapirevisions`, { withCredentials: true }); | ||
} | ||
} |