Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null name, no capitalize & introduce eslint fix command #77

Merged
merged 4 commits into from
May 3, 2024
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
23 changes: 10 additions & 13 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33860,15 +33860,6 @@ const templateParser = inputTemplate => {

/* harmony default export */ const utils_templateParser = (templateParser);

;// CONCATENATED MODULE: ./src/utils/capitalize.js
const capitalCaseUtil = str => {
return str.charAt(0).toUpperCase() + str.substring(1);
};

/* harmony default export */ const capitalize = (str => {
return str ? str.split(' ').map(capitalCaseUtil).join(' ') : '';
});

;// CONCATENATED MODULE: ./src/utils/stripDuplicates.js
/**
* function to clean an array of objects with duplicates
Expand Down Expand Up @@ -33902,7 +33893,6 @@ const htmlEncoding = string => {




const getTemplate = (userID, imageSize, name, avatarUrl) => {
return `
<td align="center">
Expand All @@ -33929,15 +33919,22 @@ const getUserInfo = async (login, avatarUrl, prevContributors, useUserName) => {
const {
data: { name, avatar_url }
} = await src_octokit.rest.users.getByUsername({ username: login });
return { name: useUserName ? login : htmlEncoding(name), url: avatar_url };
// Use login (== username) when useUserName is true, otherwise try to use name.
// Unless name is null, then fallback to login.
const finalName = (useUserName) ? login: (name) ? htmlEncoding(name) : login
return { name: finalName, url: avatar_url };
} catch (error) {
console.log(`Oops...given github id ${login} is invalid :(`);
return { name: login, url: '' };
}
}

// Use login (== username) when useUserName is true, otherwise try to use name.
// If name is null, then fallback to login.
const finalName = (useUserName) ? login : (prevContributors[login] && prevContributors[login].name) ?
htmlEncoding(prevContributors[login].name) : login
return {
name: useUserName ? login : htmlEncoding(prevContributors[login].name),
name: finalName,
url: avatarUrl || prevContributors[login].url
};
};
Expand Down Expand Up @@ -33980,7 +33977,7 @@ const templateBuilder = async (contributors, prevContributors, type) => {
contributors_content += getTemplate(
login,
imageSize,
useUsername ? name : capitalize(name),
name,
url
);
} else {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"scripts": {
"lint": "eslint .",
"fix": "eslint --fix .",
"format": "prettier --write **/*.js",
"format-check": "prettier --check **/*.js",
"test": "jest --verbose",
Expand Down
14 changes: 10 additions & 4 deletions src/utils/templateBuilder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import capitalize from './capitalize';
import stripDuplicates from './stripDuplicates';
import octokit from '../octokit';

Expand Down Expand Up @@ -31,15 +30,22 @@ export const getUserInfo = async (login, avatarUrl, prevContributors, useUserNam
const {
data: { name, avatar_url }
} = await octokit.rest.users.getByUsername({ username: login });
return { name: useUserName ? login : htmlEncoding(name), url: avatar_url };
// Use login (== username) when useUserName is true, otherwise try to use name.
// Unless name is null, then fallback to login.
const finalName = (useUserName) ? login: (name) ? htmlEncoding(name) : login
return { name: finalName, url: avatar_url };
} catch (error) {
console.log(`Oops...given github id ${login} is invalid :(`);
return { name: login, url: '' };
}
}

// Use login (== username) when useUserName is true, otherwise try to use name.
// If name is null, then fallback to login.
const finalName = (useUserName) ? login : (prevContributors[login] && prevContributors[login].name) ?
htmlEncoding(prevContributors[login].name) : login
return {
name: useUserName ? login : htmlEncoding(prevContributors[login].name),
name: finalName,
url: avatarUrl || prevContributors[login].url
};
};
Expand Down Expand Up @@ -82,7 +88,7 @@ const templateBuilder = async (contributors, prevContributors, type) => {
contributors_content += getTemplate(
login,
imageSize,
useUsername ? name : capitalize(name),
name,
url
);
} else {
Expand Down