Minor: Update gitlog script for changelog co-generation

pull/5639/head
Yannick Warnier 1 year ago
parent 1a03a7faec
commit 1aeb8ff71c
  1. 151
      tests/scripts/packaging/gitlog.php

@ -1,10 +1,13 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This script pre-generates a list of commits to generate a changelog in the
* form (branch, then commits in HTML form, then a final feedback):
*
* @example
* 1.9.x
* master
* <li>(<a href="https://github.com/chamilo/chamilo-lms/commit/7333997ce358870bac139d15816dcaa7dd7794fa">7333997c</a> - <a href="https://task.beeznest.com/issues/8680">BT#8680</a>) Fixing custom lost password to work as classic Chamilo</li>
* ...
* <li>(<a href="https://github.com/chamilo/chamilo-lms/commit/acdc14c47997315b151efda9a530c47a53100d68">acdc14c4</a> - <a href="https://task.beeznest.com/issues/8676">BT#8676</a>) Adding unique email validation option</li>
@ -17,9 +20,13 @@
* @usage php gitlog.php [-t|some-commit|-max20171001]
* @see https://github.com/ywarnier/git
*/
exit;
if (PHP_SAPI != 'cli') {
die('This script can only be launched from the command line');
}
require 'php-git/src/Git.php';
$repository = __DIR__.'/../..';
$number = 2000; //the number of commits to check (including minor)
$number = 10000; //the number of commits to check (including minor)
$formatHTML = true;
$showDate = false;
$endCommit = false;
@ -56,11 +63,23 @@ foreach ($logs as $log) {
continue;
}
}
// Check for Minor importance messages to ignore...
if (strncasecmp($log['message'], 'Minor', 5) === 0) {
//Skip minor messages
continue;
// Replace "Something - Something" by "Something: Something"
$matches = array();
if (preg_match('/^(\w*)\s-\s(.*)/', $log['message'], $matches)) {
$log['message'] = $matches[1].': '.$matches[2];
}
// Replace "Something - Something" by "Something: Something"
$matches = array();
if (preg_match('/^(\w*\s\w*)\s-\s(.*)/', $log['message'], $matches)) {
$log['message'] = $matches[1].': '.$matches[2];
}
// Replace "Something : Something" by "Something: Something"
$matches = array();
if (preg_match('/^(\w*)\s:\s(.*)/', $log['message'], $matches)) {
$log['message'] = $matches[1].': '.$matches[2];
}
//Skip language update messages (not important)
$langMsg = array(
'Update language terms',
@ -77,6 +96,14 @@ foreach ($logs as $log) {
continue 2;
}
}
$log['message'] = sanitizeCategory($log['message']);
// Check for Minor importance messages to ignore...
if (strncasecmp($log['message'], 'Minor', 5) === 0) {
//Skip minor messages
continue;
}
// Look for tasks references
$issueLink = '';
$matches = array();
@ -85,20 +112,11 @@ foreach ($logs as $log) {
if (substr($issue, 0, 1) == '#') {
// not a BeezNest task
$num = substr($issue, 1);
if ($num > 4000) {
//should be Chamilo support site
if ($formatHTML) {
$issueLink = ' - <a href="https://support.chamilo.org/issues/' . $num . '">CT#' . $num . '</a>';
} else {
$issueLink = ' - ' . $num;
}
//should be Github
if ($formatHTML) {
$issueLink = ' - <a href="https://github.com/chamilo/chamilo-lms/issues/' . $num . '">GH#' . $num . '</a>';
} else {
//should be Github
if ($formatHTML) {
$issueLink = ' - <a href="https://github.com/chamilo/chamilo-lms/issues/' . $num . '">GH#' . $num . '</a>';
} else {
$issueLink = ' - ' . $num;
}
$issueLink = ' - ' . $num;
}
} else {
$num = substr($issue, 3);
@ -120,7 +138,12 @@ foreach ($logs as $log) {
if ($hasRefs = stripos($log['message'], ' -refs ')) {
$log['message'] = substr($log['message'], 0, $hasRefs);
}
if ($hasRefs = stripos($log['message'], ' - refs ')) {
$log['message'] = substr($log['message'], 0, $hasRefs);
}
if ($hasRefs = stripos($log['message'], ' '.$matches[0][0])) {
$log['message'] = substr($log['message'], 0, $hasRefs);
}
}
$commitLink = '';
if ($formatHTML) {
@ -143,3 +166,91 @@ foreach ($logs as $log) {
$i++;
}
echo "Printed $i commits of $number requested (others were minor)".PHP_EOL;
/**
* Get a message string and replace prefixes that do not match specs
* in /documentation/changelog.html#terminology with prefixes that do
* @param string $message
* @return string The modified log message
*/
function sanitizeCategory(string $message): string {
$knownMistakes = [
'Quiz' => 'Exercise',
'Exercises' => 'Exercise',
'LP' => 'Learnpath',
'Learning Paths' => 'Learnpath',
'LearningPath' => 'Learnpath',
'Learnpaths' => 'Learnpath',
'Documents' => 'Document',
'Announcements' => 'Announcement',
'RemedialCourse' => 'Plugin: RemedialCourse',
'Groups' => 'Group',
'Survey report' => 'Survey',
'Survey list export' => 'Survey',
'Learnpath report' => 'Learnpath',
'TopLink' => 'Plugin: TopLinks',
'TopLinks' => 'Plugin: TopLinks',
'Sessions' => 'Session',
'Cas' => 'Authentication: CAS',
'Webservices' => 'Webservice',
'WebService' => 'Webservice',
'Web services' => 'Webservice',
'BBB' => 'Plugin: BigBlueButton',
'My Progress' => 'Tracking',
'My Progres' => 'Tracking',
'Reports' => 'Tracking',
'Courses' => 'Display',
'[LP]' => 'Learnpath',
'Student follow page' => 'Tracking: Student follow-up',
'REST' => 'Webservice: REST',
'Import CSV' => 'Admin: CSV import',
'ImportCSV' => 'Admin: CSV import',
'Import_csv.php' => 'Admin: CSV import',
'[Minor]' => 'Minor:',
'[usergroup]' => 'Group',
'[admin]' => 'Admin',
'MySpace' => 'Tracking',
'Career diagram' => 'Career',
'Careers' => 'Career',
'Users' => 'User',
'Style:' => 'Display:',
'Course Announcement' => 'Announcement',
'Testing' => 'QA',
'CI' => 'QA',
'Blogs' => 'Blog',
'Gradebook eval' => 'Gradebook',
'Survey test' => 'QA: Survey',
'Editor' => 'WYSIWYG',
'Global' => 'Internal',
'Extra field' => 'Extra Fields',
'Settings' => 'Admin',
'Changelog' => 'Documentation',
'Session import' => 'Admin: Session import',
'XAPI' => 'xAPI',
'CourseCopy' => 'Maintenance',
'Course Copy' => 'Maintenance',
'Reporting' => 'Tracking',
'Course Backup' => 'Maintenance',
'SSO' => 'Authentication: Single Sign On',
'Skills' => 'Skill',
'Messages' => 'Message',
'Security fixes -' => 'Security:',
'Work' => 'Assignment',
'Works' => 'Assignment',
'Improve code' => 'Internal: Improve code',
'Pending works' => 'Assignment',
'Thematic' => 'Course Progress',
'Thematic advance' => 'Course Progress',
'Agenda' => 'Calendar',
'Course import' => 'Maintenance',
'Student publication' => 'Assignment',
'Student publications' => 'Assignment',
];
foreach ($knownMistakes as $term => $fix) {
if (strncasecmp($message, $term, strlen($term)) === 0) {
//Skip minor messages
$message = $fix.substr($message, strlen($term));
}
}
return $message;
}

Loading…
Cancel
Save