Skip to content
This repository has been archived by the owner on Nov 18, 2023. It is now read-only.

duplicate check for github usernames in registry.yaml #124

Merged
merged 7 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/ci-script-change.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
on:
push:
paths:
- ci/**
pull_request:
paths:
- ci/**

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: npm install
- name: Unit Tests for CI
run: npm run test-ci
5 changes: 5 additions & 0 deletions ci/check-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const path = require('path');

const crypto = require('crypto');

const checkDuplicateGithubUserNames = require('./registry/duplicate-check-ghusername')
// Create a set to store the hashes of the pageJsonContent strings
const hashedContents = new Set();

Expand All @@ -22,6 +23,10 @@ async function validateRegistry() {
if (!registry || !registry.users) {
throw new Error('Invalid registry format. The "users" key is missing.');
}

// Verify that each github username has only one prefix/domain
checkDuplicateGithubUserNames(registry.users)

// Validate each user
for (const username in registry.users) {
const user = registry.users[username];
Expand Down
12 changes: 12 additions & 0 deletions ci/registry/duplicate-check-ghusername.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
async function checkDuplicateGithubUserNames(users){
// Verify that each github username has only one prefix/domain
const ghUsernames = Object.values(users).map(user => user.github_username);
const duplicatedGhUsernames = ghUsernames.filter((ghUsername, index) => ghUsernames.indexOf(ghUsername) != index)

if (duplicatedGhUsernames.length > 0) {
console.log("duplicated github usernames:",duplicatedGhUsernames.join(","))
throw new Error('There are duplicated github usernames in the array');
}
}

module.exports = checkDuplicateGithubUserNames
21 changes: 21 additions & 0 deletions ci/registry/duplicate-check-ghusername.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const checkDuplicateGithubUserNames = require("./duplicate-check-ghusername");



test("correct scenario, 2 different github usernames, 2 different domains", async () => {
await expect(checkDuplicateGithubUserNames({
"alice": {"github_username": "alice-gh"},
"bob": {"github_username": "bob-gh"},
})).resolves.toBeUndefined() // no error
});


test("wrong scenario, 2 same github username, 2 different domains", async () => {
expect.assertions(1);
await expect(checkDuplicateGithubUserNames({
"alice": {"github_username": "alice-gh"},
"bob": {"github_username": "alice-gh"},
})).rejects.toThrow('There are duplicated github usernames in the array')
});


Loading