【问题标题】:How can I update bugzilla entries from GitHub?如何从 GitHub 更新 bugzilla 条目?
【发布时间】:2011-07-15 18:29:16
【问题描述】:

我真的只想在提交消息中使用错误编号时添加指向提交的链接。能够关闭错误等将是一个加号,但确实超出了我的需要。

我们通常在提交消息中以 xxxx 的形式添加 bug 编号。

我目前的计划是使用 Bugzilla 附带的 email_in.pl 脚本和 github 上的电子邮件提交后挂钩。电子邮件挂钩发送包含每个提交详细信息的有效负载。我可以解析它,将其重定向到 email_in.pl 脚本。这是最好的方法吗?还没有人做过吗?

任何帮助/提示/链接将不胜感激。

【问题讨论】:

  • 使用Post-Receive URLs hook怎么样?
  • 您有什么建议?我写一个脚本来解析 JSON 并发送电子邮件?
  • 您有 github 帖子到您的 bugzilla 服务器,并使用 JSONRPC,以这种方式更新错误。不确定它是否会起作用,但从理论上讲,它应该......
  • 谢谢。 JSONRPC 可能会起作用,只需解析有效负载并点击 URL。由于我设置了 email_in.pl,但没有设置 JSON API,因此我使用了您在下面看到的内容。感谢您的提示。

标签: perl git github bugzilla


【解决方案1】:

由于我已经设置了 email_in.pl,我决定编写一个小脚本来解析 URL post-receive 挂钩的有效负载并将其作为电子邮件发送到 bugzilla。因此,接收后挂钩将命中执行以下操作的 URL:

<?php
$payload = json_decode($_REQUEST['payload']);

if ($payload) {
    // assumes you want to process all commits (we only commit to the master branch)
    // but you may want to add some other conditionals above.
    $commits = $payload->commits;

    // there may be many commits per payload
    foreach ($commits as $commit) {
       $message = $commit->message;
       preg_match('/^(\*(\d+)\*)(.*)/i', $message, $matches);
       // The commit message must match the above regex
       // i.e. *1234* commit message
       if ( !(is_array($matches) && count($matches) == 4) )
          continue;

        $bugNumber = $matches[2];
        $comment = trim($matches[3]);
        $url = $commit->url;

        // get the author info
        $author = $commit->author;
        $authorName = $author->name;
        // assumes github email address exists in bugzilla.
        $authorEmail = $author->email;

        // construct the email
        $subject = "[Bug $bugNumber]";
        $body = "$comment\n$url";
        $header = "From: $authorName <$authorEmail>";
        // $bugzillaEmail = 'your@bugzilla.email
        mail($bugzillaEmail, $subject, $body, $header);
}
?>

【讨论】:

    猜你喜欢
    • 2010-09-25
    • 2019-11-08
    • 1970-01-01
    • 2021-06-24
    • 1970-01-01
    • 1970-01-01
    • 2012-03-28
    • 2012-11-11
    • 2019-09-03
    相关资源
    最近更新 更多