2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-20 20:00:40 +03:00

chore(ci): improved contributors list generator; (#5443)

This commit is contained in:
Dmitriy Mozgovoy
2023-01-07 02:40:08 +02:00
committed by GitHub
parent 145df40e44
commit f6b480912e
4 changed files with 75 additions and 26 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TYPE_ARG: ${{ fromJSON('{"auto":"", "patch":"--patch", "minor":"--minor", "major":"--major"}')[github.event.inputs.type] }} TYPE_ARG: ${{ fromJSON('{"auto":"", "patch":"--patch", "minor":"--minor", "major":"--major"}')[github.event.inputs.type] }}
BETA_ARG: ${{ github.event.inputs.beta == 'true' && '--preRelease=beta' || '' }} BETA_ARG: ${{ github.event.inputs.beta == 'true' && '--preRelease=beta' || '' }}
run: npm run release -- --ci --verbose $TYPE_ARG $BETA_ARG run: npm run release -- --ci --no-git --verbose $TYPE_ARG $BETA_ARG
- name: get-npm-version - name: get-npm-version
id: package-version id: package-version
uses: martinbeentjes/npm-get-version-action@main uses: martinbeentjes/npm-get-version-action@main
+65 -19
View File
@@ -14,25 +14,65 @@ const cleanTemplate = template => template
.replace(/\n\n\n+/g, '\n\n') .replace(/\n\n\n+/g, '\n\n')
.replace(/\n\n$/, '\n'); .replace(/\n\n$/, '\n');
const getUserInfo = ((userCache) => async (email) => { const getUserFromCommit = ((commitCache) => async (sha) => {
if (userCache[email] !== undefined) {
return userCache[email];
}
try { try {
const tag = email.replace(/@users\.noreply\.github\.com/, ''); if(commitCache[sha] !== undefined) {
return commitCache[sha];
}
const {data: {items: [user]}} = await axios.get(`https://api.github.com/search/users?q=${tag}`); const {data} = await axios.get(`https://api.github.com/repos/axios/axios/commits/${sha}`);
return (userCache[email] = user ? { return commitCache[sha] = {
...user, ...data.commit.author,
avatar_url_sm: user.avatar_url + '&s=16' ...data.author,
} : null); avatar_url_sm: data.author.avatar_url ? data.author.avatar_url + '&s=16' : '',
};
} catch (err) { } catch (err) {
console.warn(err); return commitCache[sha] = null;
return {};
} }
})({}); })({});
const getUserInfo = ((userCache) => async (userEntry) => {
const {email, commits} = userEntry;
if (userCache[email] !== undefined) {
return userCache[email];
}
return userCache[email] = {
...userEntry,
...await getUserFromCommit(commits[0])
}
})({});
const deduplicate = (authors) => {
const loginsMap = {};
const combined= {};
const assign = (a, b) => {
const {insertions, deletions, points, ...rest} = b;
Object.assign(a, rest);
a.insertions += insertions;
a.deletions += insertions;
a.insertions += insertions;
}
for(const [email, user] of Object.entries(authors)) {
const {login} = user;
let entry;
if(login && (entry = loginsMap[login])) {
assign(entry, user);
} else {
login && (loginsMap[login] = user);
combined[email] = user;
}
}
return combined;
}
const getReleaseInfo = async (version, useGithub) => { const getReleaseInfo = async (version, useGithub) => {
version = 'v' + version.replace(/^v/, ''); version = 'v' + version.replace(/^v/, '');
@@ -52,15 +92,16 @@ const getReleaseInfo = async (version, useGithub) => {
...release.merges.map(fix => fix.commit) ...release.merges.map(fix => fix.commit)
].filter(Boolean); ].filter(Boolean);
for(const {author, email, insertions, deletions} of commits) { for(const {hash, author, email, insertions, deletions} of commits) {
const user = Object.assign({
email
}, useGithub ? await getUserInfo(email) : null);
const entry = authors[email] = (authors[email] || { const entry = authors[email] = (authors[email] || {
insertions: 0, deletions: 0, ...user name: author,
email,
commits: [],
insertions: 0, deletions: 0
}); });
entry.commits.push(hash);
entry.displayName = entry.name || author || entry.login; entry.displayName = entry.name || author || entry.login;
entry.github = entry.login ? `https://github.com/${encodeURIComponent(entry.login)}` : ''; entry.github = entry.login ? `https://github.com/${encodeURIComponent(entry.login)}` : '';
@@ -68,9 +109,14 @@ const getReleaseInfo = async (version, useGithub) => {
entry.insertions += insertions; entry.insertions += insertions;
entry.deletions += deletions; entry.deletions += deletions;
entry.points = entry.insertions + entry.deletions; entry.points = entry.insertions + entry.deletions;
entry.isBot = entry.type === "Bot"
} }
release.authors = Object.values(authors).sort((a, b) => b.points - a.points); for(const [email, author] of Object.entries(authors)) {
authors[email] = await getUserInfo(author);
}
release.authors = Object.values(deduplicate(authors)).sort((a, b) => b.points - a.points);
release.allCommits = commits; release.allCommits = commits;
} }
+3 -2
View File
@@ -161,8 +161,9 @@
"release-it": { "release-it": {
"git": { "git": {
"commitMessage": "chore(release): v${version}", "commitMessage": "chore(release): v${version}",
"push": false, "push": true,
"commit": false "commit": true,
"tag": true
}, },
"github": { "github": {
"release": false "release": false
+6 -4
View File
@@ -1,13 +1,15 @@
{{#if authors}} {{#if authors}}
### Contributors 🤵 ### Contributors to this release
{{#each authors}} {{#each authors}}
{{#if github}} {{#unless isBot}}
- {{#if avatar_url}}![avatar]({{avatar_url_sm}}){{/if}} [{{displayName}}]({{github}}) ({{insertions}}++ / {{deletions}}--) {{#if login}}
- {{#if avatar_url}}![avatar]({{avatar_url_sm}}){{/if}} [{{displayName}}]({{html_url}})
{{else}} {{else}}
- {{displayName}} ({{insertions}}++ / {{deletions}}--) - {{displayName}}
{{/if}} {{/if}}
{{/unless}}
{{/each}} {{/each}}
{{/if}} {{/if}}