Skip to content

Commit

Permalink
Surface Associated Pull Request Information
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu committed Aug 27, 2024
1 parent d039913 commit c25c828
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using APIViewWeb.Managers.Interfaces;
using APIViewWeb.Managers;
using System.Collections.Generic;
using APIViewWeb.Models;
using System.Linq;

namespace APIViewWeb.LeanControllers
{
Expand All @@ -17,17 +19,17 @@ public class APIRevisionsController : BaseApiController
private readonly IAPIRevisionsManager _apiRevisionsManager;
private readonly IReviewManager _reviewManager;
private readonly INotificationManager _notificationManager;

private readonly IPullRequestManager _pullRequestManager;

public APIRevisionsController(ILogger<APIRevisionsController> logger,
IReviewManager reviewManager,
IAPIRevisionsManager apiRevisionsManager,
INotificationManager notificationManager)
IReviewManager reviewManager, IPullRequestManager pullRequestManager,
IAPIRevisionsManager apiRevisionsManager, INotificationManager notificationManager)
{
_logger = logger;
_apiRevisionsManager = apiRevisionsManager;
_reviewManager = reviewManager;
_notificationManager = notificationManager;
_pullRequestManager = pullRequestManager;
}

/// <summary>
Expand Down
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
using APIViewWeb.Hubs;
using Microsoft.AspNetCore.SignalR;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using System.Collections.Generic;
using Microsoft.Extensions.Caching.Memory;
using System;

namespace APIViewWeb.LeanControllers
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@
</ul>
</app-page-options-section>

<app-page-options-section *ngIf="associatedPullRequests.length > 0" sectionName="Associated Pull Requests">
<ul class="list-group">
<li class="list-group-item" *ngFor="let pullRequest of associatedPullRequests">
<a href="https://github.com/{{pullRequest.repoName}}/pull/{{pullRequest.pullRequestNumber}}" target="_blank">{{pullRequest.repoName}}/{{pullRequest.pullRequestNumber}}</a>
</li>
</ul>
</app-page-options-section>

<app-page-options-section *ngIf="pullRequestsOfAssociatedAPIRevisions.length > 0" sectionName="Associated APIRevisions" [collapsedInput]="true">
<ul class="list-group">
<li class="list-group-item" *ngFor="let pullRequest of associatedPullRequests">
<a [href]="getPullRequestsOfAssociatedAPIRevisionsUrl(pullRequest)" target="_blank">{{pullRequest.language}}/{{pullRequest.packageName}}</a>
</li>
</ul>
</app-page-options-section>

<app-page-options-section sectionName="Page Settings">
<ul class="list-group">
<li class="list-group-item">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { ConfigService } from 'src/app/_services/config/config.service';
import { RevisionsService } from 'src/app/_services/revisions/revisions.service';
import { take } from 'rxjs';
import { UserProfile } from 'src/app/_models/userProfile';
import { PullRequestsService } from 'src/app/_services/pull-requests/pull-requests.service';
import { PullRequestModel } from 'src/app/_models/pullRequestModel';

@Component({
selector: 'app-review-page-options',
Expand Down Expand Up @@ -65,6 +67,9 @@ export class ReviewPageOptionsComponent implements OnInit, OnChanges{
reviewIsApproved: boolean | undefined = undefined;
reviewApprover: string = 'azure-sdk';

associatedPullRequests : PullRequestModel[] = [];
pullRequestsOfAssociatedAPIRevisions : PullRequestModel[] = [];

//Approvers Options
selectedApprovers: string[] = [];

Expand All @@ -87,7 +92,7 @@ export class ReviewPageOptionsComponent implements OnInit, OnChanges{
private configService: ConfigService,
private route: ActivatedRoute,
private router: Router,
private apiRevisionsService: RevisionsService) { }
private apiRevisionsService: RevisionsService, private pullRequestService: PullRequestsService) { }

ngOnInit() {
this.setSelectedDiffStyle();
Expand All @@ -111,6 +116,7 @@ export class ReviewPageOptionsComponent implements OnInit, OnChanges{
this.markedAsViewSwitch = this.activeAPIRevision!.viewedBy.includes(this.userProfile?.userName!);
this.selectedApprovers = this.activeAPIRevision!.assignedReviewers.map(reviewer => reviewer.assingedTo);
this.setAPIRevisionApprovalStates();
this.setPullRequestsInfo();
}

if (changes['diffAPIRevision']) {
Expand Down Expand Up @@ -262,6 +268,26 @@ export class ReviewPageOptionsComponent implements OnInit, OnChanges{
}
}

setPullRequestsInfo() {
if (this.activeAPIRevision?.apiRevisionType === 'pullRequest') {
this.pullRequestService.getAssociatedPullRequests(this.activeAPIRevision.reviewId, this.activeAPIRevision.id).pipe(take(1)).subscribe({
next: (response: PullRequestModel[]) => {
this.associatedPullRequests = response;
}
});

this.pullRequestService.getPullRequestsOfAssociatedAPIRevisions(this.activeAPIRevision.reviewId, this.activeAPIRevision.id).pipe(take(1)).subscribe({
next: (response: PullRequestModel[]) => {
for (const pr of response) {
if (pr.reviewId != this.activeAPIRevision?.reviewId) {
this.pullRequestsOfAssociatedAPIRevisions.push(pr);
}
}
}
});
}
}

handleAPIRevisionApprovalAction() {
if (!this.activeAPIRevisionIsApprovedByCurrentUser && (this.hasActiveConversation || this.hasFatalDiagnostics)) {
this.showAPIRevisionApprovalModal = true;
Expand All @@ -278,6 +304,10 @@ export class ReviewPageOptionsComponent implements OnInit, OnChanges{
this.apiRevisionApprovalEmitter.emit(true);
}

getPullRequestsOfAssociatedAPIRevisionsUrl(pr: PullRequestModel) {
return `${window.location.origin}/review/${pr.reviewId}?activeApiRevisionId=${pr.apiRevisionId}`;
}

/**
* This updates the page route without triggering a state update (i.e the code lines are not rebuilt, only the URI is updated)
* This is specifically to remove the nId query parameter from the URI
Expand Down
44 changes: 44 additions & 0 deletions src/dotnet/APIView/ClientSPA/src/app/_models/pullRequestModel.ts
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { PullRequestsService } from './pull-requests.service';

describe('PullRequestsService', () => {
let service: PullRequestsService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(PullRequestsService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
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 });
}
}

0 comments on commit c25c828

Please sign in to comment.