Skip to content

Commit

Permalink
Merge pull request #379 from privacy-scaling-explorations/ref/github-…
Browse files Browse the repository at this point in the history
…repo-commits-validator

Update the `GITHUB_REPOSITORY_COMMITS` validator
  • Loading branch information
vplasencia authored Feb 8, 2024
2 parents 4a35d80 + 7527771 commit 86ceb46
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 39 deletions.
44 changes: 9 additions & 35 deletions apps/api/src/app/credentials/credentials.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,7 @@ describe("CredentialsService", () => {
providerName: "github"
})

await credentialsService.addMember(
"code",
_stateId,
undefined,
undefined
)
await credentialsService.addMember(_stateId, "code")

const fun = credentialsService.setOAuthState({
groupId,
Expand All @@ -163,12 +158,7 @@ describe("CredentialsService", () => {

describe("# addMember", () => {
it("Should throw an error if the OAuth does not exist", async () => {
const fun = credentialsService.addMember(
"code",
"123",
undefined,
undefined
)
const fun = credentialsService.addMember("123", "code")

await expect(fun).rejects.toThrow(`OAuth state does not exist`)
})
Expand All @@ -181,10 +171,8 @@ describe("CredentialsService", () => {
})

const clientRedirectUri = await credentialsService.addMember(
"code",
_stateId,
undefined,
undefined
"code"
)

expect(clientRedirectUri).toBeUndefined()
Expand Down Expand Up @@ -230,19 +218,15 @@ describe("CredentialsService", () => {
)

const clientRedirectUri1 = await credentialsService.addMember(
"code",
_stateId1,
undefined,
undefined
"code"
)

expect(clientRedirectUri1).toBeUndefined()

const clientRedirectUri2 = await credentialsService.addMember(
"code",
_stateId2,
undefined,
undefined
"code"
)

expect(clientRedirectUri2).toBeUndefined()
Expand All @@ -268,12 +252,7 @@ describe("CredentialsService", () => {
providerName: "github"
})

const fun = credentialsService.addMember(
"code",
_stateId,
undefined,
undefined
)
const fun = credentialsService.addMember(_stateId, "code")

await expect(fun).rejects.toThrow(
`OAuth account does not match criteria`
Expand All @@ -297,12 +276,7 @@ describe("CredentialsService", () => {
providerName: "github"
})

const fun = credentialsService.addMember(
"code",
_stateId,
undefined,
undefined
)
const fun = credentialsService.addMember(_stateId, "code")

await expect(fun).rejects.toThrow(
`OAuth account has already joined the group`
Expand Down Expand Up @@ -335,8 +309,8 @@ describe("CredentialsService", () => {
})

const clientRedirectUri = await credentialsService.addMember(
"",
_stateId,
undefined,
"0x",
"sepolia"
)
Expand All @@ -352,8 +326,8 @@ describe("CredentialsService", () => {
})

const clientRedirectUri = await credentialsService.addMember(
"",
_stateId,
undefined,
"0x1",
"sepolia",
"1234"
Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/app/credentials/credentials.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ export class CredentialsService {
* @returns Redirect URI
*/
async addMember(
oAuthCode: string,
oAuthState: string,
address: string,
network: string,
oAuthCode?: string,
address?: string,
network?: string,
blockNumber?: string
): Promise<string> {
if (!this.oAuthState.has(oAuthState)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ const validator: Validator = {
if ("profile" in context && context.utils) {
let allCommits = []

const [repoOwner, repoName] = criteria.repository.split("/", 2)

for (let i = 0; allCommits.length % 100 === 0; i += 1) {
// eslint-disable-next-line no-await-in-loop
const commits = await context.utils.api(
`repos/${context.profile.login}/${criteria.repository}/commits?author=${context.profile.login}&per_page=100&page=${i}`
`repos/${repoOwner}/${repoName}/commits?author=${context.profile.login}&per_page=100&page=${i}`
)

if (commits.length === 0) {
Expand Down

0 comments on commit 86ceb46

Please sign in to comment.