feat: add read-only GitHub App access alongside OAuth

This commit is contained in:
Thomas Durieux committed 2026-09-09 22:08:12 +02:00
1 parent e5c44845f0
commit a60ad6a921
49 files changed
+1754 -139

No files matched your search

@@ -1,3 +1,4 @@
import { repositoryAccessSchema } from "../repository-access.schema";
import { Schema } from "mongoose";
const AnonymizedPullRequestSchema = new Schema({
@@ -15,6 +16,7 @@ const AnonymizedPullRequestSchema = new Schema({
lastView: Date,
pageView: Number,
owner: { type: Schema.Types.ObjectId, index: true },
githubAccess: { type: repositoryAccessSchema, default: undefined },
conference: String,
source: {
pullRequestId: Number,
@@ -1,3 +1,4 @@
import { RepositoryAccess } from "../../repository-access.types";
import { Document, Model } from "mongoose";
import { RepositoryStatus } from "../../types";
@@ -13,6 +14,7 @@ export interface IAnonymizedPullRequest {
accessToken?: string;
};
owner: string;
githubAccess?: RepositoryAccess;
conference: string;
options: {
terms: string[];
@@ -1,3 +1,4 @@
import { repositoryAccessSchema } from "../repository-access.schema";
import { Schema } from "mongoose";
const AnonymizedRepositorySchema = new Schema({
@@ -31,6 +32,7 @@ const AnonymizedRepositorySchema = new Schema({
addedAt: { type: Date, default: Date.now },
},
],
githubAccess: { type: repositoryAccessSchema, default: undefined },
conference: String,
source: {
type: { type: String },
@@ -1,3 +1,4 @@
import { RepositoryAccess } from "../../repository-access.types";
import { Document, Model } from "mongoose";
import { RepositoryStatus } from "../../types";
@@ -20,6 +21,7 @@ export interface IAnonymizedRepository {
accessToken?: string;
};
owner: string;
githubAccess?: RepositoryAccess;
coauthors?: {
username: string;
githubId?: string;
@@ -6,6 +6,13 @@ export interface ICredential {
provider: string;
encryptedToken: EncryptedToken;
updatedAt: Date;
encryptedRefreshToken?: EncryptedToken;
expiresAt?: Date;
refreshExpiresAt?: Date;
refreshLock?: string;
refreshLockUntil?: Date;
revision?: string;
revoked?: boolean;
}
const envelope = new Schema({
version: { type: Number, required: true, enum: [1] },
@@ -16,9 +23,16 @@ const envelope = new Schema({
}, { _id: false });
const schema = new Schema<ICredential>({
ownerId: { type: Schema.Types.ObjectId, required: true, ref: "user" },
provider: { type: String, required: true, enum: ["github"] },
provider: { type: String, required: true, enum: ["github", "github-app-user"] },
encryptedToken: { type: envelope, required: true, select: false },
updatedAt: { type: Date, required: true },
encryptedRefreshToken: { type: envelope, select: false },
expiresAt: Date,
refreshExpiresAt: Date,
refreshLock: { type: String, select: false },
refreshLockUntil: Date,
revision: String,
revoked: Boolean,
}, { collection: "credentials" });
schema.index({ ownerId: 1, provider: 1 }, { unique: true });
export default model<ICredential>("Credential", schema);
+15
View File
@@ -0,0 +1,15 @@
import { model, Schema } from "mongoose";
const schema = new Schema({
appId: { type: String, required: true },
installationId: { type: Number, required: true },
accountId: Number,
accountLogin: String,
accountType: String,
blocked: { type: Boolean, default: false },
reconciliationPending: { type: Boolean, default: false },
checkedAt: Date,
revision: String,
});
schema.index({ appId: 1, installationId: 1 }, { unique: true });
export default model("GitHubInstallation", schema);
@@ -0,0 +1,8 @@
import { Schema } from "mongoose";
export const repositoryAccessSchema = new Schema({
kind: { type: String, enum: ["oauth", "github-app"], required: true },
repositoryId: Number,
installationId: Number,
revision: { type: String, required: true },
}, { _id: false });