Skip to content

Commit

Permalink
Use Intl.ListFormat instead of listify
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Nov 2, 2023
1 parent de1cb2a commit ec0caba
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
22 changes: 22 additions & 0 deletions __tests__/__snapshots__/get-user-status.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,28 @@ exports[`No data 2`] = `
}
`;

exports[`Three entities 1`] = `
{
"context": "Participation",
"description": "@johndoetw participates on behalf of a non-workstream entity",
"isNothing": false,
"longDescription": "@johndoetw is part of the contoso1, contoso2, and contoso3 GitHub organizations, but they all do not participate in the Console workstream. Please have the contact for those organizations update their participation agreement.",
"state": "pending",
"target_url": "https://participate.whatwg.org/agreement-status?user=johndoetw&repo=console",
}
`;

exports[`Three entities 2`] = `
{
"context": "Participation",
"description": "@johndoetw participates on behalf of a non-workstream entity",
"isNothing": false,
"longDescription": "@johndoetw is part of the contoso1, contoso2, and contoso3 GitHub organizations, but they all do not participate in the Console workstream. Please have the contact for those organizations update their participation agreement.",
"state": "pending",
"target_url": "https://participate.whatwg.org/agreement-status?user=johndoetw&repo=console&pull=120",
}
`;

exports[`Via entity, participating in all workstreams, unverified 1`] = `
{
"context": "Participation",
Expand Down
10 changes: 10 additions & 0 deletions __tests__/get-user-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ for (const pull of [undefined, "120"]) {
expect(await getUserStatus("johndoetw", "console", pull)).toMatchSnapshot();
});

test("Three entities", async () => {
mockOrgMemberships.set("johndoetw", ["contoso1", "contoso2", "contoso3"]);
mockData.set("entity", [
entityData(["xhr"], true, { name: "Contoso 1", org: "contoso1" }),
entityData(["xhr"], true, { name: "Contoso 2", org: "contoso2" }),
entityData(["xhr"], true, { name: "Contoso 3", org: "contoso3" })
]);
expect(await getUserStatus("johndoetw", "console", pull)).toMatchSnapshot();
});


test("Entities exist, but the user is not in them", async () => {
mockOrgMemberships.set("johndoetw", []);
Expand Down
5 changes: 3 additions & 2 deletions lib/get-user-status.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use strict";
/* eslint max-len: ["error", { "code": 120, "ignoreTemplateLiterals": true }] */
const { URL } = require("url");
const listify = require("listify");
const config = require("../config.json");
const gitHubAPI = require("./helpers/github.js").api;
const { workstreamFromRepo } = require("./helpers/workstreams.js");
Expand All @@ -11,6 +10,8 @@ const html = require("escape-goat").htmlEscape;

const statusURLBase = (new URL(config.statusPath, config.serverURL)).href;

const listFormat = new Intl.ListFormat("en", { style: "long", type: "conjunction" });

module.exports = async (submitterGitHubID, repoName, pullNumber) => {
const [individualsData, entityData] = await Promise.all([
jsonGitHubDatabase.get("individual-public"),
Expand Down Expand Up @@ -170,7 +171,7 @@ function statusNothing(submitterGitHubID, targetURL) {

function entityVerbiage(entities) {
return {
orgs: listify(entities.map(entity => entity.info.gitHubOrganization)),
orgs: listFormat.format(entities.map(entity => entity.info.gitHubOrganization)),
word: entities.length === 1 ? "organization" : "organizations",
pronoun: entities.length === 1 ? "it" : "they all",
pronoun2: entities.length === 1 ? "this" : "those",
Expand Down
12 changes: 0 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"koa": "^2.14.2",
"koa-bodyparser": "^4.4.1",
"koa-handlebars": "^2.0.0",
"listify": "^1.0.3",
"twitter-api-v2": "^1.15.2"
},
"devDependencies": {
Expand Down

0 comments on commit ec0caba

Please sign in to comment.