onwwward/laravel-bugherd

Laravel 5 对 Bugherd API 的封装

0.1.0 2016-08-23 11:13 UTC

This package is not auto-updated.

Last update: 2024-09-26 03:12:46 UTC


README

Build Status StyleCI license Packagist

这是一个对 PHP Bugherd Api 包的 Laravel 5 封装。

什么是 Bugherd?

BugHerd 是一个简单的点选式错误跟踪器,由 Alan Downie 和 Matt Milosavljevic 于 2011 年创立。

https://bugherd.com/

https://www.bugherd.com/api_v2

基本安装

Laravel

将服务提供者添加到 config/app.php 文件中的 providers 数组

...
Onwwward\Bugherd\BugherdServiceProvider::class,
...

您可以可选地使用外观来缩短代码。将外观添加到 config/app.php 文件中的别名数组

...
'Bugherd' => Onwwward\Bugherd\Facade\Bugherd::class,
...

Lumen

bootstrap/app.php 文件中找到应注册服务提供者的部分,并添加以下内容

...
$app->register(Onwwward\Bugherd\BugherdServiceProvider::class);
...

您可选地使用外观来缩短代码。但是您需要在 bootstrap/app.php 文件中取消注释以下行

...
$app->withFacades();
...

您还必须将以下内容添加到同一文件

...
class_alias('Onwwward\Bugherd\Facades\Bugherd', 'Bugherd');
...

配置

Laravel

您需要提供您的 apikey,您可以在 Bugherd 的个人资料设置下找到它。在 Laravel 中,您应该能够使用 artisan 命令发布配置文件,但您也可以手动创建该文件。

$ php artisan vendor:publish --provider="Onwwward\Bugherd\BugherdServiceProvider" --tag="config"

文件在哪里? Laravel 5 将配置文件发布到 /config/bugherd.php

Lumen

Lumen 中没有发布包文件的命令,所以您必须手动创建配置文件。在应用程序的根目录中创建一个 config 目录,如果您还没有的话。然后,从 /vendor/onwwward/laravel-bugherd/src/config/ 复制 bugherd.php 文件,或者创建一个返回带有正确 'apikey' 的简单数组的 php 文件。

...
return [
  'apikey' => 'YOUR_API_KEY'
];
...

代码示例

有几种方法可以从容器中解析出某些内容。

使用外观

在顶部包含外观

use Onwwward/Bugherd/Facades/Bugherd;

然后您可以在任何地方使用它

Bugherd::api('user')->all();

类型提示

protected $protected;

public function __construct(Bugherd/Client $bugherd)
{
   $this->bugherd = $bugherd;
}

制作方法(Laravel)

$bugherd = $this->app->make('bugherd');
$bugherd->api('user')->all();

app 助手(Lumen)

$bugherd = app('bugherd');
$bugherd->api('user')->all();

访问 Bugherd 资源

/** Projects **/
// Get all projects
$projects = Bugherd::api('project')->all();

// Get all active projects
$active_projects = $bugherd->api('project')->allActive();

// Get all projects with name/id pairs
$projects = $bugherd->api('project')->listing($forceUpdate, $reverse);

// Get all active projects with name/id pairs
$active_projects = $bugherd->api('project')->listingActive($forceUpdate, $reverse);

// Get project id given its name
$id = $bugherd->api('project')->getIdByName($name);

// Get a project
$project = $bugherd->api('project')->show($id);

// Create a project
$project = $bugherd->api('project')->create(array(
    'name'      => 'Name of the Project',
    'devurl'    => 'http://example.com/',
    'is_active' => true,
    'is_public' => false,
));

/** Users **/
// Get all users
$users = $bugherd->api('user')->all();

// Get all guests
$guests = $bugherd->api('user')->getGuests();

// Get all members
$members = $bugherd->api('user')->getMembers();

/ Tasks **/
// Get a task
$task = $bugherd->api('task')->show($projectId, $taskId);

// Create a task
$task = $bugherd->api('task')->create($projectId, array(
    'description'      => 'Some description',
    'requester_id'     => $requester_id,
    'requester_email'  => $requester_email
));

// Update a task
$task = $bugherd->api('task')->update($projectId, $taskId, array(
    'description'      => 'Some new description',
));

// Get all tasks
$tasks = $bugherd->api('task')->all($projectId, array(
    'status' => 'backlog',
    'priority' => 'critical'
));

/** Organization **/
// Get organization information
$organization = $bugherd->api('organization')->show();

/** Comments **/
// Create a comment
$comment = $bugherd->api('comment')->create($projectId, $taskId, array(
    'text'      => 'some comment',
    'user_id'     => $user_id,
    'user_email'  => $user_email
));

// Get all comments
$comments = $bugherd->api('comment')->all($projectId, $taskId);


/** Webhooks **/
// Get all webhooks
$webhooks = $bugherd->api('webhook')->all();

// Create a webhook
$webhook = $bugherd->api('webhook')->create(array(
    'target_url' => 'http://example.com/tasks/create',
    'event' => 'task_create' // this could be task_update, task_destroy, comment
));

// Delete a webhook
$bugherd->api('webhook')->remove($webhookId);

待办事项

  • 添加日志吗?

许可

此插件根据宽松的 MIT 许可发布。您的贡献始终受到欢迎。