square1/gwitlog

通过将提交日志样式化成社交媒体时间轴,让开发者渴望阅读你的提交日志

0.1.5 2014-09-28 20:07 UTC

This package is auto-updated.

Last update: 2024-08-29 04:03:20 UTC


README

通过将提交日志样式化成社交媒体时间轴,让开发者渴望阅读你的提交日志。

基于这个commitstrip漫画,此工具允许你将git仓库中的提交日志样式化为社交媒体时间轴。

安装

可以通过将"conroyp/gwitlog": "dev-master"包添加到你的项目中的composer.json来安装此包。

[
    "require": {
        "square1/gwitlog": "0.1.*"
    }
]

用法

生成日志文件

运行以下命令在你的仓库上生成所需的git log格式

git log --pretty=format:'%H -%d %s (%ad) <%an:%ae>'

将时间轴输出到屏幕

<?php
/**
 * A simple script to read a git log from a file and render the timeline to screen
 */
require 'vendor/autoload.php';

use \Square1\Gwitlog\Renderer as Renderer;

$gwitlog = new Renderer();
// Provide repo name
$gwitlog->setRepoName('Gwitlog');
// Provide remote repo base (Optional, but it allows us link commits back to the web GUI)
// Currently support bitbucket and github urls
$gwitlog->setRemoteHost('https://github.com/square1-io/gwitlog');

// Log file generated based on git log command:
// git log --pretty=format:'%H -%d %s (%ad) <%an:%ae>' > git.log
$gwitlog->setInputFile('git.log');

// Generate output and render to screen
$gwitlog->render();

将时间轴输出到文件

<?php
/**
 * A simple script to read a git log from a file and render the timeline to a file
 */
require 'vendor/autoload.php';

use \Square1\Gwitlog\Renderer as Renderer;

$gwitlog = new Renderer();
// Provide repo name
$gwitlog->setRepoName('Gwitlog');
// Provide remote repo base (Optional, but it allows us link commits back to the web GUI)
// Currently support bitbucket and github urls
$gwitlog->setRemoteHost('https://github.com/square1-io/gwitlog');

// Log file generated based on git log command:
// git log --pretty=format:'%H -%d %s (%ad) <%an:%ae>' > git.log
$gwitlog->setInputFile('git.log');

// Write to file timeline.html
$gwitlog->outputToFile('timeline.html');

从stdin读取而不是从平面文件读取

Gwitlog还支持从输入流中读取,允许将git log命令通过脚本管道传输,而不需要写入中间的git.log文件。

<?php
/**
 * A simple script to read a git log from stdin and render the timeline to screen
 */
require 'vendor/autoload.php';

use \Square1\Gwitlog\Renderer as Renderer;

$gwitlog = new Renderer();
// Provide repo name
$gwitlog->setRepoName('Gwitlog');
// Provide remote repo base (Optional, but it allows us link commits back to the web GUI)
// Currently support bitbucket and github urls
$gwitlog->setRemoteHost('https://github.com/square1-io/gwitlog');

// Read from input stream
$input = fopen('php://stdin', 'r');
$gwitlog->setInputStream($input);

// Generate output and render to screen
$gwitlog->render();

将上述内容保存为gwitlog.php允许我们运行

git log --pretty=format:'%H -%d %s (%ad) <%an:%ae>' | gwitlog.php > timeline.html

这会留下一个包含格式化时间轴的文件(timeline.html)。这使得在本地测试环境中,像构建后钩子这样的功能能够生成一个新时间轴,以便团队在每次成功的合并后进行审查。

自定义输出

可以自定义结果输出。我们使用Blade模板语言,它通常在Laravel项目中找到。

可以给Renderer提供一个包含自定义视图的目录的位置。它将期望在这里找到三个视图 - header.blade.phpgwit.blade.phpfooter.blade.php。可以在调用outputToFilerender函数之前任何时候调用传递该目录的调用。

<?php
/**
 * A simple script to read a git log from stdin and render the timeline to screen, using
 * customised views
 */
require 'vendor/autoload.php';

use \Square1\Gwitlog\Renderer as Renderer;

$gwitlog = new Renderer();
// Provide repo name
$gwitlog->setRepoName('Gwitlog');
// Provide remote repo base (Optional, but it allows us link commits back to the web GUI)
// Currently support bitbucket and github urls
$gwitlog->setRemoteHost('https://github.com/square1-io/gwitlog');

// Use our custom templates
$gwitlog->setViewDirectory(__DIR__ . '/../views/gwitlog');

// Read from input stream
$input = fopen('php://stdin', 'r');
$gwitlog->setInputStream($input);

// Generate output and render to screen
$gwitlog->render();

默认情况下,这些视图将缓存到/tmp。如果你有部署权限问题或者希望将所有项目视图都缓存在一个地方,请调用setCacheDirectory($path)。这将更新由渲染器使用的缓存目录。

覆盖默认大小限制

默认情况下,将处理最多20,000个提交。如果你想要尝试处理超过这个数量的提交,调用setMaxEntries($limit)将增加处理限制。

测试

phpunit

路线图

  • 解析常规日志输出,允许多行提交在多行中可见
  • 处理--graph的输出,更好地将分支名称附加到该分支上的所有提交
  • 接受公共项目的URL并自动从中下载git日志