Skip to content

Commit

Permalink
feat(reviewers): adding reviewing data
Browse files Browse the repository at this point in the history
  • Loading branch information
Debaerdm committed Jan 12, 2021
1 parent 5b54a33 commit 7808f9e
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 21 deletions.
19 changes: 18 additions & 1 deletion src/components/Pullrequest/Pullrequest.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,23 @@
border: none;
background-color: transparent;
}
.counter {
display: inline-block;
width: 1.5rem;
height: 1.5rem;
border-radius: 50%;
text-align: center;
line-height: 1.5rem;
color: #fff;
font-size: 0.75rem;
vertical-align: middle;
font-weight: bold;
background-color: #20aa20;
}
</style>


<div class="pr">
<button
class="link"
Expand All @@ -127,7 +142,9 @@
</div>
<footer>
{#await Service.getReviews(pullRequest.provider, { pullRequest }) then reviews}
<div />
{#each Object.entries(reviews) as [key, value]}
<p>{key}: <span class="counter">{value}</span></p>
{/each}
{/await}
<Labels labels={pullRequest.labels} />
<button
Expand Down
2 changes: 1 addition & 1 deletion src/mappers/Mapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type From<T1, T2> = T1 & T2;

export abstract class Mapper<From, Result> {
public abstract to(data: From[] | From, params: any): Result[] | Result;
public abstract to(data: From[] | From, params?: any): Result[] | Result;
}
56 changes: 56 additions & 0 deletions src/mappers/Review.mapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {
AzureDevOpsReviewApiType,
AzureDevOpsVoteEnum,
GithubReviewApiType,
GithubVoteEnum,
} from 'models/api';
import type { ReviewType } from 'models/skizzle';
import { From, Mapper } from './Mapper';

export type ReviewMapperType = From<
AzureDevOpsReviewApiType,
GithubReviewApiType
>;

export class ReviewMapper extends Mapper<ReviewMapperType, ReviewType> {
public to(data: ReviewMapperType[]): ReviewType {
return data.reduce((acc, curr) => {
let key = curr.vote || curr.state;
let result = key.toString();

switch (key) {
case AzureDevOpsVoteEnum.Approved:
case GithubVoteEnum.Approved:
result = 'Validée';
break;
case AzureDevOpsVoteEnum.ApproveWithSuggestions:
result = 'Validée avec suggestion(s)';
break;
case GithubVoteEnum.Comment:
result = 'Commentaire(s)';
break;
case AzureDevOpsVoteEnum.WaitingForAuthor:
case GithubVoteEnum.Pending:
result = 'En attente';
break;
case AzureDevOpsVoteEnum.Rejected:
result = 'Refusée';
break;
case GithubVoteEnum.RequestChange:
result = 'Demande de changement';
break;
default:
result = "Pas d'avis";
break;
}

if (!acc[result]) {
acc[result] = 0;
}

acc[result] = acc[result] + 1;

return acc;
}, {} as ReviewType);
}
}
2 changes: 2 additions & 0 deletions src/mappers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ProfileMapper, ProfileMapperType } from './Profile.mapper';
import { ProjectMapper, ProjectMapperType } from './Project.mapper';
import { PullRequestMapper, PullRequestMapperType } from './PullRequest.mapper';
import { RepositoryMapper, RepositoryMapperType } from './Repository.mapper';
import { ReviewMapper } from './Review.mapper';
import { Mapper } from './Mapper';

export {
Expand All @@ -16,6 +17,7 @@ export {
ProjectMapper,
PullRequestMapper,
RepositoryMapper,
ReviewMapper,
Mapper,
};

Expand Down
6 changes: 4 additions & 2 deletions src/models/api/ReviewsApiType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ enum AzureDevOpsVoteEnum {

enum GithubVoteEnum {
Approved = 'APPROVED',
RequestChange = 'REQUEST_CHANGE',
RequestChange = 'CHANGES_REQUESTED',
Pending = 'PENDING',
Comment = 'COMMENT',
Comment = 'COMMENTED',
}

type AzureDevOpsReviewApiType = {
Expand All @@ -40,3 +40,5 @@ export type {
GithubReviewApiType,
GithubReviewsApiType,
};

export { AzureDevOpsVoteEnum, GithubVoteEnum };
3 changes: 3 additions & 0 deletions src/models/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
AzureDevOpsCommentApiEnum,
GithubUserEnum,
} from './CommentsApiType';
import { AzureDevOpsVoteEnum, GithubVoteEnum } from './ReviewsApiType';

export type {
IdentityType,
Expand Down Expand Up @@ -102,4 +103,6 @@ export {
AzureDevOpsCommentStatusApiEnum,
AzureDevOpsCommentApiEnum,
GithubUserEnum,
AzureDevOpsVoteEnum,
GithubVoteEnum,
};
6 changes: 3 additions & 3 deletions src/models/skizzle/ReviewType.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export type ReviewType = {
approved: boolean;
};
import type { Dictionary } from 'shared/utils';

export type ReviewType = Dictionary<number>;
9 changes: 3 additions & 6 deletions src/services/OAuthAzureDevOps.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ProjectMapper,
PullRequestMapper,
RepositoryMapper,
ReviewMapper,
} from 'mappers';
import {
AzureDevOpsCommentApiEnum,
Expand Down Expand Up @@ -185,9 +186,7 @@ export class OAuthAzureDevOpsService implements IService {
return mapper.to(comments, { provider: this.provider, organizationName });
}

public async getReviews({
pullRequest,
}: ServiceParams): Promise<ReviewType[]> {
public async getReviews({ pullRequest }: ServiceParams): Promise<ReviewType> {
const {
repositoryId,
pullRequestId,
Expand All @@ -202,8 +201,6 @@ export class OAuthAzureDevOpsService implements IService {
pullRequestId,
);

console.log(pullRequest.provider, { result });

return [];
return new ReviewMapper().to(result);
}
}
9 changes: 3 additions & 6 deletions src/services/OAuthGithub.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ProfileMapper,
PullRequestMapper,
RepositoryMapper,
ReviewMapper,
} from 'mappers';
import { GithubUserEnum } from 'models/api';
import type {
Expand Down Expand Up @@ -103,9 +104,7 @@ export class OAuthGithubService implements IService {
return mapper.to(comments, { provider: this.provider });
}

public async getReviews({
pullRequest,
}: ServiceParams): Promise<ReviewType[]> {
public async getReviews({ pullRequest }: ServiceParams): Promise<ReviewType> {
const { repositoryName, pullRequestId, owner } = pullRequest;

const result = await this.requester.getReviews(
Expand All @@ -114,8 +113,6 @@ export class OAuthGithubService implements IService {
pullRequestId,
);

console.log(pullRequest.provider, pullRequest.title, { result });

return [];
return new ReviewMapper().to(result);
}
}
4 changes: 2 additions & 2 deletions src/services/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface IService {
getRepositories(params: ServiceParams): Promise<RepositoryType[]>;
getPullRequests(params: ServiceParams): Promise<PullRequestType[]>;
getComments(params: ServiceParams): Promise<CommentType[]>;
getReviews(params: ServiceParams): Promise<ReviewType[]>;
getReviews(params: ServiceParams): Promise<ReviewType>;
}

export class Service {
Expand Down Expand Up @@ -117,7 +117,7 @@ export class Service {
public static async getReviews(
provider: ProviderEnum,
params: ServiceParams,
): Promise<ReviewType[]> {
): Promise<ReviewType> {
isFetchingData.set(true);
const result = await Service.INSTANCES[provider].getReviews(params);
isFetchingData.set(false);
Expand Down

0 comments on commit 7808f9e

Please sign in to comment.