Integrate Keystatic to edit twenty.com content (#10709)
This PR introduces Keystatic to let us edit twenty.com's content with a CMS. For now, we'll focus on creating release notes through Keystatic as it uses quite simple Markdown. Other types of content will need some refactoring to work with Keystatic. https://github.com/user-attachments/assets/e9f85bbf-daff-4b41-bc97-d1baf63758b2 --------- Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
committed by
GitHub
parent
6b4d3ed025
commit
2c465bd42e
@ -0,0 +1,22 @@
|
||||
const TOTAL_DAYS_TO_FULL_WIDTH = 232;
|
||||
|
||||
export const getActivityEndDate = (
|
||||
activityDates: { value: number; day: string }[],
|
||||
) => {
|
||||
const startDate = new Date(activityDates[0].day);
|
||||
const endDate = new Date(activityDates[activityDates.length - 1].day);
|
||||
|
||||
const differenceInMilliseconds = endDate.getTime() - startDate.getTime();
|
||||
|
||||
const numberOfDays = Math.floor(
|
||||
differenceInMilliseconds / (1000 * 60 * 60 * 24),
|
||||
);
|
||||
|
||||
const daysToAdd = TOTAL_DAYS_TO_FULL_WIDTH - numberOfDays;
|
||||
|
||||
if (daysToAdd > 0) {
|
||||
endDate.setDate(endDate.getDate() + daysToAdd);
|
||||
}
|
||||
|
||||
return endDate;
|
||||
};
|
||||
@ -0,0 +1,76 @@
|
||||
import { findAll } from '@/database/database';
|
||||
import { pullRequestModel, userModel } from '@/database/model';
|
||||
import { TWENTY_TEAM_MEMBERS } from '@/shared-utils/listTeamMembers';
|
||||
|
||||
export const getContributorActivity = async (username: string) => {
|
||||
const contributors = await findAll(userModel);
|
||||
|
||||
const contributor = contributors.find((contributor) => {
|
||||
return contributor.id === username;
|
||||
});
|
||||
|
||||
if (!contributor) {
|
||||
return;
|
||||
}
|
||||
|
||||
const pullRequests = await findAll(pullRequestModel);
|
||||
const mergedPullRequests = pullRequests
|
||||
.filter((pr) => pr.mergedAt !== null)
|
||||
.filter((pr) => !TWENTY_TEAM_MEMBERS.includes(pr.authorId));
|
||||
|
||||
const contributorPullRequests = pullRequests.filter(
|
||||
(pr) => pr.authorId === contributor.id,
|
||||
);
|
||||
const mergedContributorPullRequests = contributorPullRequests.filter(
|
||||
(pr) => pr.mergedAt !== null,
|
||||
);
|
||||
|
||||
const mergedContributorPullRequestsByContributor = mergedPullRequests.reduce(
|
||||
(acc, pr) => {
|
||||
acc[pr.authorId] = (acc[pr.authorId] || 0) + 1;
|
||||
return acc;
|
||||
},
|
||||
{},
|
||||
);
|
||||
|
||||
const mergedContributorPullRequestsByContributorArray = Object.entries(
|
||||
mergedContributorPullRequestsByContributor,
|
||||
)
|
||||
.map(([authorId, value]) => ({ authorId, value }))
|
||||
.sort((a, b) => b.value - a.value);
|
||||
|
||||
const contributorRank =
|
||||
((mergedContributorPullRequestsByContributorArray.findIndex(
|
||||
(contributor) => contributor.authorId === username,
|
||||
) +
|
||||
1) /
|
||||
contributors.length) *
|
||||
100;
|
||||
|
||||
const pullRequestActivity = contributorPullRequests.reduce((acc, pr) => {
|
||||
const date = new Date(pr.createdAt).toISOString().split('T')[0];
|
||||
acc[date] = (acc[date] || 0) + 1;
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
const pullRequestActivityArray = Object.entries(pullRequestActivity)
|
||||
.map(([day, value]) => ({ day, value }))
|
||||
.sort((a, b) => new Date(a.day).getTime() - new Date(b.day).getTime());
|
||||
|
||||
const firstContributionAt = pullRequestActivityArray[0]?.day;
|
||||
const mergedPRsCount = mergedContributorPullRequests.length;
|
||||
const rank = Math.ceil(Number(contributorRank)).toFixed(0);
|
||||
const activeDays = pullRequestActivityArray.length;
|
||||
const contributorAvatar = contributor.avatarUrl;
|
||||
|
||||
return {
|
||||
firstContributionAt,
|
||||
mergedPRsCount,
|
||||
rank,
|
||||
activeDays,
|
||||
pullRequestActivityArray,
|
||||
contributorPullRequests,
|
||||
contributorAvatar,
|
||||
contributor,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user