juststeveking/laravel-envoyer-sdk

一个用于与 Laravel Envoyer API 交互的简单易用的 PHP 类

v2.0.0 2022-05-31 08:26 UTC

This package is auto-updated.

Last update: 2024-08-29 05:37:51 UTC


README

Latest Version PHP Version tests Check & fix styling Total Downloads

一个用于与 Laravel Envoyer API 交互的简单易用的 PHP 类

需求

  • PHP ^7.4
  • PHP ext-json

安装

首选的安装方法是使用 composer

$ composer require juststeveking/laravel-envoyer-sdk

为了使用此包,首先您必须拥有一个 Laravel Envoyer 账户,其次您必须通过 Laravel Envoyer 本身创建一个 API 令牌。

使用方法

您可以这样创建一个简单的 SDK

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

一旦您设置了 $envoyer,您现在可以通过 API 开始操作资源

管理项目

通过 SDK 简单管理 Envoyer 项目

列出所有项目

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->projects->all();

创建新项目

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->projects->save([
    'name' => 'SDK test',
    'provider' => 'github', // bitbucket, github, gitlab, gitlab-self
    'type' => 'laravel-5', // laravel-5. laravel-4, other
    'repository' => 'laravel/laravel',
    'branch' => 'master'
]);

获取特定项目

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->projects->find('id-of-project');

修改项目

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->projects->modify('id-of-project', [
    'name' => 'Project name update through SDK',
]);

删除项目

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->projects->delete('id-of-project');

更新项目的源代码

请注意,所有选项都是必需的,您不能仅将 push_to_deploy 作为单个选项来解析

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->projects->updateSource('id-of-project', [
    'provider' => 'github',
    'repository' => 'laravel/laravel',
    'branch' => '8.x',
    'push_to_deploy' => true,
]);

管理服务器

通过 SDK 简单管理 Envoyer 服务器

列出项目的所有服务器

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->servers->on('id-of-project')->all();

为项目创建新服务器

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->servers->on('id-of-project')->create([
    'name' => 'Server Name',
    'connectAs' => 'forge',
    'host' => 'ip-address-here',
    'phpVersion' => 'php80' // php80, php74, php73, php72, php71, php70, php56
]);

获取项目的单个服务器

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->servers->on('id-of-project')->first('id-of-your-server');

修改服务器

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->servers->on('id-of-project')->modify('id-of-your-server', [
    'name' => 'SDK Server'
]);

删除服务器

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->servers->on('id-of-project')->remove('id-of-your-server');

管理项目环境

通过 SDK 简单管理项目环境

获取当前环境

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->environments->on('id-of-project')->key('1234')->all();

获取环境服务器

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->environments->on('id-of-project')->key('1234')->servers();

更新项目环境

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->environments->on('id-of-project')
    ->key('1234')->onServer(1, 2, 3)
    ->put('test=api', 'another=value')

重置环境密钥

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->environments->on('id-of-project')->key('new-env-key')->reset('new-key');

列出 Envoyer 可用操作

获取所有操作

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->actions->all();

管理项目的操作钩子

通过 SDK 简单管理项目的操作钩子

列出所有钩子

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->hooks->on('id-of-project')->all();

创建新钩子

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->hooks->on('id-of-project')->create([
    'name' => 'list',
    'script' => 'll',
    'runAs' => 'forge',
    'actionId' => 'id-of-action',
    'timing' => 'after',
    'servers' => ['id-of-server', 'another-id-of-a-server']
]);

获取单个钩子

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->hooks->on('id-of-project')->first('id-of-hook');

更新钩子

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->hooks->on('id-of-project')->modify('id-of-hook', [
    'name' => 'list files and directories'
]);

删除钩子

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->hooks->on('id-of-project')->remove('id-of-hook');

通过 SDK 简单管理项目部署

通过 SDK 简单管理项目部署

列出所有部署

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->deployments->on('id-of-project')->all();

推送新部署

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

// Default Deployment
$envoyer->deployments->on('id-of-project')->deploy();

// Deployment from branch
$envoyer->deployments->on('id-of-project')->deploy([
    'from' => 'branch',
    'branch' => 'develop'
]);

// Deployment from tag
$envoyer->deployments->on('id-of-project')->deploy([
    'from' => 'tag',
    'tag' => 'v2.0.0'
]);

获取单个部署

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->deployments->on('id-of-project')->first('id-of-deployment');

取消部署

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->deployments->on('id-of-project')->cancel('id-of-deployment');

通过 SDK 简单管理项目协作者

通过 SDK 简单管理项目协作者

列出所有协作者

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->collaborators->on('id-of-project')->all();

邀请新协作者

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->collaborators->on('id-of-project')->invite([
    'email' => 'test@email.com'
]);

获取单个协作者

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->collaborators->on('id-of-project')->first('id-of-collaborator');

删除协作者

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->collaborators->on('id-of-project')->remove('id-of-collaborator');

通过 SDK 简单管理项目通知

通过 SDK 简单管理项目通知

列出所有通知

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->notifications->on('id-of-project')->all();

创建新通知

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

// Create an Email Notification
$envoyer->notifications->on('id-of-project')->create([
    'name' => 'Notification Name',
    'type' => 'email', // email, discord, slack, teams
    'email_address' => 'test@email.com'
]);

// Create a Discord Notification
$envoyer->notifications->on('id-of-project')->create([
    'name' => 'Notification Name',
    'type' => 'discord', // email, discord, slack, teams
    'discord_webhook' => 'url-of-webhook'
]);

// Create a Slack Notification
$envoyer->notifications->on('id-of-project')->create([
    'name' => 'Notification Name',
    'type' => 'slack', // email, discord, slack, teams
    'slack_webhook' => 'url-of-webhook'
]);

// Create a Teams Notification
$envoyer->notifications->on('id-of-project')->create([
    'name' => 'Notification Name',
    'type' => 'teams', // email, discord, slack, teams
    'teams_webhook' => 'url-of-webhook'
]);

获取单个通知

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->notifications->on('id-of-project')->first('id-of-notification');

修改通知

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->notifications->on('id-of-project')->modify('id-of-notification', [
    'name' => 'Send Someone an email',
    'type' => 'email',
    'email_address' => 'test@email.com'
]);

删除通知

use JustSteveKing\Laravel\Envoyer\SDK\Envoyer;

$envoyer = Envoyer::illuminate(
    API_TOKEN_HERE,
    'https://envoyer.io/' // this is optional as is the default
);

$envoyer->notifications->on('id-of-project')->remove('id-of-notification');