-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractPlatformProvider.php
146 lines (129 loc) · 4.01 KB
/
AbstractPlatformProvider.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/*
* This file is part of foskym/flarum-issue-tracking.
*
* Copyright (c) 2024 FoskyM.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace FoskyM\IssueTracking;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\User;
use Illuminate\Contracts\Validation\Factory;
use Illuminate\Support\MessageBag;
abstract class AbstractPlatformProvider
{
/**
* @var string
* The key of the provider.
* Recommended to use the same key as the extension.
*/
public $key;
/**
* @var string
* The name of the provider, will be displayed in the admin panel.
*/
public $name;
protected $settings;
public final function __construct(SettingsRepositoryInterface $settings)
{
$this->settings = $settings;
}
/**
* Get the provider settings.
* @return array
*/
public final function getSettings(): array
{
$settings = [];
foreach ($this->availableSettings() as $key => $val) {
$settings[$key] = $this->settings->get($this->key . '.' . $key);
}
return $settings;
}
/**
* Validate the provider settings.
* @param SettingsRepositoryInterface $settings
* @param Factory $validator
* @return MessageBag
*/
public final function validateSettings(SettingsRepositoryInterface $settings, Factory $validator): MessageBag
{
$rules = [];
foreach ($this->availableSettings() as $key => $val) {
$rules[$this->key . '.' . $key] = $val;
}
return $validator->make($settings->all(), $rules)->errors();
}
/**
* Get the list of available settings.
* The key is the setting name, the value is the validation rule.
* Example: ['api_key' => 'required|string']
* @return array
*/
public abstract function availableSettings(): array;
/**
* Test the connection to the platform.
* @return bool
*/
public abstract function testConnection(): bool;
/**
* Get the list of issues.
* Array of AbstractIssue.
* @param string $sort
* The sorting method.
* Default: 'latest'
* Available: 'latest', 'newest', 'oldest'
* Just: latest_updated_at, created_at, updated_at
* @param int $skip
* The number of issues to skip.
* Default: 0
* @param int $limit
* The number of issues to return.
* Default: 15
* @return array
*/
public abstract function getIssueList(string $sort = 'latest', int $skip = 0, int $limit = 15): array;
/**
* Get the issue by ID.
* @param string $issueId
* @return AbstractIssue
*/
public abstract function getIssue(string $issueId): AbstractIssue;
/**
* Create a new issue.
* @param User $actor
* @param string $title
* @param string $description
* @return AbstractIssue
*/
public abstract function createIssue(User $actor, string $title, string $description): AbstractIssue;
/**
* Create a new comment on an issue.
* @param User $actor
* @param string $issueId
* @param string $content
* @return bool
*/
public abstract function createComment(User $actor, string $issueId, string $content): bool;
/**
* Calculate the progress of an issue.
* The progress should be a float between 0 and 1.
* 0 means the issue is just created, 1 means the issue is resolved.
* @param \FoskyM\IssueTracking\AbstractIssue $issue
* @return float
*/
public abstract function calculateIssueProgress(AbstractIssue $issue): float;
/**
* Check if the issue is resolved.
* @param \FoskyM\IssueTracking\AbstractIssue $issue
* @return bool
*/
public abstract function isIssueResolved(AbstractIssue $issue): bool;
/**
* Get the latest progress of the project.
* @return \FoskyM\IssueTracking\AbstractProgress
*/
public abstract function getLatestProgress(): AbstractProgress;
}