@r4lrgx/gitmoji
Version:
🧱 My customized Gitmoji Config - a fork of https://github.com/arvinxx/gitmoji-commit-workflow - just with several bug fixes and a cleaner look.
187 lines (182 loc) • 5.08 kB
JavaScript
import _ from 'lodash';
import 'pangu';
import fetch from 'sync-fetch';
// @r4lrgx/gitmoji v1.0.3
// MIT License
var { merge } = _;
var commitTypeMap = {
feat: {
emoji: "\u2728",
title: "Features",
subtitle: "New features and enhancements"
},
fix: {
emoji: "\u{1F41B}",
title: "Bug Fixes",
subtitle: "Resolved bugs and issues"
},
perf: {
emoji: "\u26A1",
title: "Performance Improvements",
subtitle: "Faster, leaner, better"
},
refactor: {
emoji: "\u267B",
title: "Code Refactoring",
subtitle: "Code structure improvements"
},
chore: {
emoji: "\u{1F527}",
title: "Chores",
subtitle: "Other tasks and maintenance"
},
docs: {
emoji: "\u{1F4DD}",
title: "Documentation",
subtitle: "Docs updates and improvements"
},
build: {
emoji: "\u{1F4E6}\uFE0F",
title: "Build System",
subtitle: "Changes to build tools and processes"
},
ci: {
emoji: "\u{1F477}",
title: "Continuous Integration",
subtitle: "CI config updates and automation"
},
test: {
emoji: "\u2705",
title: "Tests",
subtitle: "Added or updated tests"
},
style: {
emoji: "\u{1F3A8}",
title: "Styles",
subtitle: "Visual tweaks and formatting"
},
wip: {
emoji: "\u{1F691}\uFE0F",
title: "Cleaning",
subtitle: "Work in progress or cleanup"
},
revert: {
emoji: "\u23EA",
title: "Reverts",
subtitle: "Undone changes and rollbacks"
}
};
var defineCommitTypeMap = (customCommitTypeMap) => {
if (!customCommitTypeMap) return commitTypeMap;
return merge(customCommitTypeMap, commitTypeMap);
};
function gitHubLookup(email) {
const match = email.match(/^(\d*)\+?([a-zA-Z0-9\-]*)\.noreply\.github\.com$/);
let info = null;
if (match) {
const [_3, id, username] = match;
info = { id, username };
} else {
try {
const res = fetch(`https://api.github.com/search/commits?q=author-email:${encodeURIComponent(email)}`, {
headers: {
Accept: "application/vnd.github.cloak-preview+json"
}
});
if (!res.ok) return null;
const data = res.json();
if (data.items && data.items.length > 0) {
const username = data.items[0]?.author?.login;
const id = data.items[0]?.author?.id;
if (id && username) info = { id, username };
}
} catch (_err) {
return null;
}
}
if (!info?.id || !info?.username) return null;
try {
const res = fetch(`https://api.github.com/users/${info.username}`, {
headers: {
Accept: "application/vnd.github.cloak-preview+json"
}
});
if (!res.ok) return null;
const user = res.json();
return {
authorName: info.username,
authorAvatar: user.avatar_url,
authorUrl: user.html_url,
authorEmail: `${info.id}+${info.username}.noreply.github.com`
};
} catch (_err) {
return null;
}
}
// src/changelog-config/handlers/transformer.ts
var { cloneDeep } = _;
// src/changelog-config/context/index.ts
var users = /* @__PURE__ */ new Map();
var finalizeContext = (config) => (
/**
* Processes the changelog context
* @param {Context} context - The changelog context to enhance
* @returns {Context} The enhanced context or undefined if invalid
*/
(context) => {
const subCommitScope = (config.customScopeMap && config.customScopeMap["*"]) ?? null;
const commitTypeMap2 = defineCommitTypeMap(config.customCommitTypeMap);
context.commitGroups = context.commitGroups?.map((item) => {
const { subtitle } = Object.values(commitTypeMap2).find(({ emoji }) => item.title.includes(emoji));
let group;
let commits = item.commits.sort((a, b) => {
if (a.scope === subCommitScope && b.scope === subCommitScope) {
return 0;
} else if (a.scope === subCommitScope) {
return 1;
} else if (b.scope === subCommitScope) {
return -1;
} else {
return 0;
}
});
commits = commits.map((commit, index) => {
if (commit.scope) {
if (group !== commit.scope) {
group = commit.scope;
commit.first = true;
} else {
commit.first = false;
}
}
if (!commits[index + 1] || group !== commits[index + 1].scope) {
commit.last = true;
} else {
commit.last = false;
}
const { email } = commit.author;
if (config.showAuthor || config.showAuthorAvatar) {
if (!users.has(email)) {
try {
const author = gitHubLookup(email);
users.set(email, author);
} catch (_e) {
users.set(email, null);
}
}
}
return commit;
});
return {
title: item.title,
subtitle,
commits
};
});
context.authors = Array.from(users.values());
return context;
}
);
export { finalizeContext };
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map