-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
67 lines (57 loc) · 1.63 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
require_once("vendor/autoload.php");
require_once("config.php");
use Trello\Client;
//Get headers
$data = [];
$git_header = $_SERVER['HTTP_X_GITLAB_EVENT'] || $_SERVER['HTTPS_X_GITLAB_EVENT'];
//If it's not a git hook - exit
if (!$git_header) {
return false;
}
//Read input data
$data = json_decode(file_get_contents('php://input'), true);
$issue = $data["object_attributes"];
//If it is open or exit
if($issue["action"] !== "open"){
return false;
}
//Create new Trello Api Client
$client = new Client();
$client->authenticate($config["trello"]["key"], $config["trello"]["token"], Client::AUTH_URL_CLIENT_ID);
//Load Trello board
$board_params = [
"filter" => "open",
"lists" => "open"
];
$boards = $client->api('member')->boards()->all('me', $board_params);
//Find our board
$issue_board = false;
foreach($boards as $board){
if(strtolower($board["name"]) === strtolower($config["trello"]["board_name"]) || $board["id"] === $config["trello"]["board_id"]){
$issue_board = $board;
break;
}
}
//Find our list
$list_id = false;
if($issue_board){
foreach($issue_board["lists"] as $list){
if(!$list["closed"] && strtolower($list["name"]) === strtolower($config["trello"]["list_name"])){
$list_id = $list["id"];
break;
}
}
}else{
return false;
}
//Create card
if($list_id){
$card_style = $config["card_formats"][$config["card_name"]];
$card_params = [
"name" => $card_style[0].$issue["iid"].$card_style[1].$issue["title"],
"desc" => $issue["description"],
"idList" => $list_id
];
$client->api('cards')->create($card_params);
}