feat: add support for pull requests (#156)

This commit is contained in:
Thomas Durieux
2023-01-22 12:54:14 +01:00
committed by GitHub
parent 3091b13776
commit 73e46f926f
23 changed files with 2479 additions and 28 deletions

View File

@@ -0,0 +1,14 @@
import { model } from "mongoose";
import AnonymizedPullRequestSchema from "./anonymizedPullRequests.schema";
import {
IAnonymizedPullRequestDocument,
IAnonymizedPullRequestModel,
} from "./anonymizedPullRequests.types";
const AnonymizedPullRequestModel = model<IAnonymizedPullRequestDocument>(
"AnonymizedPullRequest",
AnonymizedPullRequestSchema
) as IAnonymizedPullRequestModel;
export default AnonymizedPullRequestModel;

View File

@@ -0,0 +1,66 @@
import { Schema } from "mongoose";
const AnonymizedPullRequestSchema = new Schema({
pullRequestId: {
type: String,
index: { unique: true },
},
status: {
type: String,
default: "preparing",
},
statusDate: Date,
statusMessage: String,
anonymizeDate: Date,
lastView: Date,
pageView: Number,
owner: Schema.Types.ObjectId,
conference: String,
source: {
pullRequestId: Number,
repositoryFullName: String,
accessToken: String,
},
options: {
terms: [String],
expirationMode: { type: String },
expirationDate: Date,
update: Boolean,
image: Boolean,
link: Boolean,
title: Boolean,
body: Boolean,
comments: Boolean,
diff: Boolean,
origin: Boolean,
username: Boolean,
date: Boolean,
},
dateOfEntry: {
type: Date,
default: new Date(),
},
pullRequest: {
diff: String,
title: String,
body: String,
creationDate: Date,
updatedDate: Date,
draft: Boolean,
merged: Boolean,
mergedDate: Date,
state: String,
baseRepositoryFullName: String,
headRepositoryFullName: String,
comments: [
{
body: String,
creationDate: Date,
updatedDate: Date,
author: String,
},
],
},
});
export default AnonymizedPullRequestSchema;

View File

@@ -0,0 +1,61 @@
import { Document, Model } from "mongoose";
import { RepositoryStatus } from "../../types";
export interface IAnonymizedPullRequest {
pullRequestId: string;
status?: RepositoryStatus;
statusMessage?: string;
statusDate: Date;
anonymizeDate: Date;
source: {
pullRequestId: number;
repositoryFullName?: string;
accessToken?: string;
};
owner: string;
conference: string;
options: {
terms: string[];
expirationMode: "never" | "redirect" | "remove";
expirationDate?: Date;
update: boolean;
image: boolean;
link: boolean;
title: boolean;
body: boolean;
comments: boolean;
diff: boolean;
origin: boolean;
username: boolean;
date: boolean;
};
pageView: number;
lastView: Date;
pullRequest: {
diff: string;
title: string;
body: string;
creationDate: Date;
updatedDate: Date;
draft?: boolean;
merged?: boolean;
mergedDate?: Date;
state?: string;
baseRepositoryFullName?: string;
headRepositoryFullName?: string;
comments?: {
body: string;
creationDate: Date;
updatedDate: Date;
author: string;
}[];
};
}
export interface IAnonymizedPullRequestDocument
extends IAnonymizedPullRequest,
Document {
setLastUpdated: (this: IAnonymizedPullRequestDocument) => Promise<void>;
}
export interface IAnonymizedPullRequestModel
extends Model<IAnonymizedPullRequestDocument> {}

View File

@@ -3,6 +3,8 @@ import Repository from "../Repository";
import config from "../../config";
import AnonymizedRepositoryModel from "./anonymizedRepositories/anonymizedRepositories.model";
import AnonymousError from "../AnonymousError";
import AnonymizedPullRequestModel from "./anonymizedPullRequests/anonymizedPullRequests.model";
import PullRequest from "../PullRequest";
const MONGO_URL = `mongodb://${config.DB_USERNAME}:${config.DB_PASSWORD}@${config.DB_HOSTNAME}:27017/`;
@@ -17,7 +19,7 @@ export async function connect() {
}
export async function getRepository(repoId: string) {
if (!repoId || repoId == 'undefined') {
if (!repoId || repoId == "undefined") {
throw new AnonymousError("repo_not_found", {
object: repoId,
httpStatus: 404,
@@ -31,3 +33,20 @@ export async function getRepository(repoId: string) {
});
return new Repository(data);
}
export async function getPullRequest(pullRequestId: string) {
if (!pullRequestId || pullRequestId == "undefined") {
throw new AnonymousError("pull_request_not_found", {
object: pullRequestId,
httpStatus: 404,
});
}
const data = await AnonymizedPullRequestModel.findOne({
pullRequestId,
});
if (!data)
throw new AnonymousError("pull_request_not_found", {
object: pullRequestId,
httpStatus: 404,
});
return new PullRequest(data);
}